forked from KeithPatrick5/honktipbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.35 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
47
48
require("dotenv").config();
const Telegraf = require("telegraf");
const session = require("telegraf/session");
const { textHandler } = require("./src/handlers/textHandler");
const { commandHandler } = require("./src/handlers/commandHandler");
const commandParts = require("telegraf-command-parts");
const { notification } = require("./src/notification");
const rateLimit = require("./src/utils/ratelimit/ratelimit");
const MemoryStore = require("./src/utils/ratelimit/memory-store");
const { isBanned } = require("./src/utils/isBanned");
const bot = new Telegraf(process.env.BOT_TOKEN);
const limitConfig = {
window: 3000,
limit: 1,
onLimitExceeded: (ctx, next) => {}
};
bot.use(async (ctx, next) => {
if (isBanned(ctx.from.id)) return;
await next();
});
bot.use(rateLimit(limitConfig));
bot.use(session());
bot.use(commandParts());
bot.context.db = { lockedUsers: [] };
// bot.use(Telegraf.log()); // for debugging
// Logger
// bot.use(async (ctx, next) => {
// console.log("**********");
// if (ctx.updateSubTypes[0] === 'text') console.log(`text:${ctx.message.text}\nfrom ${ctx.from.id}`);
// await next();
// });
bot.catch(e => console.log(e));
commandHandler(bot);
// Text Handler must be last updates handler !
textHandler(bot);
bot.launch();
bot.telegram.getMe().then(res => console.log(res));
console.log("Bot running locally\n");
notification(bot);