tested & working basic bot

This commit is contained in:
Darius
2025-09-27 16:12:50 +02:00
parent 44f3f7af0b
commit 10eee0c0fd
16 changed files with 161 additions and 127 deletions

View File

@@ -1,6 +1,6 @@
import { logSuccess } from "../util/logger.ts";
import { BaseEvent } from "./base-event.ts";
import type { EventName } from "./registry.ts";
import { logSuccess } from "../../util/logger.ts";
import { BaseEvent } from "../base-event.ts";
import type { EventName } from "../registry.ts";
export default class ConnectedEvent extends BaseEvent {
name: EventName = "connected";

View File

@@ -1,11 +1,10 @@
import { Collection } from "@discordjs/collection";
import type { ChatMessage } from "@twurple/chat";
import { commands } from "../commands/collection.ts";
import type { ICommand } from "../commands/interface.ts";
import { Config } from "../config/config.ts";
import { logInfo } from "../util/logger.ts";
import { BaseEvent } from "./base-event.ts";
import type { EventName } from "./registry.ts";
import { commands } from "../../commands/collection.ts";
import type { ICommand } from "../../commands/interface.ts";
import { Config } from "../../config/config.ts";
import { BaseEvent } from "../base-event.ts";
import type { EventName } from "../registry.ts";
const Cooldowns = new Collection<string, number>();
@@ -28,7 +27,7 @@ async function checkMessage(
text: string,
msg: ChatMessage,
) {
logInfo(`message seen: ${channel} - ${user} - ${text}`);
// logInfo(`message seen: ${channel} - ${user} - ${text}`);
const prefix = Config.prefix;
if (!text.startsWith(prefix)) return;
@@ -37,13 +36,11 @@ async function checkMessage(
.trim()
.split(/ +/g)[0]
.toLowerCase();
// logInfo(`available commands: ${commands.toJSON()}`);
// logInfo(`searching for command: ${commandName}`);
const command = commands.get(commandName);
if (!command) return;
if (!command.enabled) return;
if (command.requirements.developer && !isDeveloper(msg.userInfo.userId))
return;
if (command.requirements.mod && !msg.userInfo.isMod) return;
if (!command.checkPerms) return;
const timeLeft = checkCooldown(command);
if (timeLeft > 0) {
@@ -56,17 +53,13 @@ async function checkMessage(
await command.triggered(channel, user, text, msg);
}
function isDeveloper(userId: string): boolean {
return Config.developers.includes(userId);
}
function checkCooldown(command: ICommand): number {
const now = Date.now();
if (command.cooldown > 0) {
const cooldownTime = Cooldowns.get(command.name);
if (cooldownTime) {
if (cooldownTime < now) {
const timeLeft = 0; // TODO
const timeLeft = 0; // TODO!!!
return timeLeft;
} else {
Cooldowns.set(command.name, now + command.cooldown * 1000);

View File

@@ -1,6 +1,7 @@
import { chatClient } from "../core/chat-client.ts";
import ConnectedEvent from "./event-connected.ts";
import MessageEvent from "./event-message.ts";
import { logInfo } from "../util/logger.ts";
import ConnectedEvent from "./impl/connected.ts";
import MessageEvent from "./impl/message.ts";
import type { IEvent } from "./interface.ts";
export const eventRegistry = {
@@ -13,6 +14,7 @@ export function registerAllEvents() {
for (const event of events) {
eventRegistry[event.name](event); // Registers the event
logInfo(`event ${event.name} registered`);
}
}