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
+2 -2
View File
@@ -13,10 +13,10 @@ You can add XiaoBot to your server with [this link](https://discordapp.com/oauth
You can join the home server with [this link](https://discord.gg/fqQF8mc).
## Modules
[discord.js](https://discord.js.org/#/), [commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [snekfetch](https://github.com/GusCaplan/snekfetch), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/)
[discord.js](https://discord.js.org/#/), [commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [superagent](https://github.com/visionmedia/superagent), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/)
## APIs
[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/)
[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API)
## Self-Hosting
You can Self-Host the bot easily, provided you have API keys and a Discord Bot Token. [Node.js](https://nodejs.org/en/) is also required, with at least version 7.8.0 recommended.
+2 -2
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 QuizCommand extends Command {
constructor(client) {
@@ -22,7 +22,7 @@ module.exports = class QuizCommand 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
const response = await request
.get('http://jservice.io/api/random?count=1');
const data = response.body[0];
const answer = data.answer.toLowerCase().replace(/(<i>|<\/i>)/g, '');
+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);
+2 -2
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 BotSearchCommand extends Command {
constructor(client) {
@@ -29,7 +29,7 @@ module.exports = class BotSearchCommand extends Command {
}
const bot = args.bot.id;
try {
const response = await snekfetch
const response = await request
.get(`https://bots.discord.pw/api/bots/${bot}`)
.set({
'Authorization': process.env.DISCORD_BOTS_KEY
+2 -2
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 DefineCommand extends Command {
constructor(client) {
@@ -31,7 +31,7 @@ module.exports = class DefineCommand extends Command {
}
const word = encodeURIComponent(args.word);
try {
const response = await snekfetch
const response = await request
.get(`http://api.wordnik.com:80/v4/word.json/${word}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${process.env.WORDNIK_KEY}`);
const data = response.body[0];
const embed = new RichEmbed()
+2 -2
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 ForecastCommand extends Command {
constructor(client) {
@@ -28,7 +28,7 @@ module.exports = class ForecastCommand extends Command {
}
const location = args.locationQ;
try {
const response = await snekfetch
const response = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${location}")&format=json`);
const info = response.body.query.results.channel;
const data = info.item.forecast;
+2 -2
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const request = require('superagent');
const cheerio = require('cheerio');
const querystring = require('querystring');
@@ -29,7 +29,7 @@ module.exports = class GoogleCommand extends Command {
const query = encodeURIComponent(args.query);
const msg = await message.say('Searching...');
try {
const response = await snekfetch
const response = await request
.get(`https://www.google.com/search?q=${query}`);
const $ = cheerio.load(response.text);
let href = $('.r').first().find('a').first().attr('href');
+2 -2
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 IMDBCommand extends Command {
constructor(client) {
@@ -30,7 +30,7 @@ module.exports = class IMDBCommand extends Command {
}
const movie = encodeURIComponent(args.movie);
try {
const response = await snekfetch
const response = await request
.get(`http://www.omdbapi.com/?t=${movie}&plot=full`);
const data = response.body;
const embed = new RichEmbed()
+2 -2
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const request = require('superagent');
module.exports = class MapCommand extends Command {
constructor(client) {
@@ -38,7 +38,7 @@ module.exports = class MapCommand extends Command {
const zoom = args.zoom;
const location = encodeURIComponent(args.locationQ);
try {
const response = await snekfetch
const response = await request
.get(`https://maps.googleapis.com/maps/api/staticmap?center=${location}&zoom=${zoom}&size=500x500&key=${process.env.GOOGLE_KEY}`);
return message.channel.send({file: {attachment: response.body}});
} catch (err) {
+2 -2
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const request = require('superagent');
const cheerio = require('cheerio');
module.exports = class NeopetCommand extends Command {
@@ -25,7 +25,7 @@ module.exports = class NeopetCommand extends Command {
}
const pet = encodeURIComponent(args.pet);
try {
const response = await snekfetch
const response = await request
.get(`http://www.sunnyneo.com/petimagefinder.php?name=${pet}&size=5&mood=1`);
const $ = cheerio.load(response.text);
const link = $('textarea').first().text();
+2 -2
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 OsuCommand extends Command {
constructor(client) {
@@ -30,7 +30,7 @@ module.exports = class OsuCommand extends Command {
}
const username = encodeURIComponent(args.username);
try {
const response = await snekfetch
const response = await request
.get(`https://osu.ppy.sh/api/get_user?k=${process.env.OSU_KEY}&u=${username}&type=string`);
const data = response.body[0];
const embed = new RichEmbed()
+2 -2
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 UrbanCommand extends Command {
constructor(client) {
@@ -30,7 +30,7 @@ module.exports = class UrbanCommand extends Command {
}
const word = encodeURIComponent(args.word);
try {
const response = await snekfetch
const response = await request
.get(`http://api.urbandictionary.com/v0/define?term=${word}`);
const data = response.body.list[0];
const embed = new RichEmbed()
+2 -2
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 WattpadCommand extends Command {
constructor(client) {
@@ -25,7 +25,7 @@ module.exports = class WattpadCommand extends Command {
}
const book = encodeURIComponent(args.book);
try {
const response = await snekfetch
const response = await request
.get(`https://api.wattpad.com:443/v4/stories?query=${book}&limit=1`)
.set({
'Authorization': `Basic ${process.env.WATTPAD_KEY}`
+2 -2
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 WeatherCommand extends Command {
constructor(client) {
@@ -25,7 +25,7 @@ module.exports = class WeatherCommand extends Command {
}
const location = args.locationQ;
try {
const response = await snekfetch
const response = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${location}")&format=json`);
const data = response.body.query.results.channel;
const embed = new RichEmbed()
+2 -2
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 WikipediaCommand extends Command {
constructor(client) {
@@ -26,7 +26,7 @@ module.exports = class WikipediaCommand extends Command {
let query = encodeURIComponent(args.query);
query = query.replace(/[)]/g, '%29');
try {
const response = await snekfetch
const response = await request
.get(`https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&titles=${query}&exintro=&explaintext=&redirects=&formatversion=2`);
const data = response.body.query.pages[0];
const description = data.extract.substr(0, 1900).split('\n').join('\n\n');
+2 -2
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 YouTubeCommand extends Command {
constructor(client) {
@@ -28,7 +28,7 @@ module.exports = class YouTubeCommand extends Command {
}
const video = encodeURIComponent(args.video);
try {
const response = await snekfetch
const response = await request
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${video}&key=${process.env.GOOGLE_KEY}`);
const data = response.body.items[0];
const embed = new RichEmbed()
+2 -2
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 YuGiOhCommand extends Command {
constructor(client) {
@@ -25,7 +25,7 @@ module.exports = class YuGiOhCommand extends Command {
}
const card = encodeURIComponent(args.card);
try {
const response = await snekfetch
const response = await request
.get(`http://yugiohprices.com/api/card_data/${card}`);
const data = response.body.data;
if (data.card_type === 'monster') {
+2 -2
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const request = require('superagent');
module.exports = class WebhookCommand extends Command {
constructor(client) {
@@ -34,7 +34,7 @@ module.exports = class WebhookCommand extends Command {
const text = args.text;
try {
await message.delete();
await snekfetch
await request
.post(process.env.WEBHOOK_URL)
.send({
content: text
+3 -3
View File
@@ -33,7 +33,7 @@ module.exports = class InfoCommand extends Command {
.addField('Shards',
`${this.client.options.shardCount} (${this.client.shard.id})`, true)
.addField('Commands',
'106', true)
'107', true)
.addField('Owner',
'dragonfire535#8081', true)
.addField('Source Code',
@@ -47,9 +47,9 @@ module.exports = class InfoCommand extends Command {
.addField('Library',
'[discord.js](https://discord.js.org/#/)', true)
.addField('Modules',
'[commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [snekfetch](https://github.com/GusCaplan/snekfetch), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/)')
'[commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [superagent](https://github.com/visionmedia/superagent), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/)')
.addField('APIs',
'[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/)');
'[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API)');
return message.embed(embed);
}
};
+2 -1
View File
@@ -22,7 +22,7 @@
<li><a href="https://github.com/Gawdl3y/discord.js-commando/">discord.js-commando</a></li>
<li><a href="https://github.com/oliver-moran/jimp">JIMP</a></li>
<li><a href="https://github.com/clux/zalgolize">zalgoize</a></li>
<li><a href="https://github.com/GusCaplan/snekfetch">snekfetch</a></li>
<li><a href="https://github.com/visionmedia/superagent">superagent</a></li>
<li><a href="http://mathjs.org/">mathjs</a></li>
<li><a href="http://momentjs.com">moment</a></li>
<li><a href="https://github.com/jsmreese/moment-duration-format">moment-duration-format</a></li>
@@ -44,6 +44,7 @@
<li><a href="https://developer.yahoo.com/weather/">Yahoo Weather</a></li>
<li><a href="https://en.wikipedia.org/w/api.php">Wikipedia</a></li>
<li><a href="https://developers.google.com/maps/documentation/static-maps/">Google Static Maps</a></li>
<li><a href="https://github.com/strawpoll/strawpoll/wiki/API">Strawpoll</a></li>
</ul>
<h2>Information</h2>
<ul>
+1
View File
@@ -17,6 +17,7 @@
<li>Random Images (Cat, Pun, Potato, etc.)</li>
<li>Magic 8 Ball</li>
<li>Avatar Editing (RIP, Bob Ross, etc.)</li>
<li>Make Strawpolls</li>
<li>Meme Generator</li>
<li>Math</li>
<li>Typing and Math Games</li>
+3 -1
View File
@@ -24,6 +24,7 @@
<li>Random Images (Cat, Pun, Potato, etc.)</li>
<li>Magic 8 Ball</li>
<li>Avatar Editing (RIP, Bob Ross, etc.)</li>
<li>Make Strawpolls</li>
<li>Meme Generator</li>
<li>Math</li>
<li>Typing and Math Games</li>
@@ -65,7 +66,7 @@
<li><a href="https://github.com/Gawdl3y/discord.js-commando/">discord.js-commando</a></li>
<li><a href="https://github.com/oliver-moran/jimp">JIMP</a></li>
<li><a href="https://github.com/clux/zalgolize">zalgoize</a></li>
<li><a href="https://github.com/GusCaplan/snekfetch">snekfetch</a></li>
<li><a href="https://github.com/visionmedia/superagent">superagent</a></li>
<li><a href="http://mathjs.org/">mathjs</a></li>
<li><a href="http://momentjs.com">moment</a></li>
<li><a href="https://github.com/jsmreese/moment-duration-format">moment-duration-format</a></li>
@@ -87,6 +88,7 @@
<li><a href="https://developer.yahoo.com/weather/">Yahoo Weather</a></li>
<li><a href="https://en.wikipedia.org/w/api.php">Wikipedia</a></li>
<li><a href="https://developers.google.com/maps/documentation/static-maps/">Google Static Maps</a></li>
<li><a href="https://github.com/strawpoll/strawpoll/wiki/API">Strawpoll</a></li>
</ul>
</ul>
<h2>Information</h2>
+5 -5
View File
@@ -1,5 +1,5 @@
const { CommandoClient } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const request = require('superagent');
const path = require('path');
const client = new CommandoClient({
commandPrefix: 'x;',
@@ -35,7 +35,7 @@ client.on('guildCreate', async(guild) => {
const count = guilds.reduce((prev, val) => prev + val, 0);
console.log(`[Count] ${count}`);
try {
const response = await snekfetch
const response = await request
.post('https://www.carbonitex.net/discord/data/botdata.php')
.send({
key: process.env.CARBON_KEY,
@@ -46,7 +46,7 @@ client.on('guildCreate', async(guild) => {
console.log(`[Carbon] Failed to post to Carbon. ${err}`);
}
try {
const response = await snekfetch
const response = await request
.post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`)
.set({
'Authorization': process.env.DISCORD_BOTS_KEY
@@ -66,7 +66,7 @@ client.on('guildDelete', async(guild) => {
const count = guilds.reduce((prev, val) => prev + val, 0);
console.log(`[Count] ${count}`);
try {
const response = await snekfetch
const response = await request
.post('https://www.carbonitex.net/discord/data/botdata.php')
.send({
key: process.env.CARBON_KEY,
@@ -77,7 +77,7 @@ client.on('guildDelete', async(guild) => {
console.log(`[Carbon] Failed to post to Carbon. ${err}`);
}
try {
const response = await snekfetch
const response = await request
.post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`)
.set({
'Authorization': process.env.DISCORD_BOTS_KEY
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "27.0.0",
"version": "28.0.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {
@@ -36,7 +36,7 @@
"mathjs": "^3.11.5",
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0",
"snekfetch": "^2.3.2",
"superagent": "^3.5.2",
"zalgolize": "^1.2.4"
}
}