diff --git a/src/commands/utility/djsdocs.js b/src/commands/utility/djsdocs.js new file mode 100644 index 000000000..34d4ff7bf --- /dev/null +++ b/src/commands/utility/djsdocs.js @@ -0,0 +1,35 @@ +const { Command } = require('../..') +const fetch = require('node-fetch') +const VALID_SOURCES = ['stable', 'master', 'commando', 'rpc', 'akairo-master', 'collection'] + +module.exports = class DjsDocs extends Command { + constructor (client) { + super({ + name: 'djsdocs', + aliases: ['djdocs'], + category: 'utility', + parameters: [{ + type: 'string', + full: true, + clean: false, + missingError: 'commands:docs.noQueryProvided' + }, [{ + type: 'string', + name: 'source', + aliases: ['src'], + required: false + }]] + }, client) + } + + async run ({ channel, flags }, query) { + const { source } = flags + const src = VALID_SOURCES.includes(source) ? source : 'stable' + + const queryParams = new URLSearchParams({ src, q: query }) + const embed = await fetch(`https://djsdocs.sorta.moe/v2/embed?${queryParams.toString()}`) + .then(res => res.json()) + + channel.send({ embed }).then(() => channel.stopTyping()) + } +} diff --git a/src/locales/en-US/commands.json b/src/locales/en-US/commands.json index 528a453a2..4dc80987a 100644 --- a/src/locales/en-US/commands.json +++ b/src/locales/en-US/commands.json @@ -14,6 +14,11 @@ "commandUsage": "", "noSentence": "You have to give me some text to reverse!" }, + "djsdocs": { + "commandDescription": "Shows information from the discord.js documentation.", + "commandUsage": "", + "noQueryProvided": "You have to give me a search query!" + }, "hmmm": { "commandDescription": "Shows a random image from /r/hmmm." },