From b90789074359c7d718286d0d65ed917cb5bd8b8b Mon Sep 17 00:00:00 2001 From: Acnologla <35548489+Acnologla@users.noreply.github.com> Date: Sun, 2 Dec 2018 22:20:38 -0200 Subject: [PATCH 1/2] Create discordjs --- src/commands/utility/discordjs | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/commands/utility/discordjs diff --git a/src/commands/utility/discordjs b/src/commands/utility/discordjs new file mode 100644 index 000000000..c7a4c87ed --- /dev/null +++ b/src/commands/utility/discordjs @@ -0,0 +1,101 @@ + + +const { CommandStructures, SwitchbladeEmbed } = require('../../') +const { Command, CommandParameters, StringParameter } = CommandStructures +const snekfetch = require("snekfetch") + +module.exports = class Avatar extends Command { + constructor (client) { + super(client) + this.name = 'discordjs' + this.aliases = ['doc', 'docs',"djs","d.js"] + this.category = 'utility' + this.parameters = new CommandParameters(this, + new StringParameter({ full: true, required: true, missingError: 'commands:djs.saySomething' }) + ) + + } + async run ({ t, author, channel },content) { + let {body} = await snekfetch.get("https://cdn.jsdelivr.net/gh/discordjs/discord.js@docs/stable.json") + let args = content.split(" ") + let doc = body.classes.find(a => a.name.toLowerCase() == args[0].toLowerCase()) + if (args.join(' ').split('.').length>1){ + let retorno = (()=>{ + let a = body.classes.find(a => a.name.toLowerCase() == args.join(' ').split('.')[0].toLowerCase()) + let b = args.join(' ').split('.')[1].toLowerCase() + if (!a | !b) return null; + if (a.props){ + if (a.props.find(c => c.name.toLowerCase() == b)) return a.props.find(c => c.name.toLowerCase() == b) + } + if (a.methods){ + if (a.methods.find(c => c.name.toLowerCase() == b)) return a.methods.find(c => c.name.toLowerCase() == b) + } + if (a.events){ + if (a.events.find(c => c.name.toLowerCase() == b)) return a.events.find(c => c.name.toLowerCase() == b) + } + })() + if (retorno){ + let obj ={ + embed:{ + title:retorno.name, + description: retorno.description, + color:65535, + thumbnail:{ + url:'https://discord.js.org/static/logo-square.png' + }, + fields:[] + } + } + if (retorno.params){ + retorno.params.forEach(function(c,d){ + obj.embed.fields.push({ + name: `Parameter ${c.name}:`, + value:`${c.description}\nType: **${c.type.join(' | ')}**\nRequired: **${c.optional ? "No" : "Yes"}** `, + inline:true + }) + }) + } + if (retorno.examples){ + retorno.examples.forEach(function(c,d){ + obj.embed.fields.push({ + name:`Example ${d+1}:`, + value:"```js\n" +c +"```", + inline:false + }) + }) + } + channel.send(obj) + return; + } + else return channel.send("Nothing") + } + if (!doc.name) return channel.send("Nothing") + let obj ={ + + embed:{ + title:doc.name, + description:doc.description, + color:65535, + thumbnail:{ + url:'https://discord.js.org/static/logo-square.png' + }, + fields:[ + { + name:"Properties", + value:doc.props.map(a => `${a.name} `).slice(0,30).join('\n'), + inline:true + },{ + name:"Methods", + value:doc.methods.map(a => `${a.name} `).slice(0,30).join('\n'), + inline:true + }, + ] + } + } + + if (doc.events){ + obj.embed.fields.push({name:"Events",value:doc.events.map(a => `${a.name} `).slice(0,30).join('\n') }) + } + channel.send(obj) + } +} From 1a0694a7824e47fb36a5f97a9dc2e5d42f8e591b Mon Sep 17 00:00:00 2001 From: Pedro Fracassi Date: Sun, 2 Dec 2018 23:56:56 -0200 Subject: [PATCH 2/2] Fix file name and aliases --- src/commands/utility/{discordjs => discordjs.js} | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) rename src/commands/utility/{discordjs => discordjs.js} (95%) diff --git a/src/commands/utility/discordjs b/src/commands/utility/discordjs.js similarity index 95% rename from src/commands/utility/discordjs rename to src/commands/utility/discordjs.js index c7a4c87ed..4dc8baf11 100644 --- a/src/commands/utility/discordjs +++ b/src/commands/utility/discordjs.js @@ -1,21 +1,19 @@ - - const { CommandStructures, SwitchbladeEmbed } = require('../../') const { Command, CommandParameters, StringParameter } = CommandStructures const snekfetch = require("snekfetch") -module.exports = class Avatar extends Command { +module.exports = class DiscordJSDocs extends Command { constructor (client) { super(client) this.name = 'discordjs' - this.aliases = ['doc', 'docs',"djs","d.js"] + this.aliases = ['djs'] this.category = 'utility' this.parameters = new CommandParameters(this, new StringParameter({ full: true, required: true, missingError: 'commands:djs.saySomething' }) ) } - async run ({ t, author, channel },content) { + async run ({ t, author, channel }, content) { let {body} = await snekfetch.get("https://cdn.jsdelivr.net/gh/discordjs/discord.js@docs/stable.json") let args = content.split(" ") let doc = body.classes.find(a => a.name.toLowerCase() == args[0].toLowerCase())