62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
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);
|
|
}
|