From 72a521a2d2bc68943abf17ebb2b4b902ddeeca28 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 20 Aug 2018 01:30:49 +0000 Subject: [PATCH] Add Humble Bundle Command --- README.md | 3 ++- commands/events/humble-bundle.js | 36 ++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 commands/events/humble-bundle.js diff --git a/README.md b/README.md index 8fe36cc7..fb694a53 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (292) +## Commands (293) ### Utility: * **eval**: Executes JavaScript code. @@ -107,6 +107,7 @@ on the [home server](https://discord.gg/sbMe32W). * **google-doodle**: Responds with a Google Doodle, either the latest one or a random one from the past. * **holidays**: Responds with today's holidays. * **horoscope**: Responds with today's horoscope for a specific Zodiac sign. +* **humble-bundle**: Responds with the current Humble Bundle. * **neko-atsume-password**: Responds with today's Neko Atsume password. * **time**: Responds with the current time in a particular location. * **today-in-history**: Responds with an event that occurred today in history. diff --git a/commands/events/humble-bundle.js b/commands/events/humble-bundle.js new file mode 100644 index 00000000..d22bc297 --- /dev/null +++ b/commands/events/humble-bundle.js @@ -0,0 +1,36 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { stripIndents } = require('common-tags'); + +module.exports = class HumbleBundleCommand extends Command { + constructor(client) { + super(client, { + name: 'humble-bundle', + aliases: ['humble'], + group: 'events', + memberName: 'humble-bundle', + description: 'Responds with the current Humble Bundle.' + }); + } + + async run(msg) { + try { + const { text } = await request.get('https://www.humblebundle.com/androidapp/v2/service_check'); + const body = JSON.parse(text); + if (!body.length) return msg.say('There is no bundle right now...'); + if (body.length > 1) { + return msg.say(stripIndents` + There are **${body.length}** bundles on right now! + ${body.map(bundle => `**${bundle.bundle_name}**: <${bundle.bundle_url}>`).join('\n')} + `); + } + const data = body[0]; + return msg.say(stripIndents` + The current bundle is **${data.bundle_name}**! + ${data.bundle_url} + `); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 9d52e0a8..1c1d51ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "87.1.0", + "version": "87.2.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {