mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { redis } from "bun";
|
|
import { chatterId, streamerId, eventSub, commandPrefix, singleUserMode } from "..";
|
|
import { User } from "../user";
|
|
import commands, { sendMessage } from "../commands";
|
|
|
|
console.info(`Loaded the following commands: ${commands.keys().toArray().join(', ')}`);
|
|
|
|
eventSub.onChannelChatMessage(streamerId, streamerId, async msg => {
|
|
// return if double user mode is on and the chatter says something, we don't need them
|
|
if (!singleUserMode && msg.chatterId === chatterId) return
|
|
|
|
// Get user from cache or place user in cache
|
|
const user = await User.initUsername(msg.chatterName);
|
|
|
|
// Manage vulnerable chatters
|
|
if (![chatterId, streamerId].includes(msg.chatterId)) {// Don't add the chatter or streamer to the vulnerable chatters
|
|
if (!await redis.sismember("vulnchatters", msg.chatterId)) {
|
|
await redis.sadd('vulnchatters', msg.chatterId);
|
|
console.debug(`${msg.chatterDisplayName} is now vulnerable to explosives.`);
|
|
};
|
|
};
|
|
|
|
// Parse commands:
|
|
if (msg.messageText.startsWith(commandPrefix)) {
|
|
const commandSelection = msg.messageText.slice(commandPrefix.length).split(' ')[0]!;
|
|
const selected = commands.get(commandSelection.toLowerCase());
|
|
if (!selected) { await sendMessage(`${commandSelection} command does not exist`, { replyParentMessageId: msg.messageId }); return; };
|
|
await selected.execute(msg, user!);
|
|
};
|
|
});
|