From f8c54da5a2850f0d07fb45022c364c602bf96fb3 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sat, 8 Feb 2025 20:57:15 -0300 Subject: [PATCH] Random duck image --- src/commands/duck.js | 25 +++++++++++++++++++++++++ src/locales/english.json | 1 + src/locales/portuguese.json | 1 + src/props/resources.json | 3 ++- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/commands/duck.js diff --git a/src/commands/duck.js b/src/commands/duck.js new file mode 100644 index 0000000..698ae04 --- /dev/null +++ b/src/commands/duck.js @@ -0,0 +1,25 @@ +const Resources = require('../props/resources.json'); +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("duck", spamwatchMiddleware, async (ctx) => { + const Strings = getStrings(ctx.from.language_code); + try { + const response = await axios(Resources.duckApi); + ctx.replyWithPhoto(response.data.url, { + caption: response.data.message, + reply_to_message_id: ctx.message.message_id + }); + } catch (error) { + const message = Strings.duckApiErr.replace('{error}', error.message); + ctx.reply(message, { + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + return; + } + }); +} \ No newline at end of file diff --git a/src/locales/english.json b/src/locales/english.json index a414145..72e35b8 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -87,6 +87,7 @@ "quoteErr": "Sorry, but something went wrong while displaying the quote.", "dogImgErr": "Sorry, but I couldn't get the dog photo you wanted.", "foxApiErr": "An error occurred while fetching data from the API.\n\n`{error}`", + "duckApiErr": "An error occurred while fetching data from the API.\n\n`{error}`", "httpCodes": { "invalidCode": "Please enter a valid HTTP code.", "fetchErr": "An error occurred while fetching the HTTP code.", diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json index 3b76e96..3ffbc86 100644 --- a/src/locales/portuguese.json +++ b/src/locales/portuguese.json @@ -87,6 +87,7 @@ "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.", "foxApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`", + "duckApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`", "httpCodes": { "invalidCode": "Por favor, insira um código HTTP válido.", "fetchErr": "Ocorreu um erro ao buscar o código HTTP.", diff --git a/src/props/resources.json b/src/props/resources.json index 4dec09a..1be807d 100644 --- a/src/props/resources.json +++ b/src/props/resources.json @@ -19,5 +19,6 @@ "quoteApi": "https://quotes-api-self.vercel.app/quote", "weatherApi": "https://api.weather.com/v3", "randomPonyApi": "https://theponyapi.com/api/v1/pony/random", - "foxApi": "https://randomfox.ca/floof/" + "foxApi": "https://randomfox.ca/floof/", + "duckApi": "https://random-d.uk/api/v2/random" } \ No newline at end of file