From 97709b9b8727b008447c3f1c701c4de471cd4fdc Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 May 2020 00:39:11 +0100 Subject: [PATCH] Clean up command --- src/commands/djs.ts | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 9060c82..224150a 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -1,5 +1,5 @@ -import { Message } from 'eris'; -import axios from 'axios'; +import { Message, EmbedOptions } from 'eris'; +import axios, { AxiosResponse } from 'axios'; import { Client, Command, RichEmbed } from '../class'; export default class DJS extends Command { @@ -17,34 +17,10 @@ export default class DJS extends Command { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - 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; + const { data }: AxiosResponse = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); 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 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(); + const embed = new RichEmbed(data); return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this);