add inquiries to scores
parent
e0600c2d63
commit
ea5447cf5d
|
@ -1,4 +1,4 @@
|
|||
import { Guild, Member, Message, TextableChannel } from 'eris';
|
||||
import { Member, Message, TextableChannel } from 'eris';
|
||||
import { Client } from '.';
|
||||
|
||||
export default class Command {
|
||||
|
@ -82,6 +82,30 @@ export default class Command {
|
|||
}
|
||||
}
|
||||
|
||||
public checkCustomPermissions(member: Member, permission: number): boolean {
|
||||
if (member.id === '278620217221971968' || member.id === '253600545972027394') return true;
|
||||
switch (permission) {
|
||||
case 0:
|
||||
return true;
|
||||
case 1:
|
||||
return member.roles.some((r) => ['701481967149121627', '453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
|
||||
case 2:
|
||||
return member.roles.some((r) => ['453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
|
||||
case 3:
|
||||
return member.roles.some((r) => ['455972169449734144', '701454855952138300', '662163685439045632'].includes(r));
|
||||
case 4:
|
||||
return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
|
||||
case 5:
|
||||
return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
|
||||
case 6:
|
||||
return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r));
|
||||
case 7:
|
||||
return member.roles.includes('662163685439045632');
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public error(channel: TextableChannel, text: string): Promise<Message> {
|
||||
return channel.createMessage(`***${this.client.util.emojis.ERROR} ${text}***`);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ export default class NPM extends Command {
|
|||
}
|
||||
const name: string = data.name || 'None';
|
||||
const repository: string = bugs.replace('/issues', '') || '';
|
||||
const creation: string = data.time.created ? new Date(data.time.created).toLocaleString('en') : 'None';
|
||||
const modification: string = data.time.modified ? new Date(data.time.modified).toLocaleString('en') : 'None';
|
||||
const creation: string = data?.time.created ? new Date(data.time.created).toLocaleString('en') : 'None';
|
||||
const modification: string = data?.time.modified ? new Date(data.time.modified).toLocaleString('en') : 'None';
|
||||
|
||||
const embed = new RichEmbed();
|
||||
embed.setColor(0xCC3534);
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
import { Message } from 'eris';
|
||||
import { Member, Message } from 'eris';
|
||||
import { Client, Command, RichEmbed } from '../class';
|
||||
|
||||
export default class Score extends Command {
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'score';
|
||||
this.description = 'Gets your Community Score.';
|
||||
this.usage = 'score';
|
||||
this.description = 'Pulls a hard score report for a member.';
|
||||
this.usage = `${this.client.config.prefix} <member> <type: 'hard' | 'soft'> <reporting department: ex. Library of Code sp-us | Cloud Account Services>:<reason>`;
|
||||
this.permissions = 0;
|
||||
this.guildOnly = true;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public async run(message: Message) {
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
const score = await this.client.db.Score.findOne({ userID: message.author.id });
|
||||
let member: Member;
|
||||
if (!args[0] || !this.checkCustomPermissions(message.member, 2)) {
|
||||
member = message.member;
|
||||
} else {
|
||||
member = this.client.util.resolveMember(args[0], this.mainGuild);
|
||||
if (args[1] === 'hard') {
|
||||
if (args.length < 3) return this.client.commands.get('help').run(message, [this.name]);
|
||||
const name = args.slice(2).join(' ').split(':')[0];
|
||||
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.');
|
||||
await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } });
|
||||
}
|
||||
}
|
||||
const score = await this.client.db.Score.findOne({ userID: member.user.id });
|
||||
let totalScore = '0';
|
||||
let activityScore = '0';
|
||||
let moderationScore = '0';
|
||||
|
@ -43,10 +57,17 @@ export default class Score extends Command {
|
|||
if (score.cloudServices === 0) cloudServicesScore = '---';
|
||||
else if (score.cloudServices > 50) cloudServicesScore = '50';
|
||||
else cloudServicesScore = `${score.cloudServices}`;
|
||||
} else return this.error(message.channel, 'Your Community Score has not been calculated yet.');
|
||||
} else return this.error(message.channel, 'Community Score has not been calculated yet.');
|
||||
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Community Score');
|
||||
if (score.inquiries?.length > 0) {
|
||||
let desc = '';
|
||||
score.inquiries.forEach((inq) => {
|
||||
desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n`;
|
||||
});
|
||||
embed.setDescription(desc);
|
||||
}
|
||||
embed.addField('Total | 200 - 800', totalScore, true);
|
||||
embed.addField(`Activity | 10 - ${Math.floor(Math.log1p(1000 + 300 + 200) * 12)}`, activityScore, true);
|
||||
embed.addField('Roles | 1 - 54', roleScore, true);
|
||||
|
|
|
@ -61,7 +61,7 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff) * 5.13) * 1.87);
|
||||
|
||||
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff } });
|
||||
client.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`);
|
||||
// client.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`);
|
||||
}
|
||||
};
|
||||
await start();
|
||||
|
|
|
@ -30,7 +30,7 @@ export interface ScoreInterface extends Document {
|
|||
cloudServices: number,
|
||||
// 0 or 20, 20 points are added if the user is a staff member
|
||||
staff: number,
|
||||
inquiries: [{ name: string, reason: string}],
|
||||
inquiries: [{ name: string, reason: string, date: Date }],
|
||||
}
|
||||
|
||||
const Score: Schema = new Schema({
|
||||
|
|
Loading…
Reference in New Issue