From b1bfeaa9595256e0ba1b5e6702b50f2cfd4ce289 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 12 Jul 2017 15:02:51 +0000 Subject: [PATCH] Upvoters Command --- README.md | 2 +- commands/util/upvoters.js | 29 +++++++++++++++++++++++++++++ structures/Util.js | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 commands/util/upvoters.js diff --git a/README.md b/README.md index 867e6cd9..2aff3c97 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ JavaScript with [discord.js](https://github.com/hydrabolt/discord.js) using the ## Adding it to Your Server Visit XiaoBot's page on the Discord Bots list, which is quite fancy, with -[this link](https://bots.discord.pw/bots/278305350804045834). +[this link](https://discordbots.org/bot/278305350804045834). ## Home Server You can join the home server with [this link](https://discord.gg/fqQF8mc). diff --git a/commands/util/upvoters.js b/commands/util/upvoters.js new file mode 100644 index 00000000..9119ac81 --- /dev/null +++ b/commands/util/upvoters.js @@ -0,0 +1,29 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); +const { stripIndents } = require('common-tags'); +const { upvoters } = require('../../structures/Util'); + +module.exports = class UpvotersCommand extends Command { + constructor(client) { + super(client, { + name: 'upvoters', + aliases: ['upvote'], + group: 'util', + memberName: 'upvoters', + description: 'Responds with Xiao\'s upvoters on Discord Bots.', + guarded: true + }); + } + + async run(msg) { + const upvotes = await upvoters(this.client.user.id); + const { body } = await snekfetch + .post('https://hastebin.com/documents') + .send(upvotes.join('\n')); + return msg.say(stripIndents` + Upvote Xiao and join ${upvotes.length} others! + + List of Upvoters: + `); + } +}; diff --git a/structures/Util.js b/structures/Util.js index ed4e1ae1..ae0edfe9 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -39,6 +39,13 @@ class Util { .then(() => console.log('[DBOTSORG] Successfully posted to Discord Bots Org.')) .catch((err) => console.error(`[DBOTSORG] Failed to post to Discord Bots Org. ${err}`)); } + + async static upvoters(id) { + const { body } = await snekfetch + .get(`https://discordbots.org/api/bots/${id}/votes`) + .set({ Authorization: dbotsOrgKey }); + return body.map((user) => `${user.username}#${user.discriminator}`); + } } module.exports = Util;