-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
49 lines (42 loc) · 1.56 KB
/
index.ts
File metadata and controls
49 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { bot, setBotCommands } from "./config/bot";
import { initializeSentry, closeSentry } from "./config/sentry";
import { createSessionMiddleware } from "./config/session";
import { initializeDatabase, closeDatabase } from "./db/database";
import { commandDefinitions } from "./commands/definitions";
import { registerNotificationUserSelectionHandler } from "./commands/notifications";
import { registerDumpDbCommand } from "./commands/dump_db";
import { registerMessageHandler } from "./handlers/message";
import { registerErrorHandler } from "./handlers/error";
initializeSentry();
initializeDatabase();
bot.use(createSessionMiddleware());
await setBotCommands();
const registeredFunctions = new Set<() => void>();
for (const cmd of commandDefinitions) {
if (!cmd.available || cmd.available()) {
if (!registeredFunctions.has(cmd.register)) {
cmd.register();
registeredFunctions.add(cmd.register);
}
}
}
registerDumpDbCommand();
registerNotificationUserSelectionHandler();
registerMessageHandler();
registerErrorHandler();
const gracefulShutdown = async (signal: string) => {
console.warn(`\nReceived ${signal}, shutting down gracefully...`);
await bot.stop();
console.warn("Bot stopped.");
closeDatabase();
await closeSentry();
process.exit(0);
};
process.once("SIGINT", () => gracefulShutdown("SIGINT"));
process.once("SIGTERM", () => gracefulShutdown("SIGTERM"));
console.warn("Starting bot...");
bot.start({
onStart: (botInfo) => {
console.warn(`Bot @${botInfo.username} is running!`);
},
});