Fix setMyCommands

This commit is contained in:
2022-01-02 15:43:02 +03:00
parent 0d142c1dd8
commit efc23049a8
2 changed files with 18 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { Context, Telegraf, Markup } from 'telegraf'; import { Context, Telegraf, Markup, TelegramError } from 'telegraf';
import { BotState, Cache } from '@/bots/manager'; import { BotState, Cache } from '@/bots/manager';
@@ -25,12 +25,22 @@ export async function createApprovedBot(token: string, state: BotState): Promise
} }
}); });
await bot.telegram.setMyCommands([ async function setMyCommands() {
{command: "random", description: "Попытать удачу"}, await bot.telegram.setMyCommands([
{command: "update_log", description: "Информация об обновлении каталога"}, {command: "random", description: "Попытать удачу"},
{command: "settings", description: "Настройки"}, {command: "update_log", description: "Информация об обновлении каталога"},
{command: "help", description: "Помощь"}, {command: "settings", description: "Настройки"},
]); {command: "help", description: "Помощь"},
]);
}
try {
await setMyCommands();
} catch (e: unknown) {
if (e instanceof TelegramError && e.response.error_code === 429) {
setTimeout(() => setMyCommands(), 1000 * (e.response.parameters?.retry_after || 5));
}
}
bot.use(async (ctx: Context, next) => { bot.use(async (ctx: Context, next) => {
if (ctx.from) { if (ctx.from) {

View File

@@ -1,4 +1,3 @@
import BotsManager from './bots/manager'; import BotsManager from './bots/manager';
setTimeout(() => BotsManager.start(), 5000);
BotsManager.start();