summaryrefslogtreecommitdiff
path: root/server/src/commands/fun/DateFact.ts
blob: 6fe94bc9b01e7b60b74412aad74f325cb5487745 (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
42
43
44
45
46
47
48
49
50
51
52
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import Axios from 'axios';

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