From 6884f732a0a570a49874f2670eaaa00d010eca0c Mon Sep 17 00:00:00 2001 From: Alexandr Sekerin Date: Mon, 13 Nov 2023 12:57:03 +0300 Subject: [PATCH] chore: changed keyboards.js --- src/handlers/errorHandler.js | 4 +++- src/handlers/openaiHandlers.js | 26 +++++++++++++++++++------- src/handlers/userHandlers.js | 12 +++++++----- src/keyboards/keyboards.js | 2 ++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/handlers/errorHandler.js b/src/handlers/errorHandler.js index 4fd6e5b..ae0416d 100644 --- a/src/handlers/errorHandler.js +++ b/src/handlers/errorHandler.js @@ -1,9 +1,11 @@ import { LEXICON_EN } from '../lexicon/lexicon_en.js'; +import { menuKeyboard } from '../keyboards/keyboards.js'; class ErrorHandler { responseError(ctx, handler) { return (error) => { - console.log(`${error.name} ${handler}: ${error.message}`); + console.log(`${error.name} ${handler}: ${error.message}`, + menuKeyboard); ctx.reply( `${LEXICON_EN['noResponce']}\n\n${error.name}: ${error.message}`, ); diff --git a/src/handlers/openaiHandlers.js b/src/handlers/openaiHandlers.js index f0806d6..8efd73f 100644 --- a/src/handlers/openaiHandlers.js +++ b/src/handlers/openaiHandlers.js @@ -4,6 +4,7 @@ import { LEXICON_EN } from '../lexicon/lexicon_en.js'; import { openai } from '../openai.js'; import { converter } from '../converter.js'; +import { menuKeyboard } from '../keyboards/keyboards.js'; import { createInitialSession } from '../utils/createSession.js'; import { checkAccess } from '../utils/checkAccess.js'; @@ -17,7 +18,9 @@ class OpenAIHandlers { const sessionId = ctx.message.chat.id; sessions[sessionId] ??= createInitialSession(); - const processing = await ctx.reply(code(LEXICON_EN['processingText'])); + const processing = await ctx.reply( + code(LEXICON_EN['processingText']), + menuKeyboard); const text = ctx.message.text; @@ -36,10 +39,14 @@ class OpenAIHandlers { }); } - await ctx.reply(response.content, { parse_mode: 'Markdown' }); - }) - .catch(ErrorHandler.responseError(ctx, 'textHandler')) - .finally(async () => { + await ctx + .reply( + response.content, + { parse_mode: 'Markdown' }, + menuKeyboard); + }, + ).catch(ErrorHandler.responseError(ctx, 'textHandler'), + ).finally(async () => { await ctx.deleteMessage(processing.message_id); }); }; @@ -52,7 +59,9 @@ class OpenAIHandlers { const sessionId = ctx.message.chat.id; sessions[sessionId] ??= createInitialSession(); - const processing = await ctx.reply(code(LEXICON_EN['processingVoice'])); + const processing = await ctx.reply( + code(LEXICON_EN['processingVoice']), + menuKeyboard); const link = await ctx.telegram.getFileLink(ctx.message.voice.file_id); const userId = String(ctx.message.from.id); @@ -91,7 +100,9 @@ class OpenAIHandlers { return async (ctx) => { if (await checkAccess(config, ctx)) return; - const processing = await ctx.reply(code(LEXICON_EN['processingImage'])); + const processing = await ctx.reply( + code(LEXICON_EN['processingImage']), + menuKeyboard); const requestText = ctx.message.text.replace('/image', '').trim(); @@ -109,6 +120,7 @@ class OpenAIHandlers { if (response) { await ctx.replyWithPhoto( { url: response }, { caption: requestText }, + menuKeyboard, ); return; } diff --git a/src/handlers/userHandlers.js b/src/handlers/userHandlers.js index e733107..bdc0be4 100644 --- a/src/handlers/userHandlers.js +++ b/src/handlers/userHandlers.js @@ -2,14 +2,12 @@ import { LEXICON_EN, getIDs, getHelp, printPassword, } from '../lexicon/lexicon_en.js'; -import { createMenuKeyboard } from '../keyboards/keyboards.js'; +import { menuKeyboard } from '../keyboards/keyboards.js'; import { createInitialSession } from '../utils/createSession.js'; import { checkAccess } from '../utils/checkAccess.js'; import { generatePassword } from '../utils/generatePassword.js'; -const menuKeyboard = createMenuKeyboard(); - class UserHandlers { startHandler = (sessions) => { return async (ctx) => { @@ -42,7 +40,10 @@ class UserHandlers { passwordHandler = () => { return async (ctx) => { const password = await generatePassword(); - await ctx.reply(await printPassword(password), { parse_mode: 'HTML' }); + await ctx.reply( + await printPassword(password), + { parse_mode: 'HTML' }, + menuKeyboard); }; }; @@ -52,7 +53,8 @@ class UserHandlers { const sessionId = ctx.message.chat.id; sessions[sessionId] = createInitialSession(); - await ctx.reply(LEXICON_EN['reset'], menuKeyboard); + await ctx.reply(LEXICON_EN['reset'], + menuKeyboard); }; }; } diff --git a/src/keyboards/keyboards.js b/src/keyboards/keyboards.js index d36796f..323d5c1 100644 --- a/src/keyboards/keyboards.js +++ b/src/keyboards/keyboards.js @@ -7,3 +7,5 @@ export function createMenuKeyboard() { [LEXICON_EN['password_btn'], LEXICON_EN['getIDs_btn']]], ).resize(); } + +export const menuKeyboard = createMenuKeyboard();