summaryrefslogtreecommitdiff
path: root/server/src/commands/fun/Onion.ts
blob: e056ec712e115b4d06ce4a167f6c28cd10e34d8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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<Message> {
        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}
        `);
    }
}