superagent is better

This commit is contained in:
Daniel Odendahl Jr
2017-04-18 20:46:57 +00:00
parent 3ce1bdbb64
commit 5ec91d6728
25 changed files with 111 additions and 49 deletions
+57
View File
@@ -0,0 +1,57 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
module.exports = class StrawpollCommand extends Command {
constructor(client) {
super(client, {
name: 'strawpoll',
aliases: [
'poll',
'survey'
],
group: 'random',
memberName: 'strawpoll',
description: 'Creates a Strawpoll with your options. (;strawpoll "Who likes chips?" "Me" "Not Me")',
examples: [';strawpoll "Who likes chips?" "Me" "Not Me"'],
args: [{
key: 'title',
prompt: 'What would you like the title of the Strawpoll to be?',
type: 'string',
validate: title => {
if (title.length > 200) {
return 'Please limit your title to 200 characters.';
}
return true;
}
}, {
key: 'choices',
prompt: 'What choices do you want me pick from?',
type: 'string',
infinite: true
}]
});
}
async run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const title = args.title;
const choices = args.choices;
if (choices.length < 2) return message.say(':x: Error! You provided less than two choices!');
if (choices.length > 31) return message.say(':x: Error! You provided more than thirty choices!');
try {
const response = await request
.post('https://strawpoll.me/api/v2/polls')
.send({
title: title,
options: choices
});
const data = response.body;
return message.say(`${data.title}\nhttp://strawpoll.me/${data.id}`);
}
catch (err) {
return message.say(':x: Error! Something went wrong!');
}
}
};
+4 -3
View File
@@ -1,6 +1,6 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const request = require('superagent');
module.exports = class TodayCommand extends Command {
constructor(client) {
@@ -22,8 +22,9 @@ module.exports = class TodayCommand extends Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
}
try {
const response = await snekfetch
.get('http://history.muffinlabs.com/date');
const response = await request
.get('http://history.muffinlabs.com/date')
.buffer(true);
const parsedResponse = JSON.parse(response.text);
const events = parsedResponse.data.Events;
const randomNumber = Math.floor(Math.random() * events.length);