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`.');
|
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)) {
|
if (!args[0] || !this.checkCustomPermissions(message.member, 2)) {
|
||||||
member = message.member;
|
member = message.member;
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
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 reason = args.slice(2).join(' ').split(':')[1];
|
||||||
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.');
|
||||||
|
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() } } });
|
await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } });
|
||||||
if (score.notify === true) {
|
if (score.notify === true) {
|
||||||
await this.client.getDMChannel(member.user.id).then((chan) => {
|
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('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true);
|
||||||
embed.addField('Other', otherScore || 'N/C', true);
|
embed.addField('Other', otherScore || 'N/C', true);
|
||||||
embed.addField('Misc', miscScore || 'N/C', true);
|
embed.addField('Misc', miscScore || 'N/C', true);
|
||||||
|
if (score.locked) {
|
||||||
|
embed.addField('Status', 'Score Report Locked');
|
||||||
|
}
|
||||||
if (score.lastUpdate) {
|
if (score.lastUpdate) {
|
||||||
embed.setFooter('Report last updated', this.client.user.avatarURL);
|
embed.setFooter('Report last updated', this.client.user.avatarURL);
|
||||||
embed.setTimestamp(score.lastUpdate);
|
embed.setTimestamp(score.lastUpdate);
|
||||||
|
|
|
@ -38,6 +38,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
||||||
cloudServices: number,
|
cloudServices: number,
|
||||||
other: number,
|
other: number,
|
||||||
staff: boolean,
|
staff: boolean,
|
||||||
|
locked: boolean,
|
||||||
|
notify: boolean,
|
||||||
inquiries: [{ name: string, reason: string}?],
|
inquiries: [{ name: string, reason: string}?],
|
||||||
} = {
|
} = {
|
||||||
userID: member.user.id,
|
userID: member.user.id,
|
||||||
|
@ -48,6 +50,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
||||||
cloudServices: 0,
|
cloudServices: 0,
|
||||||
other: 0,
|
other: 0,
|
||||||
staff: false,
|
staff: false,
|
||||||
|
locked: false,
|
||||||
|
notify: false,
|
||||||
inquiries: [],
|
inquiries: [],
|
||||||
};
|
};
|
||||||
score = await (new client.db.Score(data)).save();
|
score = await (new client.db.Score(data)).save();
|
||||||
|
|
|
@ -32,6 +32,7 @@ export interface ScoreInterface extends Document {
|
||||||
staff: number,
|
staff: number,
|
||||||
other: number,
|
other: number,
|
||||||
notify: boolean,
|
notify: boolean,
|
||||||
|
locked: boolean,
|
||||||
inquiries: [{ name: string, reason: string, date: Date }],
|
inquiries: [{ name: string, reason: string, date: Date }],
|
||||||
lastUpdate: Date,
|
lastUpdate: Date,
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ const Score: Schema = new Schema({
|
||||||
staff: Number,
|
staff: Number,
|
||||||
other: Number,
|
other: Number,
|
||||||
notify: Boolean,
|
notify: Boolean,
|
||||||
|
locked: Boolean,
|
||||||
inquiries: Array,
|
inquiries: Array,
|
||||||
lastUpdate: Date,
|
lastUpdate: Date,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue