From af14cb7291080f116d42cd018a96644b6858589f Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 13 Sep 2017 11:08:17 +0000 Subject: [PATCH] Number Fact Command --- commands/random-res/number-fact.js | 32 ++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 commands/random-res/number-fact.js diff --git a/commands/random-res/number-fact.js b/commands/random-res/number-fact.js new file mode 100644 index 00000000..31aa4c49 --- /dev/null +++ b/commands/random-res/number-fact.js @@ -0,0 +1,32 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); + +module.exports = class NumberFactCommand extends Command { + constructor(client) { + super(client, { + name: 'number-fact', + group: 'random-res', + memberName: 'number-fact', + description: 'Responds with a random fact about a number.', + args: [ + { + key: 'number', + prompt: 'What number do you want to get a fact for?', + type: 'integer' + } + ] + }); + } + + async run(msg, args) { + const { number } = args; + try { + const { text } = await snekfetch + .get(`http://numbersapi.com/${number}`); + return msg.say(text); + } catch (err) { + if (err.status === 404) return msg.say('Could not find any results.'); + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index e0d7f8fe..37cccf40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "38.6.0", + "version": "38.7.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {