community-relations/src/commands/delnote.ts

27 lines
976 B
TypeScript
Raw Normal View History

2020-07-23 08:32:54 -04:00
import { Message } from 'eris';
import { Command, Client } from '../class';
export default class DelNote extends Command {
constructor(client: Client) {
super(client);
this.name = 'delnote';
this.description = 'Deletes a note.';
this.usage = `${this.client.config.prefix}delnote <note id>`;
this.permissions = 1;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
const note = await this.client.db.Note.findOne({ _id: args[0] }).lean().exec().catch(() => {});
if (!note) return this.error(message.channel, 'Could not locate that note.');
await this.client.db.Note.deleteOne({ _id: note._id });
return this.success(message.channel, `Note # \`${note._id}\` has been deleted.`);
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}