community-relations/src/commands/score_notify.ts

37 lines
1.6 KiB
TypeScript

import { Message } from 'eris';
import { Client, Command } from '../class';
export default class Score_Notify extends Command {
constructor(client: Client) {
super(client);
this.name = 'notify';
this.description = 'Edits your notification preferences for Hard Inquiries.';
this.usage = `${this.client.config.prefix}score notify <on | off>`;
this.permissions = 0;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
const user = message.author;
if (!user) return this.error(message.channel, 'Member not found.');
const score = await this.client.db.Score.findOne({ userID: message.author.id });
if (!score) return this.error(message.channel, 'Score not calculated yet.');
if (!score.notify) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { notify: false } });
switch (args[0]) {
case 'on':
await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { notify: true } });
return this.success(message.channel, 'You will now be sent notifications whenever your score is hard-pulled.');
case 'off':
await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { notify: false } });
return this.success(message.channel, 'You will no longer be sent notifications when your score is hard-pulled.');
default:
return this.error(message.channel, 'Invalid option. Valid options are `yes` and `no`.');
}
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}