import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; import { stripIndents } from 'common-tags'; import RSS from 'rss-parser'; export default class OnionFun extends Command { public constructor() { super('onion', { aliases: ['onion', 'theonion', 'the-onion'], category: 'fun', description: { content: 'Gives you a random Onion article.', usage: '', examples: [ '' ] }, ratelimit: 3 }); } public async exec(msg: Message): Promise { const parser = new RSS(); const feed = await parser.parseURL('https://www.theonion.com/rss').catch(err => { console.error(err); return msg.reply('Woops, there was an error regarding the (http://numbersapi.com) API.'); }); //@ts-ignore const article = feed.items[Math.floor(Math.random() * feed.items.length)]; return msg.reply(stripIndents` ${article.title} ${article.link} `); } }