community-relations/src/commands/score_pref.ts

36 lines
1.5 KiB
TypeScript

import { Message } from 'eris';
import { Client, Command } from '../class';
export default class Score_Pref extends Command {
constructor(client: Client) {
super(client);
this.name = 'pref';
this.description = 'Locks or unlocks your Community Report.';
this.usage = `${this.client.config.prefix}score pref <lock | unlock>`;
this.permissions = 0;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!message.author) return this.error(message.channel, 'Member not found.');
const score = await this.client.db.mongo.Score.findOne({ userID: message.author.id });
if (!score) return this.error(message.channel, 'Score not calculated yet.');
if (!score.locked) await this.client.db.mongo.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } });
switch (args[0]) {
case 'lock':
await this.client.db.mongo.Score.updateOne({ userID: message.author.id }, { $set: { locked: true } });
return this.success(message.channel, 'Your report is now locked.');
case 'unlock':
await this.client.db.mongo.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } });
return this.success(message.channel, 'Your report is now unlocked.');
default:
return this.error(message.channel, 'Invalid input');
}
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}