-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
59 lines (51 loc) · 1.84 KB
/
main.ts
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
50
51
52
53
54
55
56
57
58
59
import schedule from "node-schedule";
import TelegramBot from "node-telegram-bot-api";
import repl from "repl";
import { envVars, userIds } from "./constants";
import { alertsModule, iqMeterModule, sigameRandomModule, userRememberingModule } from "./modules";
import { weenieMeterModule } from "./modules/weenie_meter_module";
import { prayForNwbButtonModule } from "./modules/pray_for_nwb_button_module/pray_for_nwb_button_module";
import { keyboardModule } from "./modules/keyboard_module";
import { getPbModule } from "./modules/get_pb_module";
import { geogessrModule } from "./modules/geogssr_module";
import fs from "fs";
export const bot = new TelegramBot(envVars.BOT_TOKEN || "", {
polling: true,
});
userRememberingModule();
alertsModule();
weenieMeterModule();
iqMeterModule();
sigameRandomModule();
prayForNwbButtonModule();
keyboardModule();
getPbModule();
geogessrModule();
bot.onText(/\/ruok/, (msg) => {
bot.sendMessage(msg.chat.id, "I`M OK");
});
bot.on("message", (msg) => {
if (msg.from?.id && userIds.indexOf(msg.from.id) === -1) {
bot.sendMessage(msg.chat.id, "TbI KTo?", { reply_to_message_id: msg.message_id });
msg.text = null as unknown as undefined;
}
});
console.log(envVars.LOG_ALL);
bot.on("message", (msg) => (envVars.LOG_ALL ? console.log(msg) : null));
const handleExit = async () => {
console.log("[EXIT] Shutting down bot");
await bot.close();
await bot.stopPolling({ cancel: true });
console.log("[EXIT] Bot shut down");
await schedule.gracefulShutdown();
process.exit();
};
repl.start().context.nwbot = { bot, exit: handleExit };
process.on("beforeExit", async function () {
console.log("[EXIT] Exiting, schedules graceful shutdown.");
await schedule.gracefulShutdown();
console.log("[EXIT] Schedules shut down");
});
process.on("SIGINT", () => {
schedule.gracefulShutdown().then(process.exit());
});