From 1c3c91fa1a698cb728e1a6a96e438110108e0f37 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Date: Mon, 14 Oct 2024 13:06:21 -0300 Subject: [PATCH] Fixed http.cat command + include it in help --- commands/cat.js | 43 ++++++++++++++++++++++++++--------------- commands/help.js | 27 +++++++++++++++----------- locales/english.json | 8 +++++--- locales/portuguese.json | 8 +++++--- locales/spanish.json | 8 +++++--- 5 files changed, 58 insertions(+), 36 deletions(-) diff --git a/commands/cat.js b/commands/cat.js index feb7416..6f7b946 100644 --- a/commands/cat.js +++ b/commands/cat.js @@ -24,22 +24,6 @@ module.exports = (bot) => { reply_to_message_id: ctx.message.message_id }); }; - } else if (userInput && userInput.includes("http")) { - request = `/${userInput.replace("http", "")}`; - const apiUrl = `https://http.cat${request}`; - - try { - await ctx.replyWithPhoto(apiUrl, { - caption: `🐱`, - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } catch (error) { - ctx.reply(Strings.catImgErr, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - }; } else { request = userInput ? `/${userInput}` : ''; const apiUrl = `https://cataas.com/cat${request}`; @@ -58,4 +42,31 @@ module.exports = (bot) => { }; }; }); + + bot.command("httpcat", spamwatchMiddleware, async (ctx) => { + const Strings = getStrings(ctx.from.language_code); + const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, ''); + + if (!userInput || isNaN(userInput)) { + return ctx.reply(Strings.catImgErr, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + } + + const apiUrl = `https://http.cat/${userInput}`; + + try { + await ctx.replyWithPhoto(apiUrl, { + caption: `🐱 ${apiUrl}`, + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + } catch (error) { + ctx.reply(Strings.catImgErr, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + } + }); }; diff --git a/commands/help.js b/commands/help.js index b5151cd..6df820b 100644 --- a/commands/help.js +++ b/commands/help.js @@ -8,9 +8,10 @@ async function sendHelpMessage(ctx, isEditing) { 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' }], - [{ text: Strings.lastFm, callback_data: '5' }, { text: Strings.ytDlp, callback_data: '6' }] + [{ text: Strings.mainCommands, callback_data: 'helpMain' }, { text: Strings.usefulCommands, callback_data: 'helpUseful' }], + [{ text: Strings.interactiveEmojis, callback_data: 'helpInteractive' }, { text: Strings.funnyCommands, callback_data: 'helpFunny' }], + [{ text: Strings.lastFm, callback_data: 'helpLast' }, { text: Strings.animalCommands, callback_data: 'helpAnimals' }], + [{ text: Strings.ytDlp, callback_data: 'helpYouTube' }] ] } }; @@ -35,37 +36,41 @@ module.exports = (bot) => { disable_web_page_preview: true, reply_markup: JSON.stringify({ inline_keyboard: [ - [{ text: Strings.goBack, callback_data: '7' }], + [{ text: Strings.goBack, callback_data: 'helpBack' }], ] }) }; switch (callbackData) { - case '1': + case 'helpMain': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.mainCommandsDesc, options); break; - case '2': + case 'helpUseful': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.usefulCommandsDesc, options); break; - case '3': + case 'helpInteractive': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.interactiveEmojisDesc, options); break; - case '4': + case 'helpFunny': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.funnyCommandsDesc, options); break; - case '5': + case 'helpLast': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.lastFmDesc, options); break; - case '6': + case 'helpYouTube': await ctx.answerCbQuery(); await ctx.editMessageText(Strings.ytDlpDesc, options); break; - case '7': + case 'helpAnimals': + await ctx.answerCbQuery(); + await ctx.editMessageText(Strings.animalCommandsDesc, options); + break; + case 'helpBack': await ctx.answerCbQuery(); await sendHelpMessage(ctx, true); break; diff --git a/locales/english.json b/locales/english.json index 4c937d9..b2af016 100644 --- a/locales/english.json +++ b/locales/english.json @@ -31,8 +31,6 @@ "chatInfo": "*Chat info*\n\n*Name:* `{chatName}`\n*Chat ID:* `{chatId}`\n*Handle:* `{chatHandle}`\n*Type:* `{chatType}`\n*Members:* `{chatMembersCount}`\n*Is a forum:* `{isForum}`", "funEmojiResult": "*You rolled {emoji} and got* `{value}`*!*\nYou don't know what that means? Me neither!", "gifErr": "*Something went wrong while sending the GIF. Please try again later.*\n\n{err}", - "lastFm": "Last.fm", - "lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Shows the last song from your Last.fm profile + the number of plays.\n- /setuser ``: Sets the user for the command above.", "lastFmNoUser": "*Please provide a Last.fm username.*\nExample: `/setuser `", "lastFmNoSet": "*You haven't set your Last.fm username yet.*\nUse the command /setuser to set.\n\nExample: `/setuser `", "lastFmNoRecent": "*No recent tracks found for Last.fm user* `{lastfmUser}`*.*", @@ -52,11 +50,15 @@ "usefulCommands": "Useful commands", "usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device ``: Search for a device on GSMArena and show its specs.\n- /weather | /clima ``: See weather status for a specific location.\n- /modarchive | /tma ``: Download a module from The Mod Archive.\n- /wiki (WIP): Displays content from a Wikipedia page, converting some things to a more familiar format on Telegram.", "funnyCommands": "Funny commands", - "funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Sends the [Soggy cat meme](https://knowyourmeme.com/memes/soggy-cat)\n - /cat `` - Sends a random picture of a cat. You can specify some tags, separating each by a comma. Example: `/cat orange, cute`\n - /dog - Sends a random picture of a dog.", + "funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10", "interactiveEmojis": "Interactive emojis", "interactiveEmojisDesc": "*Interactive emojis*\n\n- /dice: Roll a dice\n- /idice: Infinitely roll a colored dice\n- /slot: Try to combine the figures!\n- /ball: Try to kick the ball into the goal!\n- /bowling: Try to hit the pins!\n- /dart: Try to hit the target!", "ytDlp": "yt-dlp (YouTube)", "ytDlpDesc": "*yt-dlp (YouTube)*\n\n- /yt | /ytdl `