From 61e5acce66a892fdaf7413b219dec7e2a9eb8d8e Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 25 May 2017 15:29:57 +0000 Subject: [PATCH] Bulbapedia Command --- commands/search/bulbapedia.js | 52 +++++++++++++++++++++++++++++++++++ html/carbonfeat.html | 1 + html/discordbots.html | 1 + package.json | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 commands/search/bulbapedia.js diff --git a/commands/search/bulbapedia.js b/commands/search/bulbapedia.js new file mode 100644 index 00000000..8aea929f --- /dev/null +++ b/commands/search/bulbapedia.js @@ -0,0 +1,52 @@ +const { Command } = require('discord.js-commando'); +const { RichEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class BulbapediaCommand extends Command { + constructor(client) { + super(client, { + name: 'bulbapedia', + aliases: ['bulbagarden'], + group: 'search', + memberName: 'bulbapedia', + description: 'Searches Bulbapedia for something.', + args: [ + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + if (msg.channel.type !== 'dm') + if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) + return msg.say('This Command requires the `Embed Links` Permission.'); + const { query } = args; + try { + const { body } = await snekfetch + .get('http://bulbapedia.bulbagarden.net/w/api.php') + .query({ + action: 'query', + prop: 'extracts', + format: 'json', + titles: query, + exintro: '', + explaintext: '', + redirects: '', + formatversion: 2 + }); + if (body.query.pages[0].missing) throw new Error('No Results.'); + const embed = new RichEmbed() + .setColor(0x3E7614) + .setTitle(body.query.pages[0].title) + .setAuthor('Bulbapedia', 'https://i.imgur.com/09eYo5T.png') + .setDescription(body.query.pages[0].extract.substr(0, 2000).replace(/[\n]/g, '\n\n')); + return msg.embed(embed); + } catch (err) { + return msg.say(`${err.name}: ${err.message}`); + } + } +}; diff --git a/html/carbonfeat.html b/html/carbonfeat.html index c6a5bb51..425ead39 100644 --- a/html/carbonfeat.html +++ b/html/carbonfeat.html @@ -51,6 +51,7 @@
  • YuGiOh! Card Data
  • My Anime List
  • Github
  • +
  • Bulbapedia
  • LMGTFY Link Generation!
  • Translate Text to almost 100 languages!
  • diff --git a/html/discordbots.html b/html/discordbots.html index f37fcc84..b50896ad 100644 --- a/html/discordbots.html +++ b/html/discordbots.html @@ -48,6 +48,7 @@
  • YuGiOh! Card Data
  • My Anime List
  • Github
  • +
  • Bulbapedia
  • LMGTFY Link Generation!
  • Translate Text to almost 100 languages!
  • diff --git a/package.json b/package.json index 12fd2be0..e545ad6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "21.0.0", + "version": "21.1.0", "description": "A Discord Bot", "main": "Shard.js", "scripts": {