refactor: disable sequentialize & session
This commit is contained in:
parent
44978c8b7f
commit
7a08f968f4
@ -4,17 +4,14 @@ import * as features from './features';
|
||||
import { errorHandler } from './handlers/errors';
|
||||
import { i18n } from './i18n';
|
||||
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';
|
||||
import { getSessionKey } from '@/utils/session';
|
||||
import { autoChatAction } from '@grammyjs/auto-chat-action';
|
||||
import { hydrate } from '@grammyjs/hydrate';
|
||||
import { limit } from '@grammyjs/ratelimiter';
|
||||
import { sequentialize } from '@grammyjs/runner';
|
||||
import { Bot } from 'grammy';
|
||||
|
||||
type Parameters_ = {
|
||||
@ -35,9 +32,7 @@ export function createBot({ apiRoot, token }: Parameters_) {
|
||||
|
||||
bot.use(
|
||||
limit({
|
||||
keyGenerator: (ctx) => {
|
||||
return ctx.from?.id.toString();
|
||||
},
|
||||
keyGenerator: (ctx) => ctx.from?.id.toString(),
|
||||
limit: env.RATE_LIMIT,
|
||||
onLimitExceeded: async (ctx) => {
|
||||
await ctx.reply(ctx.t('err-limit-exceeded'));
|
||||
@ -51,7 +46,6 @@ export function createBot({ apiRoot, token }: Parameters_) {
|
||||
context.logger = logger.child({
|
||||
update_id: context.update.update_id,
|
||||
});
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
@ -60,9 +54,6 @@ export function createBot({ apiRoot, token }: Parameters_) {
|
||||
|
||||
const protectedBot = bot.errorBoundary(errorHandler);
|
||||
|
||||
protectedBot.use(sequentialize(getSessionKey));
|
||||
protectedBot.use(session());
|
||||
|
||||
protectedBot.use(middlewares.updateLogger());
|
||||
protectedBot.use(autoChatAction(bot.api));
|
||||
protectedBot.use(hydrate());
|
||||
|
||||
@ -12,23 +12,19 @@ const bot = createBot({
|
||||
bot.catch((error) => {
|
||||
logger.error('Grammy bot error:');
|
||||
logger.error(`Message: ${error?.message}`);
|
||||
logger.error(error.error); // собственно, ошибка
|
||||
logger.error(error.error);
|
||||
});
|
||||
|
||||
const runner = run(bot);
|
||||
|
||||
const redis = getRedisInstance();
|
||||
|
||||
// Graceful shutdown function
|
||||
async function gracefulShutdown(signal: string) {
|
||||
logger.info(`Received ${signal}, starting graceful shutdown...`);
|
||||
|
||||
try {
|
||||
// Stop the bot
|
||||
await runner.stop();
|
||||
logger.info('Bot stopped');
|
||||
|
||||
// Disconnect Redis
|
||||
redis.disconnect();
|
||||
logger.info('Redis disconnected');
|
||||
} catch (error) {
|
||||
@ -37,8 +33,6 @@ async function gracefulShutdown(signal: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Stopping the bot when the Node.js process
|
||||
// is about to be terminated
|
||||
process.once('SIGINT', () => gracefulShutdown('SIGINT'));
|
||||
process.once('SIGTERM', () => gracefulShutdown('SIGTERM'));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user