From 16438d7457f55ac5fbab0032f66efdf73bb2ec22 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Thu, 21 Nov 2024 12:26:23 -0300 Subject: [PATCH] Finally randomizing cat photos but disabled GIF support --- commands/cat.js | 90 ++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/commands/cat.js b/commands/cat.js index ff8cf1c..2200da4 100644 --- a/commands/cat.js +++ b/commands/cat.js @@ -1,45 +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); +const axios = require('axios'); module.exports = (bot) => { + // bot.command("cat", spamwatchMiddleware, async (ctx) => { + // const Strings = getStrings(ctx.from.language_code); + // const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, ''); + // let request = ""; + + // if (userInput && userInput.includes("gif")) { + // request = `/gif${userInput.replace("gif", "")}`; + // const apiUrl = `https://cataas.com/cat${request}`; + + // try { + // await ctx.replyWithAnimation(apiUrl, { + // caption: `🐱`, + // parse_mode: 'Markdown', + // reply_to_message_id: ctx.message.message_id + // }); + // } catch (error) { + // ctx.reply(Strings.catGifErr, { + // parse_mode: 'Markdown', + // reply_to_message_id: ctx.message.message_id + // }); + // }; + // } else { + // request = userInput ? `/${userInput}` : ''; + // const apiUrl = `https://cataas.com/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 + // }); + // }; + // }; + // }); + bot.command("cat", spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); - const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, ''); - let request = ""; + const apiUrl = "https://cataas.com/cat?json=true"; + const response = await axios.get(apiUrl); + const data = response.data; + const imageUrl = `https://cataas.com/cat/${data._id}`; - if (userInput && userInput.includes("gif")) { - request = `/gif${userInput.replace("gif", "")}`; - const apiUrl = `https://cataas.com/cat${request}`; - - try { - await ctx.replyWithAnimation(apiUrl, { - caption: `🐱`, - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - } catch (error) { - ctx.reply(Strings.catGifErr, { - parse_mode: 'Markdown', - reply_to_message_id: ctx.message.message_id - }); - }; - } else { - request = userInput ? `/${userInput}` : ''; - const apiUrl = `https://cataas.com/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 - }); - }; + try { + await ctx.replyWithPhoto(imageUrl, { + 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 + }); }; }); };