2023-02-11 23:49:24 -05:00
|
|
|
import { TextChannel } from 'eris';
|
2022-03-22 12:15:54 -04:00
|
|
|
import axios from 'axios';
|
2021-12-23 22:36:13 -05:00
|
|
|
import { apply as Apply } from '.';
|
2023-02-11 23:49:24 -05:00
|
|
|
import { Client, CmdContext, Command, RichEmbed } from '../class';
|
2021-12-23 22:36:13 -05:00
|
|
|
|
|
|
|
export default class Inquiry_Remove extends Command {
|
|
|
|
public applyCommand: Apply;
|
|
|
|
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'rm';
|
|
|
|
this.description = 'Removes a Hard Inquiry.';
|
|
|
|
this.usage = `${this.client.config.prefix}inquiry rm <inquiry id>`;
|
|
|
|
this.aliases = ['remove', 'delete'];
|
|
|
|
this.permissions = 4;
|
|
|
|
this.guildOnly = true;
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
public async run(ctx: CmdContext) {
|
|
|
|
if (!ctx.args[0]) return this.client.commands.get('help').run(new CmdContext(ctx.message, [this.name]));
|
2022-03-22 12:15:54 -04:00
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
const inquiry = await this.client.db.mongo.Inquiry.findOne({ iid: ctx.args[0] });
|
|
|
|
if (!inquiry) return this.error(ctx.message.channel, 'Unable to find Inquiry.');
|
2022-03-22 12:15:54 -04:00
|
|
|
const member = this.client.util.resolveMember(inquiry.userID, this.mainGuild);
|
2023-02-11 23:49:24 -05:00
|
|
|
if (!member) return this.error(ctx.message.channel, 'Unable to locate member.');
|
2022-03-22 12:15:54 -04:00
|
|
|
const report = await this.client.db.mongo.Score.findOne({ userID: member.id });
|
2023-02-11 23:49:24 -05:00
|
|
|
if (!report) return this.error(ctx.message.channel, 'Unable to locate Community Report.');
|
2022-03-22 12:15:54 -04:00
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
if (inquiry.type !== 0) return this.error(ctx.message.channel, 'You can only remove Hard Inquiries.');
|
2022-03-22 12:15:54 -04:00
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
await this.client.db.mongo.Inquiry.deleteOne({ iid: ctx.args[0] });
|
2022-03-22 12:15:54 -04:00
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
embed.setTitle('Inquiry - Removed');
|
|
|
|
embed.addField('IID', inquiry.iid);
|
|
|
|
embed.addField('Member', `${member.username}#${member.discriminator} | <@${member.id}>`);
|
|
|
|
embed.addField('Department/Service', inquiry.name || 'N/A');
|
|
|
|
embed.addField('Reason', inquiry.reason || 'N/A');
|
|
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
|
|
embed.setTimestamp();
|
|
|
|
|
2021-12-23 22:36:13 -05:00
|
|
|
try {
|
2022-03-22 12:15:54 -04:00
|
|
|
await axios({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `https://eds.libraryofcode.org/dec/${inquiry.iid}?auth=${this.client.config.internalKey}`,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2023-02-11 23:49:24 -05:00
|
|
|
this.error(ctx.message.channel, `An error occurred while changing EDS data: ${e}\n*(This does not mean that the operation failed.)*`);
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
2022-03-22 12:15:54 -04:00
|
|
|
|
|
|
|
const log = <TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849');
|
|
|
|
log.createMessage({ embed });
|
|
|
|
|
|
|
|
const chan = await this.client.getDMChannel(member.id);
|
|
|
|
if (chan) {
|
|
|
|
chan.createMessage({ embed }).catch(() => {});
|
|
|
|
}
|
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
return this.success(ctx.message.channel, 'Inquiry successfully deleted.');
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
|
|
|
}
|