-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.6 KB
/
Copy pathindex.js
File metadata and controls
50 lines (41 loc) · 1.6 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
50
require("dotenv").config();
const { Telegraf, Markup } = require("telegraf");
const db = require("./db");
const config = require("./config");
const { mainMenuKeyboard, editMessageAndShowMenu } = require("./utils");
// Handlers
const startHandler = require("./handlers/start");
const dashboardHandler = require("./handlers/dashboard");
const earnHandler = require("./handlers/earn");
const inviteHandler = require("./handlers/invite");
const leaderboardHandler = require("./handlers/leaderboard");
const boostHandler = require("./handlers/boost");
const spinHandler = require("./handlers/spin");
const tasksHandler = require("./handlers/tasks");
const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);
// Initialize database
db.initDb();
bot.start(startHandler);
bot.action("main_menu", async (ctx) => {
await editMessageAndShowMenu(ctx, `Welcome back, ${ctx.from.first_name}!`);
});
bot.action("dashboard", dashboardHandler);
bot.action("earn", earnHandler);
bot.action("invite", inviteHandler);
bot.action("leaderboard", leaderboardHandler);
bot.action("boost", boostHandler);
bot.action("spin", spinHandler);
bot.action("tasks", tasksHandler);
bot.action("claim_daily", earnHandler.claimDailyReward);
bot.action("perform_spin", spinHandler.performSpin);
// Error handling
bot.catch((err, ctx) => {
console.error(`Error for ${ctx.updateType}`, err);
ctx.reply("Oops, something went wrong. Please try again later.");
});
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));
bot.launch().then(() => {
console.log("Bot started in polling mode");
});