add vanish command
This commit is contained in:
61
src/util/api-functions.ts
Normal file
61
src/util/api-functions.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import type { UserIdResolvable } from "@twurple/api";
|
||||
import { Config } from "../config/config";
|
||||
import { apiClient } from "../core/api-client";
|
||||
import { getUserId } from "./general";
|
||||
import { logError } from "./logger";
|
||||
|
||||
export async function timeoutByIds(
|
||||
channelId: UserIdResolvable,
|
||||
userId: UserIdResolvable,
|
||||
duration: number,
|
||||
reason: string,
|
||||
): Promise<void> {
|
||||
if (!channelId || !userId || !duration) {
|
||||
logError(`timout id command missing a required parameter`);
|
||||
}
|
||||
|
||||
await apiClient.asUser(Config.bot_user_id, async (apiClient) =>
|
||||
apiClient.moderation.banUser(channelId, { user: userId, duration, reason }),
|
||||
);
|
||||
}
|
||||
|
||||
export async function timeout(
|
||||
channelName: string,
|
||||
userName: string,
|
||||
duration: number,
|
||||
reason: string,
|
||||
): Promise<void> {
|
||||
if (!channelName || !userName || !duration) {
|
||||
logError(`timout name command missing a required parameter`);
|
||||
}
|
||||
|
||||
const channelId = await getUserId(channelName);
|
||||
const userId = await getUserId(userName);
|
||||
|
||||
await timeoutByIds(channelId, userId, duration, reason);
|
||||
}
|
||||
|
||||
export async function purgeByIds(
|
||||
channelId: UserIdResolvable,
|
||||
userId: UserIdResolvable,
|
||||
): Promise<void> {
|
||||
if (!channelId || !userId) {
|
||||
logError(`purge id command missing a required parameter`);
|
||||
}
|
||||
|
||||
await timeoutByIds(channelId, userId, 1, "purged");
|
||||
}
|
||||
|
||||
export async function purge(
|
||||
channelName: string,
|
||||
userName: string,
|
||||
): Promise<void> {
|
||||
if (!channelName || !userName) {
|
||||
logError(`purge name command missing a required parameter`);
|
||||
}
|
||||
|
||||
const channelId = await getUserId(channelName);
|
||||
const userId = await getUserId(userName);
|
||||
|
||||
await purgeByIds(channelId, userId);
|
||||
}
|
||||
Reference in New Issue
Block a user