updates to scoring model (major)
parent
aaa5699fc1
commit
74a32a6134
|
@ -143,4 +143,8 @@ export default class Util {
|
||||||
const hex = int.toString(16);
|
const hex = int.toString(16);
|
||||||
return '#000000'.substring(0, 7 - hex.length) + hex;
|
return '#000000'.substring(0, 7 - hex.length) + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public randomNumber(min: number, max: number): number {
|
||||||
|
return Math.round(Math.random() * (max - min) + min);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint-disable default-case */
|
/* eslint-disable default-case */
|
||||||
import { Member, Message } from 'eris';
|
import { Message, User } from 'eris';
|
||||||
import { Client, Command, RichEmbed } from '../class';
|
import { Client, Command, RichEmbed } from '../class';
|
||||||
|
|
||||||
export default class Score extends Command {
|
export default class Score extends Command {
|
||||||
|
@ -9,16 +9,16 @@ export default class Score extends Command {
|
||||||
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>\n${this.client.config.prefix}score notify <on | off>\n${this.client.config.prefix}score <lock | unlock>`;
|
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>\n${this.client.config.prefix}score <lock | unlock>`;
|
||||||
this.permissions = 0;
|
this.permissions = 0;
|
||||||
this.guildOnly = true;
|
this.guildOnly = false;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
let member: Member;
|
let user: User;
|
||||||
if (args[0] === 'notify') {
|
if (args[0] === 'notify') {
|
||||||
member = message.member;
|
user = message.author;
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
if (!user) return this.error(message.channel, 'Member not found.');
|
||||||
const score = await this.client.db.Score.findOne({ userID: message.author.id });
|
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) 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 } });
|
if (!score.notify) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { notify: false } });
|
||||||
|
@ -34,8 +34,8 @@ export default class Score extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args[0] === 'lock' || args[0] === 'unlock') {
|
if (args[0] === 'lock' || args[0] === 'unlock') {
|
||||||
member = message.member;
|
user = message.author;
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
if (!user) return this.error(message.channel, 'Member not found.');
|
||||||
const score = await this.client.db.Score.findOne({ userID: message.author.id });
|
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) 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 } });
|
if (!score.locked) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } });
|
||||||
|
@ -48,29 +48,34 @@ export default class Score extends Command {
|
||||||
return this.success(message.channel, 'Your report is now unlocked.');
|
return this.success(message.channel, 'Your report is now unlocked.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!args[0] || !this.checkCustomPermissions(message.member, 6)) {
|
if (!args[0] || !this.checkCustomPermissions(this.client.util.resolveMember(message.author.id, this.mainGuild), 6)) {
|
||||||
member = message.member;
|
user = message.author;
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
if (!user) return this.error(message.channel, 'Member not found.');
|
||||||
} else {
|
} else {
|
||||||
member = this.client.util.resolveMember(args[0], this.mainGuild);
|
user = this.client.util.resolveMember(args[0], this.mainGuild).user;
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
if (!user) {
|
||||||
|
const sc = await this.client.db.Score.findOne({ pin: [Number(args[0].split('-')[0]), Number(args[0].split('-')[1]), Number(args[0].split('-')[2])] });
|
||||||
|
user = this.client.util.resolveMember(sc.userID, this.mainGuild).user;
|
||||||
|
}
|
||||||
|
if (!user) return this.error(message.channel, 'Member not found.');
|
||||||
|
if (message.channel.type !== 0) return this.error(message.channel, 'Hard Inquiries must be initiated in a guild.');
|
||||||
if (args[1] === 'hard') {
|
if (args[1] === 'hard') {
|
||||||
if (args.length < 3) return this.client.commands.get('help').run(message, [this.name]);
|
if (args.length < 3) return this.client.commands.get('help').run(message, [this.name]);
|
||||||
const name = args.slice(2).join(' ').split(':')[0];
|
const name = args.slice(2).join(' ').split(':')[0];
|
||||||
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: 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.');
|
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: 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(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()}`);
|
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(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!member) return this.error(message.channel, 'Member not found.');
|
if (!user) return this.error(message.channel, 'Member not found.');
|
||||||
const score = await this.client.db.Score.findOne({ userID: member.user.id });
|
const score = await this.client.db.Score.findOne({ userID: user.id });
|
||||||
let totalScore = '0';
|
let totalScore = '0';
|
||||||
let activityScore = '0';
|
let activityScore = '0';
|
||||||
let moderationScore = '0';
|
let moderationScore = '0';
|
||||||
|
@ -107,8 +112,8 @@ export default class Score extends Command {
|
||||||
|
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Community Score');
|
embed.setTitle('Community Score');
|
||||||
embed.setAuthor(member.user.username, member.user.avatarURL);
|
embed.setAuthor(user.username, user.avatarURL);
|
||||||
embed.setThumbnail(member.user.avatarURL);
|
embed.setThumbnail(user.avatarURL);
|
||||||
/* for (const role of member.roles.map((r) => this.mainGuild.roles.get(r)).sort((a, b) => b.position - a.position)) {
|
/* for (const role of member.roles.map((r) => this.mainGuild.roles.get(r)).sort((a, b) => b.position - a.position)) {
|
||||||
if (role?.color !== 0) {
|
if (role?.color !== 0) {
|
||||||
embed.setColor(role.color);
|
embed.setColor(role.color);
|
||||||
|
@ -124,11 +129,13 @@ export default class Score extends Command {
|
||||||
embed.setDescription(desc);
|
embed.setDescription(desc);
|
||||||
}
|
}
|
||||||
let color = '🔴';
|
let color = '🔴';
|
||||||
|
let additionalText = 'POOR';
|
||||||
embed.setColor('FF0000');
|
embed.setColor('FF0000');
|
||||||
if (score.total >= 300) { color = '🟠'; embed.setColor('FFA500'); }
|
if (score.total >= 300) { color = '🟠'; additionalText = 'FAIR'; embed.setColor('FFA500'); }
|
||||||
if (score.total >= 500) { color = '🟡'; embed.setColor('FFFF00'); }
|
if (score.total >= 500) { color = '🟡'; additionalText = 'GOOD'; embed.setColor('FFFF00'); }
|
||||||
if (score.total >= 700) { color = '🟢'; embed.setColor('66FF66'); }
|
if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); }
|
||||||
embed.addField('Total | 200 to 800', `${color} ${totalScore}`, true);
|
if (score.total >= 770) { color = '<a:excp:756975350998892574>'; additionalText = 'EXCEPTIONAL'; embed.setColor('#99FFFF'); }
|
||||||
|
embed.addField('Total | 200 to 800', `${color} ${totalScore} | ${additionalText}`, true);
|
||||||
embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore || 'N/C', true);
|
embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore || 'N/C', true);
|
||||||
embed.addField('Roles | 1 to N/A', roleScore || 'N/C', true);
|
embed.addField('Roles | 1 to N/A', roleScore || 'N/C', true);
|
||||||
embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true);
|
embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true);
|
||||||
|
@ -138,6 +145,9 @@ export default class Score extends Command {
|
||||||
if (score.locked) {
|
if (score.locked) {
|
||||||
embed.addField('Status', 'Score Report Locked');
|
embed.addField('Status', 'Score Report Locked');
|
||||||
}
|
}
|
||||||
|
if (score.pin?.length > 0 && message.channel.type === 1) {
|
||||||
|
embed.addField('PIN', score.pin.join('-'), true);
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -147,9 +157,9 @@ export default class Score extends Command {
|
||||||
if (args[1] === 'hard') {
|
if (args[1] === 'hard') {
|
||||||
await message.channel.createMessage({ embed });
|
await message.channel.createMessage({ embed });
|
||||||
await message.channel.createMessage('***===BEGIN ADDITIONAL INFORMATION===***');
|
await message.channel.createMessage('***===BEGIN ADDITIONAL INFORMATION===***');
|
||||||
await this.client.commands.get('whois').run(message, [member.id]);
|
await this.client.commands.get('whois').run(message, [user.id]);
|
||||||
await this.client.commands.get('notes').run(message, [member.id]);
|
await this.client.commands.get('notes').run(message, [user.id]);
|
||||||
const whoisMessage = await message.channel.createMessage(`=whois ${member.user.id} --full`);
|
const whoisMessage = await message.channel.createMessage(`=whois ${user.id} --full`);
|
||||||
await whoisMessage.delete();
|
await whoisMessage.delete();
|
||||||
const modlogsMessage = await message.channel.createMessage(`=modlogs ${message.author.id}`);
|
const modlogsMessage = await message.channel.createMessage(`=modlogs ${message.author.id}`);
|
||||||
await modlogsMessage.delete();
|
await modlogsMessage.delete();
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default class CommandHandler extends Event {
|
||||||
if (!resolved) return;
|
if (!resolved) return;
|
||||||
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) return;
|
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) return;
|
||||||
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; }
|
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; }
|
||||||
if (!resolved.cmd.checkPermissions(message.member)) return;
|
if (!resolved.cmd.checkPermissions(this.client.util.resolveMember(message.author.id, this.client.guilds.get('446067825673633794')))) return;
|
||||||
if ((message.channel.type === 0) && !message.channel.guild.members.get(message.author.id)) {
|
if ((message.channel.type === 0) && !message.channel.guild.members.get(message.author.id)) {
|
||||||
message.channel.guild.members.add(await message.channel.guild.getRESTMember(message.author.id));
|
message.channel.guild.members.add(await message.channel.guild.getRESTMember(message.author.id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,12 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
||||||
locked: boolean,
|
locked: boolean,
|
||||||
notify: boolean,
|
notify: boolean,
|
||||||
inquiries: [{ name: string, reason: string}?],
|
inquiries: [{ name: string, reason: string}?],
|
||||||
|
lastUpdated: Date,
|
||||||
|
pin: number[],
|
||||||
|
/* generalMessagesRatio: number,
|
||||||
|
supportMessagesRatio: number,
|
||||||
|
totalModerations: number,
|
||||||
|
notes: number, */
|
||||||
} = {
|
} = {
|
||||||
userID: member.user.id,
|
userID: member.user.id,
|
||||||
total: 0,
|
total: 0,
|
||||||
|
@ -53,6 +59,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
||||||
locked: false,
|
locked: false,
|
||||||
notify: false,
|
notify: false,
|
||||||
inquiries: [],
|
inquiries: [],
|
||||||
|
lastUpdated: new Date(),
|
||||||
|
pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)],
|
||||||
};
|
};
|
||||||
score = await (new client.db.Score(data)).save();
|
score = await (new client.db.Score(data)).save();
|
||||||
client.util.signale.debug(`SCORE INIT - ${member.username}`);
|
client.util.signale.debug(`SCORE INIT - ${member.username}`);
|
||||||
|
@ -124,6 +132,9 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
||||||
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff + other) * 5.13) * 1.87);
|
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff + other) * 5.13) * 1.87);
|
||||||
|
|
||||||
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
|
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
|
||||||
|
if (!score.pin) {
|
||||||
|
await client.db.Score.updateOne({ userID: member.id }, { $set: { pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)] } });
|
||||||
|
}
|
||||||
// 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}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,6 +35,14 @@ export interface ScoreInterface extends Document {
|
||||||
locked: boolean,
|
locked: boolean,
|
||||||
inquiries: [{ name: string, reason: string, date: Date }],
|
inquiries: [{ name: string, reason: string, date: Date }],
|
||||||
lastUpdate: Date,
|
lastUpdate: Date,
|
||||||
|
pin: number[],
|
||||||
|
|
||||||
|
// general & media
|
||||||
|
/* generalMessagesRatio: number,
|
||||||
|
// programming-support channels and cloud-support
|
||||||
|
supportMessagesRatio: number,
|
||||||
|
totalModerations: number,
|
||||||
|
notes: number, */
|
||||||
}
|
}
|
||||||
|
|
||||||
const Score: Schema = new Schema({
|
const Score: Schema = new Schema({
|
||||||
|
@ -50,6 +58,11 @@ const Score: Schema = new Schema({
|
||||||
locked: Boolean,
|
locked: Boolean,
|
||||||
inquiries: Array,
|
inquiries: Array,
|
||||||
lastUpdate: Date,
|
lastUpdate: Date,
|
||||||
|
pin: Array,
|
||||||
|
/* generalMessagesRatio: Number,
|
||||||
|
supportMessagesRatio: Number,
|
||||||
|
totalModerations: Number,
|
||||||
|
notes: Number, */
|
||||||
});
|
});
|
||||||
|
|
||||||
export default model<ScoreInterface>('Score', Score);
|
export default model<ScoreInterface>('Score', Score);
|
||||||
|
|
Loading…
Reference in New Issue