bot: set commands & info only at run
This commit is contained in:
parent
581e5a7802
commit
5396a83150
@ -1,12 +1,12 @@
|
||||
/* eslint-disable n/callback-return */
|
||||
import { setCommands } from './commands';
|
||||
import { type Context } from './context';
|
||||
import * as features from './features';
|
||||
import { errorHandler } from './handlers/errors';
|
||||
import { i18n } from './i18n';
|
||||
import { setInfo } from './info';
|
||||
import * as middlewares from './middlewares';
|
||||
import { session } from './middlewares';
|
||||
import { setCommands } from './settings/commands';
|
||||
import { setInfo } from './settings/info';
|
||||
import { env } from '@/config/env';
|
||||
import { logger } from '@/utils/logger';
|
||||
import { getRedisInstance } from '@/utils/redis';
|
||||
@ -55,14 +55,15 @@ export function createBot({ apiRoot, token }: Parameters_) {
|
||||
await next();
|
||||
});
|
||||
|
||||
setInfo(bot);
|
||||
setCommands(bot);
|
||||
|
||||
const protectedBot = bot.errorBoundary(errorHandler);
|
||||
|
||||
protectedBot.use(sequentialize(getSessionKey));
|
||||
protectedBot.use(session());
|
||||
|
||||
protectedBot.use(middlewares.updateLogger());
|
||||
protectedBot.use(setInfo);
|
||||
protectedBot.use(setCommands);
|
||||
protectedBot.use(autoChatAction(bot.api));
|
||||
protectedBot.use(hydrate());
|
||||
protectedBot.use(features.welcome);
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import { type Context } from '../context';
|
||||
import { type NextFunction } from 'grammy';
|
||||
|
||||
export async function setInfo(ctx: Context, next: NextFunction) {
|
||||
await ctx.api.setMyDescription(ctx.t('description'));
|
||||
await ctx.api.setMyShortDescription(ctx.t('short-description'));
|
||||
|
||||
return next();
|
||||
}
|
||||
@ -2,9 +2,9 @@ import { type Context } from '@/bot/context';
|
||||
import { i18n } from '@/bot/i18n';
|
||||
import { Command, CommandGroup } from '@grammyjs/commands';
|
||||
import { type LanguageCode } from '@grammyjs/types';
|
||||
import { type NextFunction } from 'grammy';
|
||||
import { type Api, type Bot, type RawApi } from 'grammy';
|
||||
|
||||
export async function setCommands(ctx: Context, next: NextFunction) {
|
||||
export async function setCommands({ api }: Bot<Context, Api<RawApi>>) {
|
||||
const start = createCommand('start');
|
||||
|
||||
const commands = [start];
|
||||
@ -15,8 +15,7 @@ export async function setCommands(ctx: Context, next: NextFunction) {
|
||||
|
||||
const commandsGroup = new CommandGroup().add([start]);
|
||||
|
||||
await commandsGroup.setCommands(ctx);
|
||||
return next();
|
||||
await commandsGroup.setCommands({ api });
|
||||
}
|
||||
|
||||
function addLocalizations(command: Command) {
|
||||
2
apps/bot/src/bot/settings/index.ts
Normal file
2
apps/bot/src/bot/settings/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './commands';
|
||||
export * from './info';
|
||||
10
apps/bot/src/bot/settings/info.ts
Normal file
10
apps/bot/src/bot/settings/info.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { type Context } from '../context';
|
||||
import { i18n } from '../i18n';
|
||||
import { type Api, type Bot, type RawApi } from 'grammy';
|
||||
|
||||
export async function setInfo({ api }: Bot<Context, Api<RawApi>>) {
|
||||
for (const locale of i18n.locales) {
|
||||
await api.setMyDescription(i18n.t(locale, 'description'));
|
||||
await api.setMyShortDescription(i18n.t(locale, 'short-description'));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user