diff --git a/README.md b/README.md index 81cf17a4..996748f1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (297) +## Commands (298) ### Utility: * **eval**: Executes JavaScript code. @@ -119,6 +119,7 @@ on the [home server](https://discord.gg/sbMe32W). * **danbooru**: Responds with an image from Danbooru, with optional query. * **deviantart**: Responds with an image from a DeviantArt section, with optional query. * **dictionary**: Defines a word. +* **discord-js-docs**: Searches the Discord.js docs for your query. * **eshop**: Searches the Nintendo eShop for your query. * **flickr**: Searches Flickr for your query. * **forecast**: Responds with the seven-day forecast for a specific location. diff --git a/commands/search/discord-js-docs.js b/commands/search/discord-js-docs.js new file mode 100644 index 00000000..63a962b3 --- /dev/null +++ b/commands/search/discord-js-docs.js @@ -0,0 +1,47 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const branches = ['stable', 'master', 'rpc', 'commando']; + +module.exports = class DiscordJSDocsCommand extends Command { + constructor(client) { + super(client, { + name: 'discord-js-docs', + aliases: ['djs-docs', 'docs', 'djs', 'discord-js'], + group: 'search', + memberName: 'discord-js-docs', + description: 'Searches the Discord.js docs for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What would you like to search the docs for?', + type: 'string', + parse: query => query.toLowerCase() + } + ] + }); + } + + async run(msg, { query }) { + let project = 'main'; + let branch = query.split(' '); + if (branches.includes(branch[0])) { + query = branch.slice(1).join(' '); + branch = branch[0]; + } else { + branch = 'master'; + } + if (branch === 'commando' || branch === 'rpc') { + project = branch; + branch = 'master'; + } + try { + const { body } = await request + .get(`https://djsdocs.sorta.moe/${project}/${branch}/embed`) + .query({ q: query }); + return msg.embed(body); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index be26c6fa..d0a1619c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.7.1", + "version": "85.8.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {