updates to score

pull/29/head
Matthew 2020-09-10 00:54:19 -04:00
parent 6d270ba046
commit 50697482e1
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
2 changed files with 24 additions and 1 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable default-case */
import { Member, Message } from 'eris'; import { Member, Message } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
@ -6,7 +7,7 @@ export default class Score extends Command {
super(client); super(client);
this.name = 'score'; this.name = 'score';
this.description = 'Pulls a hard score report for a member.'; this.description = 'Pulls a hard score report for a member.';
this.usage = `${this.client.config.prefix}score <member> <type: 'hard' | 'soft'> <reporting department: ex. Library of Code sp-us | Cloud Account Services>:<reason>`; this.usage = `${this.client.config.prefix}score <member> <type: 'hard' | 'soft'> <reporting department: ex. Library of Code sp-us | Cloud Account Services>:<reason>\n${this.client.config.prefix}score notify <on | off>`;
this.permissions = 0; this.permissions = 0;
this.guildOnly = true; this.guildOnly = true;
this.enabled = true; this.enabled = true;
@ -17,6 +18,21 @@ export default class Score extends Command {
let member: Member; let member: Member;
if (!args[0] || !this.checkCustomPermissions(message.member, 2)) { if (!args[0] || !this.checkCustomPermissions(message.member, 2)) {
member = message.member; member = message.member;
if (args[0] === 'notify') {
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[1]) {
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`.');
}
}
} else { } else {
member = this.client.util.resolveMember(args[0], this.mainGuild); member = this.client.util.resolveMember(args[0], this.mainGuild);
if (args[1] === 'hard') { if (args[1] === 'hard') {
@ -26,6 +42,11 @@ export default class Score extends Command {
const score = await this.client.db.Score.findOne({ userID: member.user.id }); const score = await this.client.db.Score.findOne({ userID: member.user.id });
if (!score) return this.error(message.channel, 'Score not calculated yet.'); if (!score) return this.error(message.channel, 'Score not calculated yet.');
await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } }); await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } });
if (score.notify === true) {
await this.client.getDMChannel(member.user.id).then((chan) => {
chan.createMessage(`__**Community Score - Hard Pull Notification**__\n*You have signed up to be notified whenever your hard score has been pulled. See \`?score\` for more information.*\n\n**Department/Service:** ${name.toUpperCase()}`);
}).catch(() => {});
}
} }
} }
const score = await this.client.db.Score.findOne({ userID: member.user.id }); const score = await this.client.db.Score.findOne({ userID: member.user.id });

View File

@ -30,6 +30,7 @@ export interface ScoreInterface extends Document {
cloudServices: number, cloudServices: number,
// 0 or 20, 20 points are added if the user is a staff member // 0 or 20, 20 points are added if the user is a staff member
staff: number, staff: number,
notify: boolean,
inquiries: [{ name: string, reason: string, date: Date }], inquiries: [{ name: string, reason: string, date: Date }],
} }
@ -41,6 +42,7 @@ const Score: Schema = new Schema({
moderation: Number, moderation: Number,
cloudServices: Number, cloudServices: Number,
staff: Number, staff: Number,
notify: Boolean,
inquiries: Array, inquiries: Array,
}); });