Spaces:
Paused
Paused
Deploy Bot commited on
Commit Β·
6fbf164
1
Parent(s): 4ab4872
Feat: Smart Launch Strategy (Webhook)
Browse files546 unmodified lines5475485495505515525535545555565575585595605615625635645655665675685693 unmodified lines573574575576577578579546 unmodified lines// Launch with Retry Logic and DNS Check// const dns = require('dns'); // Already imported at the topconst launchBot = async () => {try {// Clear any stuck webhooksawait bot.telegram.deleteWebhook({ drop_pending_updates: true });console.log('π Webhook tozalandi...');await bot.launch({dropPendingUpdates: true});console.log('β Bot muvaffaqiyatli ishga tushdi!');} catch (err) {console.error('Botni ishga tushirishda xatolik:', err);if (err.description && err.description.includes('Conflict')) {console.warn("β οΈ DIQQAT: Botni boshqa joyda (masalan, kompyuteringizda terminalda) o'chirishingiz kerak! Serverda ikkita bot bitta token bilan ishlayapti.");}console.log('5 soniyadan keyin qayta urunib ko\'ramiz...');setTimeout(launchBot, 5000); // Retry after 5 seconds}};3 unmodified linesprocess.once('SIGINT', () => bot.stop('SIGINT'));process.once('SIGTERM', () => bot.stop('SIGTERM'));// Graceful stop handled abovemodule.exports = bot;546 unmodified lines5475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985993 unmodified lines603604605606607546 unmodified lines// Launch with Retry Logic and DNS Check// const dns = require('dns'); // Already imported at the top// Launch Strategy (Polling vs Webhook)const launchBot = async () => {try {const PORT = process.env.PORT || 7860; // Render/HF defaultconst DOMAIN = process.env.RENDER_EXTERNAL_URL || process.env.RAILWAY_PUBLIC_DOMAIN; // Auto-detectif (DOMAIN) {// WEBHOOK MODE (Production)console.log(`π Starting in WEBHOOK mode on port ${PORT}`);console.log(`π Domain: ${DOMAIN}`);// Delete any existing webhook first (optional, but good for restart)// await bot.telegram.deleteWebhook();await bot.launch({webhook: {domain: DOMAIN,port: PORT},dropPendingUpdates: true});console.log(`β Webhook Active: ${DOMAIN}/telegraf/<token>`);} else {// POLLING MODE (Local / Dev)console.log(`π Starting in POLLING mode`);// Clear any stuck webhooksawait bot.telegram.deleteWebhook({ drop_pending_updates: true });console.log('π Webhook tozalandi (Polling uchun)...');await bot.launch({dropPendingUpdates: true});console.log('β Bot (Polling) ishga tushdi!');}} catch (err) {console.error('β Botni ishga tushirishda xatolik:', err.message);if (err.description && err.description.includes('Conflict')) {console.warn("β οΈ MUAZZAM DIQQAT: Bot allaqachon boshqa joyda ishlamoqda!");console.warn("Agar bu server bo'lsa, demak lokal (kompyuterda) botni o'chirish kerak.");console.warn("Admin panelda 'Stop' tugmasini bosib, qayta yuklang.");}// Retry logic for Polling stabilityconsole.log('β³ 10 soniyadan keyin qayta urunib ko\'ramiz...');setTimeout(launchBot, 10000); // 10s retry}};3 unmodified linesprocess.once('SIGINT', () => bot.stop('SIGINT'));process.once('SIGTERM', () => bot.stop('SIGTERM'));module.exports = bot;
src/main.js+42-14