community-relations/src/commands/eris.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-07-28 15:41:26 -04:00
import { Message, EmbedOptions } from 'eris';
2020-12-25 20:16:41 -05:00
import axios, { AxiosResponse } from 'axios';
import { Client, Command } from '../class';
2020-07-28 15:41:26 -04:00
export default class Eris extends Command {
constructor(client: Client) {
super(client);
this.name = 'eris';
this.description = 'Get information about Eris.';
this.usage = 'eris <query>';
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]);
let res: AxiosResponse<{embed: EmbedOptions}>;
try {
res = await axios.get('https://erisdocs.cloud.libraryofcode.org/docs', { params: { search: args[0] } });
} catch (err) {
if (err.code === 404) return this.error(message.channel, 'Could not find information. Try something else.');
return this.error(message.channel, 'Please try again later, something unexpected happened.');
}
return message.channel.createMessage(res.data);
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}