From 1b67dd0f43847f89df57c7cd1bc422d5899addcd Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 9 Jul 2018 17:54:36 +0000 Subject: [PATCH] Superpower Command --- README.md | 3 ++- commands/random/superpower.js | 44 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 commands/random/superpower.js diff --git a/README.md b/README.md index 2f5adb80..0f9d14ad 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ You can invite the bot to your server using Be sure to also join the [home server](https://discord.gg/sbMe32W) for information and support. -## Commands (290) +## Commands (291) ### Utility: * **prefix**: Shows or sets the command prefix. @@ -85,6 +85,7 @@ information and support. * **roll**: Rolls a dice with a maximum value of your choice. * **security-key**: Responds with a random security key. * **shower-thought**: Responds with a random shower thought, directly from r/Showerthoughts. +* **superpower**: Responds with a random superpower. * **user-roulette**: Randomly chooses a member of the server. * **would-you-rather**: Responds with a random "Would you rather ...?" question. * **xiao**: Responds with a random image of Xiao Pai. diff --git a/commands/random/superpower.js b/commands/random/superpower.js new file mode 100644 index 00000000..1b97636d --- /dev/null +++ b/commands/random/superpower.js @@ -0,0 +1,44 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { stripIndents } = require('common-tags'); +const { shorten } = require('../../util/Util'); + +module.exports = class SuperpowerCommand extends Command { + constructor(client) { + super(client, { + name: 'superpower', + group: 'random', + memberName: 'superpower', + description: 'Responds with a random superpower.' + }); + } + + async run(msg) { + try { + const article = await this.randomSuperpower(); + const { body } = await request + .get('http://powerlisting.wikia.com/api/v1/Articles/AsSimpleJson/') + .query({ id: article }); + return msg.reply(stripIndents` + Your superpower is... **${body.title}**! + _${shorten(body.sections[0].content.map(section => section.text).join('\n\n'), 1950)}_ + `); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async randomSuperpower() { + const { body } = await request + .get('http://powerlisting.wikia.com/api.php') + .query({ + action: 'query', + list: 'random', + rnnamespace: 0, + rnlimit: 1, + format: 'json', + formatversion: 2 + }); + return body.query.random[0].id; + } +}; diff --git a/package.json b/package.json index 7e2b01ff..1a219dea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "84.0.0", + "version": "84.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {