-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.ts
56 lines (49 loc) · 1.43 KB
/
index.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
import { Bot as TelegramBot } from "grammy";
import { notifyAdmin } from "./helpers/notifier";
import * as dotenv from "dotenv";
import { errorHandler } from "./middleware/error-handler";
dotenv.config();
if (!process.env.TELEGRAM_BOT_TOKEN) {
throw new Error("TELEGRAM_BOT_TOKEN env variable is not defined");
}
export const bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN);
// Catch all errors with middleware
bot.catch(errorHandler);
try {
bot.api.setMyCommands([
{
command: "autoexpand",
description: "Manage link autoexpand settings for this chat.",
},
{
command: "lock",
description: "[Admin] Lock / unlock bot settings for this chat.",
},
{
command: "changelog",
description: "Manage changelog settings for this chat.",
},
{
command: "permissions",
description: "Check if the bot has needed permissions.",
},
{
command: "source",
description: "Check the source code of this bot on GitHub.",
},
]);
} catch (error) {
console.error("[Error] Could not set bot commands.", error);
notifyAdmin(error);
}
// Import all listeners from their index files
import "./link-listener";
import "./link-listener-channel";
import "./commands";
import "./callbacks";
bot.start().catch((error) => {
console.error("[Error] Could not start bot.", error);
notifyAdmin(error);
});
console.info("[ Bot started... ]");
notifyAdmin(`[ Bot started... ]`);