Skip to content

Commit

Permalink
Random fox image
Browse files Browse the repository at this point in the history
  • Loading branch information
lucmsilva651 committed Feb 8, 2025
1 parent 4e49350 commit f01feb7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/commands/fox.js
Original file line number Diff line number Diff line change
@@ -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("fox", spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code);
try {
const response = await axios(Resources.foxApi);
ctx.replyWithPhoto(response.data.image, {
caption: response.data.link,
reply_to_message_id: ctx.message.message_id
});
} catch (error) {
const message = Strings.foxApiErr.replace('{error}', error.message);
ctx.reply(message, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
return;
}
});
}
1 change: 1 addition & 0 deletions src/locales/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"quoteResult": "Here is a random quote for you:",
"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}`",
"httpCodes": {
"invalidCode": "Please enter a valid HTTP code.",
"fetchErr": "An error occurred while fetching the HTTP code.",
Expand Down
1 change: 1 addition & 0 deletions src/locales/portuguese.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"quoteResult": "Aqui está uma citação aleatória pra você (em inglês):",
"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}`",
"httpCodes": {
"invalidCode": "Por favor, insira um código HTTP válido.",
"fetchErr": "Ocorreu um erro ao buscar o código HTTP.",
Expand Down
3 changes: 2 additions & 1 deletion src/props/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"ponyApi": "http://ponyapi.net/v1",
"quoteApi": "https://quotes-api-self.vercel.app/quote",
"weatherApi": "https://api.weather.com/v3",
"randomPonyApi": "https://theponyapi.com/api/v1/pony/random"
"randomPonyApi": "https://theponyapi.com/api/v1/pony/random",
"foxApi": "https://randomfox.ca/floof/"
}

0 comments on commit f01feb7

Please sign in to comment.