allow report locking
parent
a6291c715b
commit
be4ce13e8c
|
@ -33,6 +33,20 @@ export default class Score extends Command {
|
|||
return this.error(message.channel, 'Invalid option. Valid options are `yes` and `no`.');
|
||||
}
|
||||
}
|
||||
if (args[0] === 'lock' || args[0] === 'unlock') {
|
||||
if (!member) 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.locked) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } });
|
||||
switch (args[0]) {
|
||||
case 'lock':
|
||||
await this.client.db.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.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } });
|
||||
return this.success(message.channel, 'Your report is now unlocked.');
|
||||
}
|
||||
}
|
||||
if (!args[0] || !this.checkCustomPermissions(message.member, 2)) {
|
||||
member = message.member;
|
||||
if (!member) return this.error(message.channel, 'Member not found.');
|
||||
|
@ -45,6 +59,7 @@ export default class Score extends Command {
|
|||
const reason = args.slice(2).join(' ').split(':')[1];
|
||||
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.locked) return this.error(message.channel, 'The score report you have requested has been locked.');
|
||||
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) => {
|
||||
|
@ -119,6 +134,9 @@ export default class Score extends Command {
|
|||
embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true);
|
||||
embed.addField('Other', otherScore || 'N/C', true);
|
||||
embed.addField('Misc', miscScore || 'N/C', true);
|
||||
if (score.locked) {
|
||||
embed.addField('Status', 'Score Report Locked');
|
||||
}
|
||||
if (score.lastUpdate) {
|
||||
embed.setFooter('Report last updated', this.client.user.avatarURL);
|
||||
embed.setTimestamp(score.lastUpdate);
|
||||
|
|
|
@ -38,6 +38,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
cloudServices: number,
|
||||
other: number,
|
||||
staff: boolean,
|
||||
locked: boolean,
|
||||
notify: boolean,
|
||||
inquiries: [{ name: string, reason: string}?],
|
||||
} = {
|
||||
userID: member.user.id,
|
||||
|
@ -48,6 +50,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
cloudServices: 0,
|
||||
other: 0,
|
||||
staff: false,
|
||||
locked: false,
|
||||
notify: false,
|
||||
inquiries: [],
|
||||
};
|
||||
score = await (new client.db.Score(data)).save();
|
||||
|
|
|
@ -32,6 +32,7 @@ export interface ScoreInterface extends Document {
|
|||
staff: number,
|
||||
other: number,
|
||||
notify: boolean,
|
||||
locked: boolean,
|
||||
inquiries: [{ name: string, reason: string, date: Date }],
|
||||
lastUpdate: Date,
|
||||
}
|
||||
|
@ -46,6 +47,7 @@ const Score: Schema = new Schema({
|
|||
staff: Number,
|
||||
other: Number,
|
||||
notify: Boolean,
|
||||
locked: Boolean,
|
||||
inquiries: Array,
|
||||
lastUpdate: Date,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue