Clean up command

merge-requests/12/head
Bsian 2020-05-17 00:39:11 +01:00
parent 9bc1576fc7
commit 97709b9b87
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 4 additions and 28 deletions

View File

@ -1,5 +1,5 @@
import { Message } from 'eris'; import { Message, EmbedOptions } from 'eris';
import axios from 'axios'; import axios, { AxiosResponse } from 'axios';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
export default class DJS extends Command { export default class DJS extends Command {
@ -17,34 +17,10 @@ export default class DJS extends Command {
try { try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
let res; const { data }: AxiosResponse<EmbedOptions> = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`);
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.'); if (!data) return this.error(message.channel, 'Could not find information. Try something else.');
const name: string = data.author?.name || ''; const embed = new RichEmbed(data);
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 }); return message.channel.createMessage({ embed });
} catch (err) { } catch (err) {
return this.client.util.handleError(err, message, this); return this.client.util.handleError(err, message, this);