Files
tardis-bot/src/index.ts
T

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-05-14 20:06:15 +02:00
import { Client, Events, GatewayIntentBits } from "discord.js";
import { config } from "./config.js";
process.on("unhandledRejection", (reason) => {
console.error("Unhandled promise rejection:", reason);
});
process.on("uncaughtException", (err) => {
console.error("Uncaught exception:", err);
});
import { openDatabase } from "./db/db.js";
2026-05-14 21:26:10 +02:00
import type { BotStateRow } from "./db/schema.js";
2026-05-14 20:06:15 +02:00
import { loadStrings, makeT } from "./i18n/strings.js";
import { TTSRegistry } from "./tts/registry.js";
import { AudioService } from "./audio/AudioService.js";
import { CommandRegistry } from "./commands/CommandRegistry.js";
import { registerModules } from "./modules/registry.js";
import { repoRoot, type BotContext } from "./context.js";
const client = new Client({
intents: [
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
],
});
client.on(Events.Error, (err) => console.error("Discord client error:", err));
client.on(Events.Warn, (msg) => console.warn("Discord client warning:", msg));
const db = await openDatabase(config.DB_FILE);
2026-05-14 21:26:10 +02:00
const savedEngine = await db.get<BotStateRow>(
"select value from BotState where key='announcement_engine'",
);
const savedVoice = await db.get<BotStateRow>(
"select value from BotState where key='announcement_voice'",
);
const tts = new TTSRegistry(
savedEngine?.value ?? config.ANNOUNCEMENT_ENGINE,
savedVoice?.value ?? config.ANNOUNCEMENT_VOICE,
);
2026-05-14 20:06:15 +02:00
const audio = new AudioService({ voiceTmpPath: config.VOICE_TMP_PATH, tts });
const commands = new CommandRegistry(config.PREFIX);
const strings = loadStrings(config.STRING_SET);
const ctx: BotContext = {
client,
config,
audio,
commands,
tts,
db,
strings,
t: makeT(strings),
rootDir: repoRoot,
};
await registerModules(ctx);
client.on(Events.MessageCreate, (message) => {
void commands.handleMessage(message);
});
await client.login(config.TOKEN);