From 0264c120d7281a8fd9e91fd96bfc8403c6104f4a Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Date: Sun, 13 Oct 2024 23:16:52 -0300 Subject: [PATCH] Add random dog image --- commands/dog.js | 26 ++++++++++++++++++++++++++ locales/english.json | 3 ++- locales/portuguese.json | 3 ++- locales/spanish.json | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 commands/dog.js diff --git a/commands/dog.js b/commands/dog.js new file mode 100644 index 0000000..5a8d809 --- /dev/null +++ b/commands/dog.js @@ -0,0 +1,26 @@ +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("dog", spamwatchMiddleware, async (ctx) => { + const Strings = getStrings(ctx.from.language_code); + const apiUrl = "https://dog.ceo/api/breeds/image/random"; + const response = await axios.get(apiUrl); + const data = response.data; + + try { + await ctx.replyWithPhoto(data.message, { + caption: `🐶`, + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + } catch (error) { + ctx.reply(Strings.dogImgErr, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + }; + }); +}; diff --git a/locales/english.json b/locales/english.json index 0729e1c..6adcec6 100644 --- a/locales/english.json +++ b/locales/english.json @@ -74,5 +74,6 @@ "catImgErr": "Sorry, but I couldn't get the cat photo you wanted.", "catGifErr": "Sorry, but I couldn't get the cat GIF you wanted.", "quoteResult": "Here is a random quote for you:", - "quoteErr": "Sorry, but something went wrong while displaying the quote." + "quoteErr": "Sorry, but something went wrong while displaying the quote.", + "dogImgErr": "Sorry, but I couldn't get the dog photo you wanted." } \ No newline at end of file diff --git a/locales/portuguese.json b/locales/portuguese.json index 9f3b376..32b3697 100644 --- a/locales/portuguese.json +++ b/locales/portuguese.json @@ -74,5 +74,6 @@ "catImgErr": "Desculpe, mas não consegui obter a foto do gato que você queria.", "catGifErr": "Desculpe, mas não consegui obter o GIF do gato que você queria.", "quoteResult": "Aqui está uma citação aleatória pra você (em inglês):", - "quoteErr": "Desculpe, mas algo deu errado ao exibir a citação." + "quoteErr": "Desculpe, mas algo deu errado ao exibir a citação.", + "dogImgErr": "Desculpe, mas não consegui obter a foto do cacbhorro que você queria." } \ No newline at end of file diff --git a/locales/spanish.json b/locales/spanish.json index c6de821..7c5b2ba 100644 --- a/locales/spanish.json +++ b/locales/spanish.json @@ -74,5 +74,6 @@ "catImgErr": "Lo siento, pero no pude obtener la foto del gato que querías.", "catGifErr": "Lo siento, pero no pude obtener el GIF del gato que querías.", "quoteResult": "Aquí tienes una cita aleatoria para ti (en inglés):", - "quoteErr": "Lo siento, pero algo salió mal al mostrar la cita." + "quoteErr": "Lo siento, pero algo salió mal al mostrar la cita.", + "dogImgErr": "Lo siento, pero no pude obtener la foto del perro que querías." } \ No newline at end of file