Random quotes (WIP), not included in /help yet
This commit is contained in:
parent
8b1c912520
commit
f9d6117752
4 changed files with 38 additions and 3 deletions
29
commands/quotes.js
Normal file
29
commands/quotes.js
Normal 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'
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue