Files
arestools/src/index.js
T
2026-08-09 16:53:38 +03:00

34 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { GrammyError } from 'grammy';
import { ALLOWED_UPDATES, createBot, shutdown, syncCommands } from './bot.js';
import { logger } from './core/logger.js';
const { bot, registry } = await createBot();
for (const signal of ['SIGINT', 'SIGTERM']) {
process.once(signal, () => {
shutdown(bot).then(
() => process.exit(0),
(err) => {
logger.error('Ошибка при остановке', err);
process.exit(1);
},
);
});
}
try {
await bot.start({
allowed_updates: ALLOWED_UPDATES,
// Первый апдейт приходит уже после getMe, поэтому меню обновляем здесь.
onStart: async ({ username }) => {
await syncCommands(bot, registry).catch((err) => logger.warn('setMyCommands не прошёл', err));
logger.info(`@${username} запущен. Апдейты: ${ALLOWED_UPDATES.join(', ')}`);
},
});
} catch (err) {
// bot.catch() ловит ошибки апдейтов, но не падения на старте.
if (err instanceof GrammyError && err.error_code === 401) {
logger.error('Telegram не принял токен (401). Проверьте BOT_TOKEN в .env.');
} else {
logger.error('Не удалось запустить б