From 177a3c55408ae7c249a7b3a6416b39183e76cc39 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Wed, 11 Sep 2024 18:45:25 -0300 Subject: [PATCH] Put help in another file to avoid confusion --- commands/help.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ commands/main.js | 62 -------------------------------------------- 2 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 commands/help.js diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..85b833d --- /dev/null +++ b/commands/help.js @@ -0,0 +1,67 @@ +const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); + +async function sendHelpMessage(ctx, isEditing) { + const Strings = getStrings(ctx.from.language_code); + const options = { + parse_mode: 'Markdown', + reply_markup: { + inline_keyboard: [ + [{ text: Strings.mainCommands, callback_data: '1' }, { text: Strings.usefulCommands, callback_data: '2' }], + [{ text: Strings.interactiveEmojis, callback_data: '3' }, { text: Strings.funnyCommands, callback_data: '4' }] + ] + } + }; + const helpText = Strings.lynxHelp; + if (isEditing) { + await ctx.editMessageText(helpText, options); + } else { + await ctx.reply(helpText, options); + } +} + +module.exports = (bot) => { + bot.help(spamwatchMiddleware, async (ctx) => { + await sendHelpMessage(ctx); + }); + + bot.on('callback_query', async (ctx) => { + const callbackData = ctx.callbackQuery.data; + const Strings = getStrings(ctx.from.language_code); + const options = { + parse_mode: 'Markdown', + reply_markup: JSON.stringify({ + inline_keyboard: [ + [{ text: Strings.goBack, callback_data: '5' }], + ] + }) + }; + + switch (callbackData) { + case '1': + await ctx.answerCbQuery(); + await ctx.editMessageText(Strings.mainCommandsDesc, options); + break; + case '2': + await ctx.answerCbQuery(); + await ctx.editMessageText(Strings.usefulCommandsDesc, options); + break; + case '3': + await ctx.answerCbQuery(); + await ctx.editMessageText(Strings.interactiveEmojisDesc, options); + break; + case '4': + await ctx.answerCbQuery(); + await ctx.editMessageText(Strings.funnyCommandsDesc, options); + break; + case '5': + await ctx.answerCbQuery(); + await sendHelpMessage(ctx, true); + break; + default: + await ctx.answerCbQuery(Strings.invalidOption); + break; + } + }); +} \ No newline at end of file diff --git a/commands/main.js b/commands/main.js index 471174e..dc65c88 100644 --- a/commands/main.js +++ b/commands/main.js @@ -3,25 +3,6 @@ const { getStrings } = require('../plugins/checklang.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); -async function sendHelpMessage(ctx, isEditing) { - const Strings = getStrings(ctx.from.language_code); - const options = { - parse_mode: 'Markdown', - reply_markup: { - inline_keyboard: [ - [{ text: Strings.mainCommands, callback_data: '1' }, { text: Strings.usefulCommands, callback_data: '2' }], - [{ text: Strings.interactiveEmojis, callback_data: '3' }, { text: Strings.funnyCommands, callback_data: '4' }] - ] - } - }; - const helpText = Strings.lynxHelp; - if (isEditing) { - await ctx.editMessageText(helpText, options); - } else { - await ctx.reply(helpText, options); - } -} - module.exports = (bot) => { bot.start(spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); @@ -34,49 +15,6 @@ module.exports = (bot) => { ); }); - bot.help(spamwatchMiddleware, async (ctx) => { - await sendHelpMessage(ctx); - }); - - bot.on('callback_query', async (ctx) => { - const callbackData = ctx.callbackQuery.data; - const Strings = getStrings(ctx.from.language_code); - const options = { - parse_mode: 'Markdown', - reply_markup: JSON.stringify({ - inline_keyboard: [ - [{ text: Strings.goBack, callback_data: '5' }], - ] - }) - }; - - switch (callbackData) { - case '1': - await ctx.answerCbQuery(); - await ctx.editMessageText(Strings.mainCommandsDesc, options); - break; - case '2': - await ctx.answerCbQuery(); - await ctx.editMessageText(Strings.usefulCommandsDesc, options); - break; - case '3': - await ctx.answerCbQuery(); - await ctx.editMessageText(Strings.interactiveEmojisDesc, options); - break; - case '4': - await ctx.answerCbQuery(); - await ctx.editMessageText(Strings.funnyCommandsDesc, options); - break; - case '5': - await ctx.answerCbQuery(); - await sendHelpMessage(ctx, true); - break; - default: - await ctx.answerCbQuery(Strings.invalidOption); - break; - } - }); - bot.command('privacy', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); ctx.reply(