summaryrefslogtreecommitdiff
path: root/server/src/commands/fun/NumberFact.ts
blob: 27392188097dc5900bad6c6080d3a6f2ab21f4ac (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 NumberFactFun extends Command {
    public constructor() {
        super('numberfact', {
            aliases: ['numberfact', 'number-fact', 'numfact', 'num-fact'],
            category: 'fun',
            description: {
                content: 'Grabs a facts about a specified number.',
                usage: '[number]',
                examples: [
                    '8'
                ]
            },
            ratelimit: 3,
            args: [
                {
                    id: 'number',
                    type: 'integer',
                    prompt: {
                        start: 'What number would you like to get facts for? (Numeric value)',
                        retry: 'That is not a valid number, please try again.',
                        retries: 3
                    },
                    default: 'random',
                }
            ]
        });
    }
    
    public async exec(msg: Message, { number }): Promise<Message> {
        const fact = await Axios.get(`http://numbersapi.com/${number}`).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);
    }
}