From 256ad170cb86b6d335eba262590e920c4f8e2641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Tue, 5 May 2020 08:51:20 -0400 Subject: [PATCH] Added discord.js docs command --- src/commands/djs.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/commands/djs.ts diff --git a/src/commands/djs.ts b/src/commands/djs.ts new file mode 100644 index 0000000..fde99d9 --- /dev/null +++ b/src/commands/djs.ts @@ -0,0 +1,53 @@ +import { Message } from 'eris'; +import axios from 'axios'; +import { Client, Command, RichEmbed } from '../class'; + +export default class DJS extends Command { + constructor(client: Client) { + super(client); + this.name = 'djs'; + this.description = 'Get information about Discord.js.'; + this.usage = 'djs '; + this.permissions = 0; + this.guildOnly = false; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + + return axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`) + .then((res) => { + const { data } = res; + if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); + + const name = data.author?.name || ''; + const icon_url = data.author?.icon_url || ''; + const author_url = data.author?.url || ''; + const description = data.description || 'None'; + const title = data.title || ''; + + const embed = new RichEmbed(); + embed.setAuthor(name, icon_url, author_url); + embed.setColor(0x2296f3); + embed.setTitle(title); + embed.setDescription(description); + if (data.fields !== undefined && data.fields.length > 0) { + data.fields.forEach((field) => { + embed.addField(field.name, field.value); + }); + } + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + return message.channel.createMessage({ embed }); + }) + .catch((err) => { + this.error(message.channel, 'Please try again later, something unexpected happened.'); + this.client.util.handleError(err, message, this); + }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +}