forked from ThemerBot/ThemerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.09 KB
/
index.js
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
/* eslint-disable no-console */
if (!process.env.TOKEN) {
require(`dotenv`).config();
}
const { TOKEN, BOT_USERNAME = ``, LOG_CHANNEL, API_ROOT } = process.env;
const fs = require(`fs`);
const path = require(`path`);
const downloadTranslations = require(`./scripts/download-translations`);
const Telegraf = require(`telegraf`);
const main = async () => {
const bot = new Telegraf(TOKEN, {
username: BOT_USERNAME,
telegram: {
...API_ROOT && {
apiRoot: API_ROOT,
},
},
});
if (!fs.existsSync(path.join(__dirname, `i18n`))) {
if (LOG_CHANNEL) {
bot.telegram.sendMessage(LOG_CHANNEL, `Downloading i18n files`);
} else {
console.log(`Downloading i18n files`);
}
await downloadTranslations();
}
require(`./middleware`)(bot);
require(`./handlers`)(bot);
bot.startPolling();
if (LOG_CHANNEL) {
bot.telegram.sendMessage(LOG_CHANNEL, `@${BOT_USERNAME} is running...`);
} else {
console.log(`@${BOT_USERNAME} is running...`);
}
};
main();