feat: initial Papo bot scaffold

This commit is contained in:
Pascal.P
2025-11-30 11:04:41 +01:00
commit 000481a3b0
12168 changed files with 1584750 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import fs from 'fs';
import path from 'path';
import { Client } from 'discord.js';
import { EventHandler } from '../utils/types.js';
import { logger } from '../utils/logger.js';
export class EventHandlerService {
constructor(private client: Client) {}
public async loadEvents() {
const eventsPath = path.join(process.cwd(), 'src', 'events');
const files = this.walk(eventsPath);
for (const file of files) {
const mod = await import(file);
const event: EventHandler = mod.default;
if (!event?.name || !event.execute) continue;
if (event.once) {
this.client.once(event.name, (...args) => event.execute(...args));
} else {
this.client.on(event.name, (...args) => event.execute(...args));
}
logger.info(`Bound event ${event.name}`);
}
}
private walk(dir: string): string[] {
const entries = fs.readdirSync(dir, { withFileTypes: true });
const files: string[] = [];
for (const entry of entries) {
const res = path.resolve(dir, entry.name);
if (entry.isDirectory()) files.push(...this.walk(res));
else if (entry.isFile() && (entry.name.endsWith('.ts') || entry.name.endsWith('.js'))) files.push(res);
}
return files;
}
}