From 8074fe51bde8b915e0be5ea8b1ed64f51f55da17 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 16 Apr 2017 01:12:22 +0000 Subject: [PATCH] =?UTF-8?q?Move=20to=20snekfetch=20=F0=9F=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- commands/avataredit/steamcard.js | 2 +- commands/games/lottery.js | 2 +- commands/games/quiz.js | 9 +-- commands/moderation/ban.js | 7 +- commands/moderation/kick.js | 7 +- commands/moderation/warn.js | 7 +- commands/{numedit => random}/math.js | 2 +- commands/random/strawpoll.js | 4 +- commands/random/today.js | 9 +-- commands/search/botinfo.js | 4 +- commands/search/define.js | 15 +--- commands/search/forecast.js | 12 +-- commands/search/google.js | 11 +-- commands/search/imdb.js | 12 +-- commands/search/map.js | 14 +--- commands/search/neopet.js | 13 +--- commands/search/osu.js | 13 +--- commands/search/urban.js | 11 +-- commands/search/wattpad.js | 12 +-- commands/search/weather.js | 12 +-- commands/search/wikipedia.js | 21 ++---- commands/search/youtube.js | 15 +--- commands/search/yugioh.js | 6 +- commands/textedit/languages.json | 97 ++++++++++++++++++++++++ commands/textedit/morse.js | 47 +----------- commands/textedit/morsemappings.json | 44 +++++++++++ commands/textedit/translate.js | 109 ++------------------------- commands/textedit/webhook.js | 4 +- commands/textedit/yoda.js | 11 +-- commands/userinfo/userinfo.js | 8 +- commands/util/info.js | 2 +- html/carbondesc.html | 2 +- html/discordbots.html | 2 +- index.js | 11 ++- package.json | 4 +- 36 files changed, 252 insertions(+), 311 deletions(-) rename commands/{numedit => random}/math.js (97%) create mode 100644 commands/textedit/languages.json create mode 100644 commands/textedit/morsemappings.json diff --git a/README.md b/README.md index 3ad2d60c..dc572b6d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ 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), [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/) +[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/) ## 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/), [Yoda Speak](https://market.mashape.com/ismaelc/yoda-speak), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Yandex.Translate](https://translate.yandex.com/developers), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/) diff --git a/commands/avataredit/steamcard.js b/commands/avataredit/steamcard.js index 31946743..3c4aea4c 100644 --- a/commands/avataredit/steamcard.js +++ b/commands/avataredit/steamcard.js @@ -26,7 +26,7 @@ module.exports = class SteamCardCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const user = args.user; - const userDisplayName = message.guild ? message.guild.member(user).displayName : user.username; + const userDisplayName = user.username; let userAvatar = user.displayAvatarURL; userAvatar = userAvatar.replace('.jpg', '.png'); userAvatar = userAvatar.replace('.gif', '.png'); diff --git a/commands/games/lottery.js b/commands/games/lottery.js index 2fce1b93..2b61cd20 100644 --- a/commands/games/lottery.js +++ b/commands/games/lottery.js @@ -16,7 +16,7 @@ module.exports = class LotteryCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } const lottery = ['Winner'][Math.floor(Math.random() * 100)]; - const userName = message.member ? message.member.displayName : message.author.username; + const userName = message.author.username; if (lottery !== 'Winner') return message.say(`Nope, sorry ${userName}, you lost.`); return message.say(`Wow ${userName}! You actually won! Great job!`); } diff --git a/commands/games/quiz.js b/commands/games/quiz.js index 44f9c3c6..89f1561c 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -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 QuizCommand extends Command { constructor(client) { @@ -22,11 +22,8 @@ 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 request - .get('http://jservice.io/api/random') - .query({ - count: 1 - }); + const response = await snekfetch + .get('http://jservice.io/api/random?count=1'); const data = response.body[0]; const answer = data.answer.toLowerCase().replace(/(|<\/i>)/g, ''); const embed = new RichEmbed() diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index 339e0099..72e9cb14 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -16,7 +16,7 @@ module.exports = class BanCommand extends Command { args: [{ key: 'member', prompt: 'What member do you want to ban?', - type: 'member' + type: 'user' }, { key: 'reason', prompt: 'What do you want to set the reason as?', @@ -41,7 +41,10 @@ module.exports = class BanCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS')) return message.say(':x: Error! I don\'t have the Ban Members Permission!'); } if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!'); - const member = args.member; + let member = message.guild.member(args.member); + if (!member) { + member = await message.guild.fetchMember(args.member); + } const reason = args.reason; if (!member.bannable) return message.say(':x: Error! This member cannot be banned! Perhaps they have a higher role than me?'); try { diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index 307bccb4..d736c0d1 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -13,7 +13,7 @@ module.exports = class KickCommand extends Command { args: [{ key: 'member', prompt: 'What member do you want to kick?', - type: 'member' + type: 'user' }, { key: 'reason', prompt: 'What do you want to set the reason as?', @@ -38,7 +38,10 @@ module.exports = class KickCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('KICK_MEMBERS')) return message.say(':x: Error! I don\'t have the Kick Members Permission!'); } if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!'); - const member = args.member; + let member = message.guild.member(args.member); + if (!member) { + member = await message.guild.fetchMember(args.member); + } const reason = args.reason; if (!member.bannable) return message.say(':x: Error! This member cannot be kicked! Perhaps they have a higher role than me?'); try { diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 5aaa5950..20398f9d 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -13,7 +13,7 @@ module.exports = class WarnCommand extends Command { args: [{ key: 'member', prompt: 'What member do you want to warn?', - type: 'member' + type: 'user' }, { key: 'reason', prompt: 'What do you want to set the reason as?', @@ -36,7 +36,10 @@ module.exports = class WarnCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const member = args.member; + let member = message.guild.member(args.member); + if (!member) { + member = await message.guild.fetchMember(args.member); + } const reason = args.reason; if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!'); try { diff --git a/commands/numedit/math.js b/commands/random/math.js similarity index 97% rename from commands/numedit/math.js rename to commands/random/math.js index d7863db0..e0677a2e 100644 --- a/commands/numedit/math.js +++ b/commands/random/math.js @@ -11,7 +11,7 @@ module.exports = class MathCommand extends Command { 'multiply', 'divide' ], - group: 'numedit', + group: 'random', memberName: 'math', description: 'Does Math (;math 2 + 2)', examples: [';math 2 + 2'], diff --git a/commands/random/strawpoll.js b/commands/random/strawpoll.js index e15d9b97..7ac2fdbe 100644 --- a/commands/random/strawpoll.js +++ b/commands/random/strawpoll.js @@ -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, diff --git a/commands/random/today.js b/commands/random/today.js index 3e348d9c..57eca714 100644 --- a/commands/random/today.js +++ b/commands/random/today.js @@ -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); diff --git a/commands/search/botinfo.js b/commands/search/botinfo.js index ae6bc2dd..75d21ca2 100644 --- a/commands/search/botinfo.js +++ b/commands/search/botinfo.js @@ -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 BotSearchCommand extends Command { constructor(client) { @@ -29,7 +29,7 @@ module.exports = class BotSearchCommand extends Command { } const bot = args.bot.id; try { - const response = await request + const response = await snekfetch .get(`https://bots.discord.pw/api/bots/${bot}`) .set({ 'Authorization': process.env.DISCORD_BOTS_KEY diff --git a/commands/search/define.js b/commands/search/define.js index 9d992dfb..8e7d3fec 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -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 DefineCommand extends Command { constructor(client) { @@ -29,17 +29,10 @@ module.exports = class DefineCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const word = encodeURI(args.word); + const word = encodeURIComponent(args.word); try { - const response = await request - .get(`http://api.wordnik.com:80/v4/word.json/${word}/definitions`) - .query({ - limit: 1, - includeRelated: false, - useCanonical: false, - includeTags: false, - api_key: process.env.WORDNIK_KEY - }); + const response = await snekfetch + .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() .setColor(0x9797FF) diff --git a/commands/search/forecast.js b/commands/search/forecast.js index 20e6f64b..8a07c181 100644 --- a/commands/search/forecast.js +++ b/commands/search/forecast.js @@ -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 ForecastCommand extends Command { constructor(client) { @@ -26,14 +26,10 @@ module.exports = class ForecastCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const location = args.locationQ; + const location = encodeURIComponent(args.locationQ); try { - const response = await request - .get('https://query.yahooapis.com/v1/public/yql') - .query({ - q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${location}")`, - format: 'json' - }); + const response = await snekfetch + .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; const embed = new RichEmbed() diff --git a/commands/search/google.js b/commands/search/google.js index b1808ee7..d24f4a76 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); const cheerio = require('cheerio'); const querystring = require('querystring'); @@ -26,14 +26,11 @@ module.exports = class GoogleCommand extends Command { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } - const query = args.query; + const query = encodeURIComponent(args.query); const msg = await message.say('Searching...'); try { - const response = await request - .get(`https://www.google.com/search`) - .query({ - q: query - }); + const response = await snekfetch + .get(`https://www.google.com/search?q=${query}`); const $ = cheerio.load(response.text); let href = $('.r').first().find('a').first().attr('href'); href = querystring.parse(href.replace('/url?', '')); diff --git a/commands/search/imdb.js b/commands/search/imdb.js index 30e61457..d7ada0f8 100644 --- a/commands/search/imdb.js +++ b/commands/search/imdb.js @@ -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 IMDBCommand extends Command { constructor(client) { @@ -28,14 +28,10 @@ module.exports = class IMDBCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const movie = args.movie; + const movie = encodeURIComponent(args.movie); try { - const response = await request - .get(`http://www.omdbapi.com/`) - .query({ - t: movie, - plot: 'full' - }); + const response = await snekfetch + .get(`http://www.omdbapi.com/?t=${movie}&plot=full`); const data = response.body; const embed = new RichEmbed() .setColor(0xDBA628) diff --git a/commands/search/map.js b/commands/search/map.js index 100f8f29..9db0dd36 100644 --- a/commands/search/map.js +++ b/commands/search/map.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); module.exports = class MapCommand extends Command { constructor(client) { @@ -36,16 +36,10 @@ module.exports = class MapCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } const zoom = args.zoom; - const locationQ = args.locationQ; + const location = encodeURIComponent(args.locationQ); try { - const response = await request - .get('https://maps.googleapis.com/maps/api/staticmap') - .query({ - center: locationQ, - zoom: zoom, - size: '500x500', - key: process.env.GOOGLE_KEY - }); + const response = await snekfetch + .get(`https://maps.googleapis.com/maps/api/staticmap?center=${location}&zoom=${zoom}&size=500x500&key=${process.env.GOOGLE_KEY}`); return message.channel.sendFile(response.body); } catch (err) { diff --git a/commands/search/neopet.js b/commands/search/neopet.js index c6f8d2a5..ad2b3da3 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); const cheerio = require('cheerio'); module.exports = class NeopetCommand extends Command { @@ -23,15 +23,10 @@ module.exports = class NeopetCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); } - const pet = args.pet; + const pet = encodeURIComponent(args.pet); try { - const response = await request - .get('http://www.sunnyneo.com/petimagefinder.php') - .query({ - name: pet, - size: 5, - mood: 1 - }); + const response = await snekfetch + .get(`http://www.sunnyneo.com/petimagefinder.php?name=${pet}&size=5&mood=1`); const $ = cheerio.load(response.text); const link = $('textarea').first().text(); if (!link.includes('cp')) return message.say(':x: Error! Pet not found!'); diff --git a/commands/search/osu.js b/commands/search/osu.js index 5a305e66..3a635d5b 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -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 OsuCommand extends Command { constructor(client) { @@ -28,15 +28,10 @@ module.exports = class OsuCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const username = args.username; + const username = encodeURIComponent(args.username); try { - const response = await request - .get('https://osu.ppy.sh/api/get_user') - .query({ - k: process.env.OSU_KEY, - u: username, - type: 'string' - }); + const response = await snekfetch + .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() .setColor(0xFF66AA) diff --git a/commands/search/urban.js b/commands/search/urban.js index b728ac70..82e1b8fb 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -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 UrbanCommand extends Command { constructor(client) { @@ -28,13 +28,10 @@ module.exports = class UrbanCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const word = args.word; + const word = encodeURIComponent(args.word); try { - const response = await request - .get('http://api.urbandictionary.com/v0/define') - .query({ - term: word - }); + const response = await snekfetch + .get(`http://api.urbandictionary.com/v0/define?term=${word}`); const data = response.body.list[0]; const embed = new RichEmbed() .setColor(0x32a8f0) diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 5d432fda..68793700 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -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 WattpadCommand extends Command { constructor(client) { @@ -23,16 +23,12 @@ module.exports = class WattpadCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const book = args.book; + const book = encodeURIComponent(args.book); try { - const response = await request - .get('https://api.wattpad.com:443/v4/stories') + const response = await snekfetch + .get(`https://api.wattpad.com:443/v4/stories?query=${book}&limit=1`) .set({ 'Authorization': `Basic ${process.env.WATTPAD_KEY}` - }) - .query({ - query: book, - limit: 1 }); const data = response.body.stories[0]; const embed = new RichEmbed() diff --git a/commands/search/weather.js b/commands/search/weather.js index 70df48bc..fb81ebc0 100644 --- a/commands/search/weather.js +++ b/commands/search/weather.js @@ -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 WeatherCommand extends Command { constructor(client) { @@ -23,14 +23,10 @@ module.exports = class WeatherCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const location = args.locationQ; + const location = encodeURIComponent(args.locationQ); try { - const response = await request - .get('https://query.yahooapis.com/v1/public/yql') - .query({ - q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${location}")`, - format: 'json' - }); + const response = await snekfetch + .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() .setColor(0x0000FF) diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index 0bc5185e..27182062 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -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 WikipediaCommand extends Command { constructor(client) { @@ -23,27 +23,16 @@ module.exports = class WikipediaCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const query = args.query.replace(/[)]/g, '%29'); - const title = encodeURI(query); + const query = encodeURIComponent(args.query.replace(/[)]/g, '%29')); try { - const response = await request - .get(`https://en.wikipedia.org/w/api.php`) - .query({ - action: 'query', - prop: 'extracts', - format: 'json', - titles: query, - exintro: '', - explaintext: '', - redirects: '', - formatversion: 2 - }); + const response = await snekfetch + .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'); const embed = new RichEmbed() .setColor(0xE7E7E7) .setTitle(data.title) - .setURL(`https://en.wikipedia.org/wiki/${title}`) + .setURL(`https://en.wikipedia.org/wiki/${query}`) .setAuthor('Wikipedia', 'https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png') .setDescription(description); return message.embed(embed); diff --git a/commands/search/youtube.js b/commands/search/youtube.js index a39ef232..d7c90abf 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -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 YouTubeCommand extends Command { constructor(client) { @@ -26,17 +26,10 @@ module.exports = class YouTubeCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const video = args.video; + const video = encodeURIComponent(args.video); try { - const response = await request - .get('https://www.googleapis.com/youtube/v3/search') - .query({ - part: 'snippet', - type: 'video', - maxResults: 1, - q: video, - key: process.env.GOOGLE_KEY - }); + const response = await snekfetch + .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() .setColor(0xDD2825) diff --git a/commands/search/yugioh.js b/commands/search/yugioh.js index c2e25a18..d3bc990d 100644 --- a/commands/search/yugioh.js +++ b/commands/search/yugioh.js @@ -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 YuGiOhCommand extends Command { constructor(client) { @@ -23,9 +23,9 @@ module.exports = class YuGiOhCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } - const card = encodeURI(args.card); + const card = encodeURIComponent(args.card); try { - const response = await request + const response = await snekfetch .get(`http://yugiohprices.com/api/card_data/${card}`); const data = response.body.data; if (data.card_type === 'monster') { diff --git a/commands/textedit/languages.json b/commands/textedit/languages.json new file mode 100644 index 00000000..a9589e9b --- /dev/null +++ b/commands/textedit/languages.json @@ -0,0 +1,97 @@ +{ + "languages": { + "af": "Afrikaans", + "am": "Amharic", + "ar": "Arabic", + "az": "Azerbaijani", + "ba": "Bashkir", + "be": "Belarusian", + "bg": "Bulgarian", + "bn": "Bengali", + "bs": "Bosnian", + "ca": "Catalan", + "ceb": "Cebuano", + "cs": "Czech", + "cy": "Welsh", + "da": "Danish", + "de": "German", + "el": "Greek", + "en": "English", + "eo": "Esperanto", + "es": "Spanish", + "et": "Estonian", + "eu": "Basque", + "fa": "Persian", + "fi": "Finnish", + "fr": "French", + "ga": "Irish", + "gd": "Scots Gaelic", + "gl": "Galician", + "gu": "Gujarati", + "he": "Hebrew", + "hi": "Hindi", + "hr": "Croatian", + "ht": "Haitian", + "hu": "Hungarian", + "hy": "Armenian", + "id": "Indonesian", + "is": "Icelandic", + "it": "Italian", + "ja": "Japanese", + "jv": "Javanese", + "ka": "Georgian", + "kk": "Kazakh", + "km": "Khmer", + "kn": "Kannada", + "ko": "Korean", + "ky": "Kyrgyz", + "la": "Latin", + "lb": "Luxembourgish", + "lo": "Loa", + "lt": "Lithuanian", + "lv": "Latvian", + "mg": "Malagasy", + "mhr": "Mari", + "mi": "Maori", + "mk": "Macedonian", + "ml": "Malayalam", + "mn": "Mongolian", + "mr": "Marathi", + "mrj": "Hill Mari", + "ms": "Malay", + "mt": "Maltese", + "my": "Burmese", + "ne": "Nepali", + "nl": "Dutch", + "no": "Norwegian", + "pa": "Punjabi", + "pap": "Papiamento", + "pl": "Polish", + "pt": "Portuguese", + "ro": "Romanian", + "ru": "Russian", + "si": "Sinhalese", + "sk": "Slovak", + "sl": "Slovenian", + "sq": "Albanian", + "sr": "Serbian", + "su": "Sundanese", + "sv": "Swedish", + "sw": "Swahili", + "ta": "Tamil", + "te": "Telugu", + "tg": "Tajik", + "th": "Thai", + "tl": "Tagalog", + "tr": "Turkish", + "tt": "Tatar", + "udm": "Udmurt", + "uk": "Ukrainian", + "ur": "Urdu", + "uz": "Uzbek", + "vi": "Vietnamese", + "xh": "Xhosa", + "yi": "Yiddish", + "zh": "Chinese" + } +} diff --git a/commands/textedit/morse.js b/commands/textedit/morse.js index 6988a11a..6024f90a 100644 --- a/commands/textedit/morse.js +++ b/commands/textedit/morse.js @@ -1,47 +1,6 @@ const { Command } = require('discord.js-commando'); const translator = require('custom-translate'); -const morse = { - "a": ".-", - "b": "-...", - "c": "-.-.", - "d": "-..", - "e": ".", - "f": "..-.", - "g": "--.", - "h": "....", - "i": "..", - "j": ".---", - "k": "-.-", - "l": ".-..", - "m": "--", - "n": "-.", - "o": "---", - "p": ".--.", - "q": "--.-", - "r": ".-.", - "s": "...", - "t": "-", - "u": "..-", - "v": "...-", - "w": ".--", - "x": "-..-", - "y": "-.--", - "z": "--..", - "0": "-----", - "1": ".----", - "2": "..---", - "3": "...--", - "4": "....-", - "5": ".....", - "6": "-....", - "7": "--...", - "8": "---..", - "9": "----.", - ".": ".-.-.-", - "?": "..--..", - ",": "--..--", - "'": ".----." -}; +const { dictionary } = require('./morsemappings.json'); module.exports = class MorseCommand extends Command { constructor(client) { @@ -59,7 +18,7 @@ module.exports = class MorseCommand extends Command { prompt: 'What text would you like to convert to morse?', type: 'string', validate: content => { - if (translator.letterTrans(content, morse, ' ').length < 1900) { + if (translator.letterTrans(content, dictionary, ' ').length < 1900) { return true; } return 'Your text to encode is too long.'; @@ -73,7 +32,7 @@ module.exports = class MorseCommand extends Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } const text = args.text.toLowerCase(); - const encoded = translator.letterTrans(text, morse, ' '); + const encoded = translator.letterTrans(text, dictionary, ' '); return message.say(encoded); } }; diff --git a/commands/textedit/morsemappings.json b/commands/textedit/morsemappings.json new file mode 100644 index 00000000..680156eb --- /dev/null +++ b/commands/textedit/morsemappings.json @@ -0,0 +1,44 @@ +{ + "dictionary": { + "a": ".-", + "b": "-...", + "c": "-.-.", + "d": "-..", + "e": ".", + "f": "..-.", + "g": "--.", + "h": "....", + "i": "..", + "j": ".---", + "k": "-.-", + "l": ".-..", + "m": "--", + "n": "-.", + "o": "---", + "p": ".--.", + "q": "--.-", + "r": ".-.", + "s": "...", + "t": "-", + "u": "..-", + "v": "...-", + "w": ".--", + "x": "-..-", + "y": "-.--", + "z": "--..", + "0": "-----", + "1": ".----", + "2": "..---", + "3": "...--", + "4": "....-", + "5": ".....", + "6": "-....", + "7": "--...", + "8": "---..", + "9": "----.", + ".": ".-.-.-", + "?": "..--..", + ",": "--..--", + "'": ".----." + } +} diff --git a/commands/textedit/translate.js b/commands/textedit/translate.js index 5df1a50e..292bbff2 100644 --- a/commands/textedit/translate.js +++ b/commands/textedit/translate.js @@ -1,101 +1,7 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); -const request = require('superagent'); -const languages = { - "af": "Afrikaans", - "am": "Amharic", - "ar": "Arabic", - "az": "Azerbaijani", - "ba": "Bashkir", - "be": "Belarusian", - "bg": "Bulgarian", - "bn": "Bengali", - "bs": "Bosnian", - "ca": "Catalan", - "ceb": "Cebuano", - "cs": "Czech", - "cy": "Welsh", - "da": "Danish", - "de": "German", - "el": "Greek", - "en": "English", - "eo": "Esperanto", - "es": "Spanish", - "et": "Estonian", - "eu": "Basque", - "fa": "Persian", - "fi": "Finnish", - "fr": "French", - "ga": "Irish", - "gd": "Scots Gaelic", - "gl": "Galician", - "gu": "Gujarati", - "he": "Hebrew", - "hi": "Hindi", - "hr": "Croatian", - "ht": "Haitian", - "hu": "Hungarian", - "hy": "Armenian", - "id": "Indonesian", - "is": "Icelandic", - "it": "Italian", - "ja": "Japanese", - "jv": "Javanese", - "ka": "Georgian", - "kk": "Kazakh", - "km": "Khmer", - "kn": "Kannada", - "ko": "Korean", - "ky": "Kyrgyz", - "la": "Latin", - "lb": "Luxembourgish", - "lo": "Loa", - "lt": "Lithuanian", - "lv": "Latvian", - "mg": "Malagasy", - "mhr": "Mari", - "mi": "Maori", - "mk": "Macedonian", - "ml": "Malayalam", - "mn": "Mongolian", - "mr": "Marathi", - "mrj": "Hill Mari", - "ms": "Malay", - "mt": "Maltese", - "my": "Burmese", - "ne": "Nepali", - "nl": "Dutch", - "no": "Norwegian", - "pa": "Punjabi", - "pap": "Papiamento", - "pl": "Polish", - "pt": "Portuguese", - "ro": "Romanian", - "ru": "Russian", - "si": "Sinhalese", - "sk": "Slovak", - "sl": "Slovenian", - "sq": "Albanian", - "sr": "Serbian", - "su": "Sundanese", - "sv": "Swedish", - "sw": "Swahili", - "ta": "Tamil", - "te": "Telugu", - "tg": "Tajik", - "th": "Thai", - "tl": "Tagalog", - "tr": "Turkish", - "tt": "Tatar", - "udm": "Udmurt", - "uk": "Ukrainian", - "ur": "Urdu", - "uz": "Uzbek", - "vi": "Vietnamese", - "xh": "Xhosa", - "yi": "Yiddish", - "zh": "Chinese" -}; +const snekfetch = require('snekfetch'); +const { languages } = require('./languages.json'); module.exports = class TranslateCommand extends Command { constructor(client) { @@ -136,15 +42,10 @@ module.exports = class TranslateCommand 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!'); } const language = args.to.toLowerCase(); - const query = args.text; + const query = encodeURIComponent(args.text); try { - const response = await request - .get(`https://translate.yandex.net/api/v1.5/tr.json/translate`) - .query({ - key: process.env.YANDEX_KEY, - lang: language, - text: query - }); + const response = await snekfetch + .get(`https://translate.yandex.net/api/v1.5/tr.json/translate?key=${process.env.YANDEX_KEY}&lang=${language}&text=${query}`); const data = response.body; const translated = data.text[0]; const langs = data.lang.split('-'); diff --git a/commands/textedit/webhook.js b/commands/textedit/webhook.js index 99cf94ab..1aad8f6d 100644 --- a/commands/textedit/webhook.js +++ b/commands/textedit/webhook.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); module.exports = class WebhookCommand extends Command { constructor(client) { @@ -33,7 +33,7 @@ module.exports = class WebhookCommand extends Command { const text = args.text; try { await message.delete(); - await request + await snekfetch .post(process.env.WEBHOOK_URL) .send({ content: text diff --git a/commands/textedit/yoda.js b/commands/textedit/yoda.js index abd4345e..cc5e7bcf 100644 --- a/commands/textedit/yoda.js +++ b/commands/textedit/yoda.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); module.exports = class YodaCommand extends Command { constructor(client) { @@ -21,16 +21,13 @@ module.exports = class YodaCommand extends Command { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } - const text = args.text; + const text = encodeURIComponent(args.text); try { - const response = await request - .get('https://yoda.p.mashape.com/yoda') + const response = await snekfetch + .get(`https://yoda.p.mashape.com/yoda?sentence=${text}`) .set({ 'X-Mashape-Key': process.env.MASHAPE_KEY, 'Accept': 'text/plain' - }) - .query({ - sentence: text }); return message.say(`\u180E${response.text}`); } diff --git a/commands/userinfo/userinfo.js b/commands/userinfo/userinfo.js index 3b30c4b6..cd23ae03 100644 --- a/commands/userinfo/userinfo.js +++ b/commands/userinfo/userinfo.js @@ -25,12 +25,16 @@ module.exports = class UserInfoCommand extends Command { }); } - run(message, args) { + async run(message, args) { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); } const user = args.user; + let member = message.guild.member(user); + if (!member) { + member = await message.guild.fetchMember(user); + } let stat; let color; switch (user.presence.status) { @@ -62,7 +66,7 @@ module.exports = class UserInfoCommand extends Command { .addField('**Joined Discord On:**', `${user.createdAt}\n${moment.duration(Date.now() - user.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) .addField('**Joined Server On:**', - `${message.guild.member(user).joinedAt}\n${moment.duration(Date.now() - message.guild.member(user).joinedTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) + `${member.joinedAt}\n${moment.duration(Date.now() - member.joinedTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) .addField('**Status:**', stat, true) .addField('**Playing:**', diff --git a/commands/util/info.js b/commands/util/info.js index d4acb14a..f4faf0bc 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -47,7 +47,7 @@ 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), [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/)') + '[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/)') .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/), [Yoda Speak](https://market.mashape.com/ismaelc/yoda-speak), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Yandex.Translate](https://translate.yandex.com/developers), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/)'); return message.embed(embed); diff --git a/html/carbondesc.html b/html/carbondesc.html index 5d048cf3..197226cd 100644 --- a/html/carbondesc.html +++ b/html/carbondesc.html @@ -20,7 +20,7 @@
  • discord.js-commando
  • JIMP
  • zalgoize
  • -
  • superagent
  • +
  • snekfetch
  • mathjs
  • moment
  • moment-duration-format
  • diff --git a/html/discordbots.html b/html/discordbots.html index 52036406..3618dd95 100644 --- a/html/discordbots.html +++ b/html/discordbots.html @@ -66,7 +66,7 @@
  • discord.js-commando
  • JIMP
  • zalgoize
  • -
  • superagent
  • +
  • snekfetch
  • mathjs
  • moment
  • moment-duration-format
  • diff --git a/index.js b/index.js index 65da87dd..722a5209 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const commando = require('discord.js-commando'); -const request = require('superagent'); +const snekfetch = require('snekfetch'); const path = require('path'); const client = new commando.Client({ commandPrefix: ';', @@ -18,7 +18,6 @@ client.registry ['randomimg', 'Random Image'], ['avataredit', 'Avatar Manipulation'], ['textedit', 'Text Manipulation'], - ['numedit', 'Number Manipulation'], ['imageedit', 'Image Manipulation'], ['search', 'Search'], ['games', 'Games'], @@ -37,7 +36,7 @@ client.on('guildCreate', async(guild) => { const count = guilds.reduce((prev, val) => prev + val, 0); console.log(`[Count] ${count}`); try { - const response = await request + const response = await snekfetch .post('https://www.carbonitex.net/discord/data/botdata.php') .send({ key: process.env.CARBON_KEY, @@ -49,7 +48,7 @@ client.on('guildCreate', async(guild) => { console.log(`[Carbon] Failed to post to Carbon. ${err}`); } try { - const response = await request + const response = await snekfetch .post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`) .set({ 'Authorization': process.env.DISCORD_BOTS_KEY @@ -70,7 +69,7 @@ client.on('guildDelete', async(guild) => { const count = guilds.reduce((prev, val) => prev + val, 0); console.log(`[Count] ${count}`); try { - const response = await request + const response = await snekfetch .post('https://www.carbonitex.net/discord/data/botdata.php') .send({ key: process.env.CARBON_KEY, @@ -82,7 +81,7 @@ client.on('guildDelete', async(guild) => { console.log(`[Carbon] Failed to post to Carbon. ${err}`); } try { - const response = await request + const response = await snekfetch .post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`) .set({ 'Authorization': process.env.DISCORD_BOTS_KEY diff --git a/package.json b/package.json index fed87868..c3046e8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "24.5.0", + "version": "25.0.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": { @@ -36,7 +36,7 @@ "mathjs": "^3.11.0", "moment": "^2.18.1", "moment-duration-format": "^1.3.0", - "superagent": "^3.5.2", + "snekfetch": "^2.2.3", "zalgolize": "^1.2.4" } }