mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 07:01:38 +01:00
first commit, basic command handling and auth managing
This commit is contained in:
27
bot/events/index.ts
Normal file
27
bot/events/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { eventSub } from "..";
|
||||
|
||||
eventSub.onSubscriptionCreateSuccess(event => {
|
||||
console.info(`Successfully created EventSub subscription: ${event.id}`);
|
||||
});
|
||||
|
||||
eventSub.onSubscriptionCreateFailure(event => {
|
||||
eventSub.stop()
|
||||
console.error(`Failed to create EventSub subscription: ${event.id}`);
|
||||
eventSub.start()
|
||||
});
|
||||
|
||||
eventSub.onSubscriptionDeleteSuccess(event => {
|
||||
console.info(`Successfully deleted EventSub subscription: ${event.id}`);
|
||||
});
|
||||
|
||||
eventSub.onSubscriptionDeleteFailure(event => {
|
||||
console.error(`Failed to delete EventSub subscription: ${event.id}`);
|
||||
});
|
||||
|
||||
import { readdir } from 'node:fs/promises';
|
||||
const files = await readdir(import.meta.dir);
|
||||
for (const file of files) {
|
||||
if (!file.endsWith('.ts')) continue;
|
||||
if (file === import.meta.file) continue;
|
||||
await import(import.meta.dir + '/' + file.slice(0, -3));
|
||||
};
|
||||
27
bot/events/message.ts
Normal file
27
bot/events/message.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { redis } from "bun";
|
||||
import { chatterId, streamerId, eventSub, commandPrefix } from "..";
|
||||
import { User } from "../user";
|
||||
import commands, { sendMessage } from "../commands";
|
||||
|
||||
console.info(`Loaded the ${commands.keys().toArray().join(', ')} commands`);
|
||||
|
||||
eventSub.onChannelChatMessage(streamerId, streamerId, async msg => {
|
||||
// Get user from cache or place user in cache
|
||||
const user = await User.init(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!);
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user