-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
77 lines (65 loc) · 2.48 KB
/
bot.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { Telegraf, Markup, Scenes, session } = require('telegraf');
const { distributeSolWizard } = require('./src/commands/distribute/distributeSolWizard');
const { distributeSplWizard } = require('./src/commands/distribute/distributeSplWizard');
const { handleGenerateWallets } = require('./src/commands/generateWallets');
const {
handleMyWallets,
handleViewKey,
handleRemoveWallet,
handleAddNewWallet,
handleWalletPagination,
} = require('./src/commands/mywallets');
const { handleBackToMainMenu } = require('./src/utils/bot/navigation');
const { chooseTokenType, registerTokenTypeActions } = require('./src/utils/bot/chooseTokenType');
const { registerHelpMenu } = require('./src/commands/help');
const config = require('./config');
// Check if BOT_TOKEN is set
if (!config.BOT_TOKEN) {
console.error('Error: BOT_TOKEN is not set. Please add your Telegram bot token in the .env file.');
process.exit(1);
}
const bot = new Telegraf(config.BOT_TOKEN);
const stage = new Scenes.Stage([distributeSolWizard, distributeSplWizard]);
bot.use(session());
bot.use(stage.middleware());
// Token Distribution Menu
bot.action('menu_distribute_tokens', async (ctx) => {
await chooseTokenType(ctx);
});
// Register Token Type Actions
registerTokenTypeActions(bot);
bot.start((ctx) => {
ctx.reply(
`👋 Welcome to the Sol Wallet Manager Bot!\n\n` +
`📋 <b>Main Menu</b>\n\n` +
`Use the buttons below to navigate through the available features:`,
{
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[
{ text: '💳 Generate Wallets', callback_data: 'menu_generate_wallets' },
{ text: '📜 My Wallets', callback_data: 'menu_my_wallets' },
],
[
{ text: '💸 Distribute Tokens', callback_data: 'menu_distribute_tokens' },
{ text: 'ℹ️ Help', callback_data: 'menu_help' },
],
]
}
}
);
});
handleGenerateWallets(bot);
bot.action('menu_my_wallets', (ctx) => handleMyWallets(ctx));
bot.action(/^view_key_(.+)$/, (ctx) => handleViewKey(ctx));
bot.action(/^remove_wallet_(.+)$/, (ctx) => handleRemoveWallet(ctx));
bot.action('add_new_wallet', (ctx) => handleAddNewWallet(ctx));
handleWalletPagination(bot);
registerHelpMenu(bot);
bot.action('menu_main', (ctx) => handleBackToMainMenu(ctx));
// Launch the bot
bot.launch();
// Handle graceful shutdown
process.on('SIGINT', () => bot.stop('SIGINT'));
process.on('SIGTERM', () => bot.stop('SIGTERM'));