Add /rpony + polishment on other commands

This commit is contained in:
Luquinhas 2025-02-08 00:14:10 -03:00
parent 2d02e6213f
commit d4dfe160e1
No known key found for this signature in database
GPG key ID: D9B075FC6DC93985
5 changed files with 48 additions and 11 deletions

View file

@ -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;
}
});
}