-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
75 lines (55 loc) · 2.96 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
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
import 'dotenv/config';
import bot from './interface/botInstance.js';
import { withErrorHandling } from './interface/utils/errorHandling.js';
import cron from 'node-cron'
// Import callback handlers
import * as callbacks from './interface/callBacks/index.js';
import monitorUserUsage from './services/moduls/crons/monitorUserUsage.js';
cron.schedule('*/4 * * * *', async () => {
console.log('Cron job triggered at:', new Date());
await monitorUserUsage(); // Call the function to check users' usages
});
// --- Command Handlers ---
bot.command('start', withErrorHandling(callbacks.startCallback));
bot.callbackQuery('start', withErrorHandling(callbacks.startCallback));
bot.hears('💼 خرید کانفیگ', withErrorHandling(callbacks.plansList));
bot.callbackQuery(/sendPaymentCard_(.+)/, withErrorHandling(callbacks.sendPaymentCard));
bot.hears('🔋 شارژ کانفیگ', ctx => withErrorHandling(callbacks.selectConfig(ctx, 'selectConfig')));
bot.callbackQuery(/selectConfig_(.+)/, withErrorHandling(callbacks.plansList));
bot.callbackQuery('addAnExistingConfig', withErrorHandling(callbacks.addAnExsistingConfig));
// bot.on('message', withErrorHandling(callbacks.receiptImage)); // gets the config url and add it to database
bot.hears('📋 جزئیات کانفیگ', ctx => withErrorHandling(callbacks.selectConfig(ctx, 'getUsage')));
bot.callbackQuery(/getUsage_(.+)/, withErrorHandling(callbacks.getUsage));
const chiDoroyMigoy = async (ctx) => {
const referralMessage = [
"🎉 لینک دعوت شما آماده است:",
`🔗 https://t.me/Testtinybug_bot?start=${ctx.from.id}`,
"",
"📢 اگر دوست شما اولین کانفیگ خود را خریداری کند، شما 10٪ از مبلغ خرید او را به عنوان جایزه دریافت خواهید کرد!",
].join("\n");
await ctx.reply(referralMessage, { parse_mode: "HTML" });
}
bot.hears('👥 دعوت از دوستان', withErrorHandling(chiDoroyMigoy));
const chiDoroyMigoy2 = async (ctx) => {
const message = [
'برای ارتباط با پشتیبانی، از طریق لینک زیر با ما در تماس باشید:',
'<a href="https://t.me/tinybug_dev"><b>@tinybug_dev</b></a>',
].join('\n\n');
await ctx.reply(message, { parse_mode: 'HTML' });
}
bot.hears('🆘 پشتیبانی', withErrorHandling(chiDoroyMigoy2));
bot.command('health', (ctx) => ctx.reply('Bot is running!!'));
bot.on('message', withErrorHandling(callbacks.messageHandler));
bot.callbackQuery(/(accept|reject)_(\d+)_(.+)/, withErrorHandling(callbacks.receiptApproval));
// Add global error handling
bot.catch(async (err) => {
console.error('Error caught by Grammy:', err);
// You can log this error to an external service like Sentry
// or send a notification to you (developer) about the issue
await bot.api.sendMessage(
process.env.ADMIN_ID,
`An error occurred: ${err.message}`
);
});
// Start the bot
bot.start();