summaryrefslogtreecommitdiff
path: root/server/src/commands/fun/YearFact.ts
blob: e6b22083a91c06593930db17e9af9a7153d81733 (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
36
37
38
39
40
41
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import Axios from 'axios';

export default class YearFactFun extends Command {
    public constructor() {
        super('yearfact', {
            aliases: ['yearfact'],
            category: 'fun',
            description: {
                content: 'Grabs a fact about a specified year.',
                usage: '[numeric year]',
                examples: [
                    '1995'
                ]
            },
            ratelimit: 3,
            args: [
                {
                    id: 'year',
                    type: 'integer',
                    prompt: {
                        start: 'What year would you like to get facts for? (Numeric value)',
                        retry: 'That is not a valid year, please try again.',
                        retries: 3
                    },
                    default: 'random',
                }
            ]
        });
    }
    
    public async exec(msg: Message, { year }): Promise<Message> {
        const fact = await Axios.get(`http://numbersapi.com/${year}/year`).catch(err => {
            console.error(err);
            return msg.reply('Woops, there was an error with the (http://numbersapi.com) API.');
        });
        //@ts-ignore
        return msg.reply(fact.data);
    }
}