From d4dfe160e1423b3abe13e76879e7d4fc89e52518 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Sat, 8 Feb 2025 00:14:10 -0300 Subject: [PATCH] Add /rpony + polishment on other commands --- src/commands/ponyapi.js | 12 ++++++------ src/commands/randompony.js | 36 ++++++++++++++++++++++++++++++++++++ src/locales/english.json | 4 ++-- src/locales/portuguese.json | 4 ++-- src/props/resources.json | 3 ++- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/commands/randompony.js diff --git a/src/commands/ponyapi.js b/src/commands/ponyapi.js index 8b59eb2..ea26ad8 100644 --- a/src/commands/ponyapi.js +++ b/src/commands/ponyapi.js @@ -86,8 +86,8 @@ module.exports = (bot) => { }); }; } catch (error) { - console.error(error); - ctx.reply(Strings.ponyApi.apiErr, { + const message = Strings.ponyApi.apiErr.replace('{error}', error.message); + ctx.reply(message, { parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); @@ -155,8 +155,8 @@ module.exports = (bot) => { }); }; } catch (error) { - console.error(error); - ctx.reply(Strings.ponyApi.apiErr, { + const message = Strings.ponyApi.apiErr.replace('{error}', error.message); + ctx.reply(message, { parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); @@ -222,8 +222,8 @@ module.exports = (bot) => { }); }; } catch (error) { - console.error(error); - ctx.reply(Strings.ponyApi.apiErr, { + const message = Strings.ponyApi.apiErr.replace('{error}', error.message); + ctx.reply(message, { parse_mode: 'Markdown', reply_to_message_id: ctx.message.message_id }); diff --git a/src/commands/randompony.js b/src/commands/randompony.js new file mode 100644 index 0000000..814e41a --- /dev/null +++ b/src/commands/randompony.js @@ -0,0 +1,36 @@ +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(["rpony", "randompony"], spamwatchMiddleware, async (ctx) => { + const Strings = getStrings(ctx.from.language_code); + try { + const response = await axios(Resources.randomPonyApi); + let tags = []; + + if (response.data.pony.tags) { + if (typeof response.data.pony.tags === 'string') { + tags.push(response.data.pony.tags); + } else if (Array.isArray(response.data.pony.tags)) { + tags = tags.concat(response.data.pony.tags); + } + } + + ctx.replyWithPhoto(response.data.pony.representations.full, { + caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : 'N/A'}`, + parse_mode: 'Markdown', + reply_to_message_id: ctx.message.message_id + }); + } catch (error) { + const message = Strings.ponyApi.apiErr.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 0d08166..4ca7f5e 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -94,7 +94,7 @@ }, "ponyApi": { "helpEntry": "My Little Pony", - "helpDesc": "*My Little Pony*\n\n- /mlp: Displays this help message.\n- /mlpchar ``: Shows specific information about a My Little Pony character. Example: `/mlpchar twilight`\n- /mlpep: Shows specific information about a My Little Pony episode. Example: `/mlpep 136`", + "helpDesc": "*My Little Pony*\n\n- /mlp: Displays this help message.\n- /mlpchar ``: Shows specific information about a My Little Pony character. Example: `/mlpchar Twilight Sparkle`\n- /mlpep: Shows specific information about a My Little Pony episode. Example: `/mlpep 136`\n- /mlpcomic ``: Shows specific information about a My Little Pony comic. Example: `/mlpcomic Nightmare Rarity`\n- /rpony | /randompony: Sends a random artwork made by the My Little Pony community.", "charRes": "*MLP Character Information for* \"`{input}`\"*:*\n\n*Name:* `{name}`\n*Alias*: `{alias}`\n*Fandom URL:* [{url}]({url})\n*Sex:* `{sex}`\n*Residence:* `{residence}`\n*Occupation:* `{occupation}`\n*Kind:* `{kind}`", "epRes": "*MLP Episode Information for* \"`{input}`\"*:*\n\n*Name:* `{name}`\n*Fandom URL:* [{url}]({url})\n*Season:* `{season}`\n*Episode:* `{episode}`\n*Overall Ep.:* `{overall}`\n*Release date:* `{airdate}`\n*Story by:* `{storyby}`\n*Written by:* `{writtenby}`\n*Storyboard:* `{storyboard}`", "comicRes": "*MLP Comic Information for* \"`{input}`\"*:*\n\n*Name:* `{name}`\n*Fandom URL:* [{url}]({url})\n*Series:* `{series}`\n*Writer:* `{writer}`\n*Artist:* `{artist}`\n*Colorist:* `{colorist}`\n*Letterer:* `{letterer}`\n*Editor:* `{editor}`", @@ -104,7 +104,7 @@ "noEpisodeFound": "No episode found.", "noComicName": "Please provide the comic's name.", "noComicFound": "No comic found.", - "apiErr": "An error occurred while fetching data from the API." + "apiErr": "An error occurred while fetching data from the API.\n\n`{error}`" }, "codenameCheck": { "noCodename": "Please provide a codename to search.", diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json index cd352b9..eadb3de 100644 --- a/src/locales/portuguese.json +++ b/src/locales/portuguese.json @@ -94,7 +94,7 @@ }, "ponyApi": { "helpEntry": "My Little Pony", - "helpDesc": "*My Little Pony*\n\n- /mlp: Exibe esta mensagem de ajuda.\n- /mlpchar ``: Mostra informações específicas sobre um personagem de My Little Pony em inglês. Exemplo: `/mlpchar twilight`\n- /mlpep: Mostra informações específicas sobre um episódio de My Little Pony em inglês. Exemplo: `/mlpep 136`", + "helpDesc": "*My Little Pony*\n\n- /mlp: Exibe esta mensagem de ajuda.\n- /mlpchar ``: Mostra informações específicas sobre um personagem de My Little Pony em inglês. Exemplo: `/mlpchar twilight`\n- /mlpep: Mostra informações específicas sobre um episódio de My Little Pony em inglês. Exemplo: `/mlpep 136`\n- /mlpcomic ``: Mostra informações específicas sobre uma comic de My Little Pony em inglês. Exemplo: `/mlpcomic Nightmare Rarity`\n- /rpony | /randompony: Envia uma arte aleatória feita pela comunidade de My Little Pony.", "charRes": "*Informações do Personagem de MLP para* `{input}`*:*\n\n*Nome:* `{name}`\n*Apelido:* `{alias}`\n*URL do Fandom:* [{url}]({url})\n*Sexo:* `{sex}`\n*Residência:* `{residence}`\n*Ocupação:* `{occupation}`\n*Tipo:* `{kind}`", "epRes": "*Informações do Episódio de MLP para* `{input}`*:*\n\n*Nome:* `{name}`\n*URL do Fandom:* [{url}]({url})\n*Temporada:* `{season}`\n*Episódio:* `{episode}`\n*Episódio Geral:* `{overall}`\n*Data de Lançamento:* `{airdate}`\n*História por:* `{storyby}`\n*Escrito por:* `{writtenby}`\n*Storyboard:* `{storyboard}`", "comicRes": "*Informações da Comic de MLP para* \"`{input}`\"*:*\n\n*Nome:* `{name}`\n*URL do Fandom:* [{url}]({url})\n*Série:* `{series}`\n*Escritor:* `{writer}`\n*Artista:* `{artist}`\n*Colorista:* `{colorist}`\n*Letrista:* `{letterer}`\n*Editor:* `{editor}`", @@ -104,7 +104,7 @@ "noEpisodeFound": "Nenhum episódio encontrado.", "noComicName": "Por favor, forneça o nome da comic.", "noComicFound": "Nenhuma comic foi encontrada.", - "apiErr": "Ocorreu um erro ao buscar dados da API." + "apiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`" }, "codenameCheck": { "noCodename": "Por favor, forneça um codinome para pesquisar.", diff --git a/src/props/resources.json b/src/props/resources.json index 92449c8..f9eb35b 100644 --- a/src/props/resources.json +++ b/src/props/resources.json @@ -17,5 +17,6 @@ "modArchiveApi": "https://api.modarchive.org/downloads.php?moduleid=", "ponyApi": "http://ponyapi.net/v1", "quoteApi": "https://quotes-api-self.vercel.app/quote", - "weatherApi": "https://api.weather.com/v3" + "weatherApi": "https://api.weather.com/v3", + "randomPonyApi": "https://theponyapi.com/api/v1/pony/random" } \ No newline at end of file