Move to snekfetch 🐍

This commit is contained in:
Daniel Odendahl Jr
2017-04-16 01:12:22 +00:00
parent 90d3e66e89
commit 8074fe51bd
36 changed files with 252 additions and 311 deletions
+39
View File
@@ -0,0 +1,39 @@
const { Command } = require('discord.js-commando');
const math = require('mathjs');
module.exports = class MathCommand extends Command {
constructor(client) {
super(client, {
name: 'math',
aliases: [
'add',
'subtract',
'multiply',
'divide'
],
group: 'random',
memberName: 'math',
description: 'Does Math (;math 2 + 2)',
examples: [';math 2 + 2'],
args: [{
key: 'expression',
prompt: 'What do you want to answer?',
type: 'string'
}]
});
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const expression = args.expression;
try {
const solved = math.eval(expression);
return message.say(solved).catch(() => message.say(':x: Error! Invalid statement!'));
}
catch (err) {
return message.say(':x: Error! Invalid statement!');
}
}
};
+2 -2
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
const snekfetch = require('snekfetch');
module.exports = class StrawpollCommand extends Command {
constructor(client) {
@@ -41,7 +41,7 @@ module.exports = class StrawpollCommand extends Command {
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
const response = await snekfetch
.post('https://strawpoll.me/api/v2/polls')
.send({
title: title,
+3 -6
View File
@@ -1,6 +1,6 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const snekfetch = require('snekfetch');
module.exports = class TodayCommand extends Command {
constructor(client) {
@@ -22,12 +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 request
const response = await snekfetch
.get('http://history.muffinlabs.com/date')
.set({
'Accept': 'application/json'
})
.buffer(true);
.buffer();
const parsedResponse = JSON.parse(response.text);
const events = parsedResponse.data.Events;
const randomNumber = Math.floor(Math.random() * events.length);