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 */
|
/* eslint-disable n/callback-return */
|
||||||
import { setCommands } from './commands';
|
|
||||||
import { type Context } from './context';
|
import { type Context } from './context';
|
||||||
import * as features from './features';
|
import * as features from './features';
|
||||||
import { errorHandler } from './handlers/errors';
|
import { errorHandler } from './handlers/errors';
|
||||||
import { i18n } from './i18n';
|
import { i18n } from './i18n';
|
||||||
import { setInfo } from './info';
|
|
||||||
import * as middlewares from './middlewares';
|
import * as middlewares from './middlewares';
|
||||||
import { session } from './middlewares';
|
import { session } from './middlewares';
|
||||||
|
import { setCommands } from './settings/commands';
|
||||||
|
import { setInfo } from './settings/info';
|
||||||
import { env } from '@/config/env';
|
import { env } from '@/config/env';
|
||||||
import { logger } from '@/utils/logger';
|
import { logger } from '@/utils/logger';
|
||||||
import { getRedisInstance } from '@/utils/redis';
|
import { getRedisInstance } from '@/utils/redis';
|
||||||
@ -55,14 +55,15 @@ export function createBot({ apiRoot, token }: Parameters_) {
|
|||||||
await next();
|
await next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setInfo(bot);
|
||||||
|
setCommands(bot);
|
||||||
|
|
||||||
const protectedBot = bot.errorBoundary(errorHandler);
|
const protectedBot = bot.errorBoundary(errorHandler);
|
||||||
|
|
||||||
protectedBot.use(sequentialize(getSessionKey));
|
protectedBot.use(sequentialize(getSessionKey));
|
||||||
protectedBot.use(session());
|
protectedBot.use(session());
|
||||||
|
|
||||||
protectedBot.use(middlewares.updateLogger());
|
protectedBot.use(middlewares.updateLogger());
|
||||||
protectedBot.use(setInfo);
|
|
||||||
protectedBot.use(setCommands);
|
|
||||||
protectedBot.use(autoChatAction(bot.api));
|
protectedBot.use(autoChatAction(bot.api));
|
||||||
protectedBot.use(hydrate());
|
protectedBot.use(hydrate());
|
||||||
protectedBot.use(features.welcome);
|
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 { i18n } from '@/bot/i18n';
|
||||||
import { Command, CommandGroup } from '@grammyjs/commands';
|
import { Command, CommandGroup } from '@grammyjs/commands';
|
||||||
import { type LanguageCode } from '@grammyjs/types';
|
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 start = createCommand('start');
|
||||||
|
|
||||||
const commands = [start];
|
const commands = [start];
|
||||||
@ -15,8 +15,7 @@ export async function setCommands(ctx: Context, next: NextFunction) {
|
|||||||
|
|
||||||
const commandsGroup = new CommandGroup().add([start]);
|
const commandsGroup = new CommandGroup().add([start]);
|
||||||
|
|
||||||
await commandsGroup.setCommands(ctx);
|
await commandsGroup.setCommands({ api });
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLocalizations(command: Command) {
|
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