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 1/3] 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); + } + } +} From c1fe2de75a53bf11ad3fb8e298e82d8348ba2bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Tue, 5 May 2020 09:36:40 -0400 Subject: [PATCH 2/3] defined variables type --- src/commands/djs.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index fde99d9..129083e 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -22,11 +22,11 @@ export default class DJS extends Command { 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 name: string = data.author?.name || ''; + const icon_url: string = data.author?.icon_url || ''; + const author_url: string = data.author?.url || ''; + const description: string = data.description || 'None'; + const title: string = data.title || ''; const embed = new RichEmbed(); embed.setAuthor(name, icon_url, author_url); From da7d68d7fbab370b184e668615a67fbf34cdb8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Sat, 9 May 2020 22:01:51 -0400 Subject: [PATCH 3/3] used await instead of .then().catch() (KhaaZ) --- src/commands/djs.ts | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 129083e..9060c82 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -17,35 +17,35 @@ export default class DJS extends Command { 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.'); + let res; + try { + res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); + } catch (err) { + this.error(message.channel, 'Please try again later, something unexpected happened.'); + return this.client.util.handleError(err, message, this); + } + const { data } = res; + if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); - const name: string = data.author?.name || ''; - const icon_url: string = data.author?.icon_url || ''; - const author_url: string = data.author?.url || ''; - const description: string = data.description || 'None'; - const title: string = data.title || ''; + const name: string = data.author?.name || ''; + const icon_url: string = data.author?.icon_url || ''; + const author_url: string = data.author?.url || ''; + const description: string = data.description || 'None'; + const title: string = 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); + 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) { return this.client.util.handleError(err, message, this); }