first commit, basic command handling and auth managing

This commit is contained in:
2025-05-30 22:56:46 +02:00
commit cc796765ed
17 changed files with 610 additions and 0 deletions

42
bot/commands/index.ts Normal file
View File

@@ -0,0 +1,42 @@
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base";
import { type HelixSendChatMessageParams } from "@twurple/api";
import { User } from "../user";
/** The Command class represents a command */
export class Command {
public readonly name: string;
public readonly aliases: string[];
public readonly requiredIntents: string[];
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>;
constructor(name: string, aliases: string[], requiredIntents: string[], execution: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>) {
this.name = name;
this.aliases = aliases;
this.requiredIntents = requiredIntents;
this.execute = execution;
};
};
import { readdir } from 'node:fs/promises';
const commands = new Map<string, Command>;
const intents: string[] = [];
const files = await readdir(import.meta.dir);
for (const file of files) {
if (!file.endsWith('.ts')) continue;
if (file === import.meta.file) continue;
const command: Command = await import(import.meta.dir + '/' + file.slice(0, -3)).then(a => a.default);
intents.push(...command.requiredIntents);
for (const alias of command.aliases) {
commands.set(alias, command); // Since it's not a primitive type the map is filled with references to the command, not the actual object
};
};
export default commands;
export { intents };
import { singleUserMode, chatterApi, chatterId, streamerId } from "..";
/** Helper function to send a message to the stream */
export const sendMessage = async (message: string, options?: HelixSendChatMessageParams) => {
singleUserMode ? await chatterApi.chat.sendChatMessage(streamerId, message, options) : chatterApi.asUser(chatterId, async newapi => newapi.chat.sendChatMessage(streamerId, message, options));
};

10
bot/commands/ping.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Command, sendMessage } from ".";
// This command is purely for testing
export default new Command('ping',
['ping'],
[],
async msg => {
await sendMessage('pong!', { replyParentMessageId: msg.messageId });
}
);

17
bot/commands/yabai.ts Normal file
View File

@@ -0,0 +1,17 @@
import { Command, sendMessage } from ".";
import { type HelixSendChatMessageParams } from "@twurple/api";
// Remake of the !yabai command in ttv/kiara_tv
export default new Command('yabai',
['yabai', 'goon'],
[],
async msg => {
const replyobj: HelixSendChatMessageParams = { replyParentMessageId: msg.messageId }
const rand = Math.floor(Math.random() * 100) + 1;
if (rand < 25) await sendMessage(`${rand}% yabai! chumpi4Bewwy`, replyobj);
else if (rand < 50) await sendMessage(`${rand}% yabai chumpi4Hustle`, replyobj);
else if (rand === 50) await sendMessage(`${rand}% yabai kiawaBlank`, replyobj);
else if (rand < 80) await sendMessage(`${rand}% yabai chumpi4Shock`, replyobj);
else await sendMessage(`${rand}% yabai chumpi4Jail`, replyobj);
}
);