add vanish command
This commit is contained in:
28
src/commands/impl/vanish.ts
Normal file
28
src/commands/impl/vanish.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { ChatMessage } from "@twurple/chat";
|
||||
import { purgeByIds } from "../../util/api-functions.ts";
|
||||
import { logSuccess } from "../../util/logger.ts";
|
||||
import { BaseCommand } from "../base-command.ts";
|
||||
import type { ICommandRequirements } from "../interface.ts";
|
||||
|
||||
export class VanishCommand extends BaseCommand {
|
||||
name = "v";
|
||||
cooldown = 0;
|
||||
enabled = true;
|
||||
|
||||
requirements: ICommandRequirements = {
|
||||
developer: false,
|
||||
mod: false,
|
||||
};
|
||||
|
||||
triggered = async (
|
||||
channel: string,
|
||||
user: string,
|
||||
_text: string,
|
||||
msg: ChatMessage,
|
||||
) => {
|
||||
logSuccess(`${channel} ${user} vanish command triggered`);
|
||||
if (msg.channelId) {
|
||||
purgeByIds(msg.channelId, msg.userInfo.userId);
|
||||
}
|
||||
};
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
import * as readline from "node:readline";
|
||||
import type { UserIdResolvable } from "@twurple/api";
|
||||
import { apiClient } from "../core/api-client.ts";
|
||||
import { logSuccess, logWarning } from "./logger.ts";
|
||||
|
||||
export async function getUserId(username: string): Promise<string | null> {
|
||||
export async function getUserId(username: string): Promise<UserIdResolvable> {
|
||||
const user = await apiClient.users.getUserByName(username);
|
||||
if (user?.id) {
|
||||
logSuccess(`${user.name} => ${user.id}`);
|
||||
return user.id;
|
||||
}
|
||||
logWarning(`no user with name ${username} found`);
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
export async function promptForInput(prompt: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user