diff --git a/apps/bot/src/bot/index.ts b/apps/bot/src/bot/index.ts index 6035a4f..a786c1e 100644 --- a/apps/bot/src/bot/index.ts +++ b/apps/bot/src/bot/index.ts @@ -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); diff --git a/apps/bot/src/bot/info/index.ts b/apps/bot/src/bot/info/index.ts deleted file mode 100644 index 26a08c8..0000000 --- a/apps/bot/src/bot/info/index.ts +++ /dev/null @@ -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(); -} diff --git a/apps/bot/src/bot/commands/index.ts b/apps/bot/src/bot/settings/commands.ts similarity index 82% rename from apps/bot/src/bot/commands/index.ts rename to apps/bot/src/bot/settings/commands.ts index afaf8ca..5c99bb8 100644 --- a/apps/bot/src/bot/commands/index.ts +++ b/apps/bot/src/bot/settings/commands.ts @@ -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>) { 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) { diff --git a/apps/bot/src/bot/settings/index.ts b/apps/bot/src/bot/settings/index.ts new file mode 100644 index 0000000..39fbc6b --- /dev/null +++ b/apps/bot/src/bot/settings/index.ts @@ -0,0 +1,2 @@ +export * from './commands'; +export * from './info'; diff --git a/apps/bot/src/bot/settings/info.ts b/apps/bot/src/bot/settings/info.ts new file mode 100644 index 0000000..0820b6d --- /dev/null +++ b/apps/bot/src/bot/settings/info.ts @@ -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>) { + for (const locale of i18n.locales) { + await api.setMyDescription(i18n.t(locale, 'description')); + await api.setMyShortDescription(i18n.t(locale, 'short-description')); + } +}