diff --git a/commands/search/mdn.js b/commands/search/mdn.js new file mode 100644 index 00000000..6d590968 --- /dev/null +++ b/commands/search/mdn.js @@ -0,0 +1,42 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class MDNCommand extends Command { + constructor(client) { + super(client, { + name: 'mdn', + aliases: ['mozilla-developer-network'], + group: 'search', + memberName: 'mdn', + description: 'Searches MDN for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What article would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { query } = args; + try { + const { body } = await snekfetch + .get('https://developer.mozilla.org/en-US/search.json') + .query({ q: query }); + if (!body.documents.length) return msg.say('Could not find any results.'); + const embed = new MessageEmbed() + .setColor(0x066FAD) + .setAuthor('MDN', 'https://i.imgur.com/ClMfs9l.png') + .setURL(body.documents[0].url) + .setTitle(body.documents[0].title) + .setDescription(body.documents[0].excerpt); + return msg.embed(embed); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/osu.js b/commands/search/osu.js index 9a131815..5b37887f 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -7,6 +7,7 @@ module.exports = class OsuCommand extends Command { constructor(client) { super(client, { name: 'osu', + aliases: ['osu-user'], group: 'search', memberName: 'osu', description: 'Searches osu! usernames for your query.', diff --git a/package.json b/package.json index bafcd8da..d749c88a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "38.7.3", + "version": "38.8.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {