Random quotes (WIP), not included in /help yet

This commit is contained in:
Lucas Gabriel 2024-10-09 21:30:52 -03:00
parent 8b1c912520
commit f9d6117752
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
4 changed files with 38 additions and 3 deletions

29
commands/quotes.js Normal file
View File

@ -0,0 +1,29 @@
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("quote", spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code);
try {
const response = await axios.get('https://quotes-api-self.vercel.app/quote');
const data = response.data;
const escapedQuote = data.quote.replace(/([_*~`>.!-])/g, '\\$1');
const escapedAuthor = `- ${data.author}.`.replace(/([_*~`>.!-])/g, '\\$1');
const escapedData = `${Strings.quoteResult}\n>*${escapedQuote}*\n_${escapedAuthor}_`;
ctx.reply(escapedData, {
reply_to_message_id: ctx.message.message_id,
parse_mode: 'MarkdownV2'
});
} catch (error) {
console.error(error);
ctx.reply(Strings.quoteErr, {
reply_to_message_id: ctx.message.id,
parse_mode: 'MarkdownV2'
});
};
});
};

View File

@ -72,5 +72,7 @@
"botUpdated": "Bot updated with success.\n\n```{result}```",
"errorUpdatingBot": "Error updating bot\n\n{error}",
"catImgErr": "Sorry, but I couldn't get the cat GIF you wanted.",
"catGifErr": "Sorry, but I couldn't get the cat photo you wanted."
"catGifErr": "Sorry, but I couldn't get the cat photo you wanted.",
"quoteResult": "Here is a random quote for you:",
"quoteErr": "Sorry, but something went wrong while displaying the quote."
}

View File

@ -72,5 +72,7 @@
"botUpdated": "Bot atualizado com sucesso.\n\n```{result}```",
"errorUpdatingBot": "Erro ao atualizar o bot\n\n{error}",
"catImgErr": "Desculpe, mas não consegui obter o GIF do gato que você queria.",
"catGifErr": "Desculpe, mas não consegui obter a foto do gato que você queria."
"catGifErr": "Desculpe, mas não consegui obter a foto 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."
}

View File

@ -72,5 +72,7 @@
"botUpdated": "Bot actualizado con éxito.\n\n```{result}```",
"errorUpdatingBot": "Error al actualizar el bot\n\n{error}",
"catImgErr": "Lo siento, pero no pude obtener el GIF del gato que querías.",
"catGifErr": "Lo siento, pero no pude obtener la foto del gato que querías."
"catGifErr": "Lo siento, pero no pude obtener la foto 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."
}