Update mdn

This commit is contained in:
Daniel Odendahl Jr
2017-11-05 15:36:01 +00:00
parent 2a82601523
commit 0c802745de
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -1,7 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { shorten } = require('../../util/Util');
module.exports = class MDNCommand extends Command { module.exports = class MDNCommand extends Command {
constructor(client) { constructor(client) {
@@ -16,7 +15,8 @@ module.exports = class MDNCommand extends Command {
{ {
key: 'query', key: 'query',
prompt: 'What article would you like to search for?', prompt: 'What article would you like to search for?',
type: 'string' type: 'string',
parse: query => query.replace(/#/g, '.prototype.')
} }
] ]
}); });
@@ -26,7 +26,11 @@ module.exports = class MDNCommand extends Command {
try { try {
const { body } = await snekfetch const { body } = await snekfetch
.get('https://developer.mozilla.org/en-US/search.json') .get('https://developer.mozilla.org/en-US/search.json')
.query({ q: query }); .query({
q: query,
locale: 'en-US',
highlight: false
});
if (!body.documents.length) return msg.say('Could not find any results.'); if (!body.documents.length) return msg.say('Could not find any results.');
const data = body.documents[0]; const data = body.documents[0];
const embed = new MessageEmbed() const embed = new MessageEmbed()
@@ -34,7 +38,7 @@ module.exports = class MDNCommand extends Command {
.setAuthor('MDN', 'https://i.imgur.com/DFGXabG.png') .setAuthor('MDN', 'https://i.imgur.com/DFGXabG.png')
.setURL(data.url) .setURL(data.url)
.setTitle(data.title) .setTitle(data.title)
.setDescription(shorten(data.excerpt)); .setDescription(data.excerpt);
return msg.embed(embed); return msg.embed(embed);
} catch (err) { } catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiaobot", "name": "xiaobot",
"version": "51.4.2", "version": "51.4.3",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "XiaoBot.js", "main": "XiaoBot.js",
"scripts": { "scripts": {