2021-02-02 01:45:03 -05:00
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import { Client } from '.';
|
|
|
|
import { InqType } from '../models';
|
2020-10-31 02:27:41 -04:00
|
|
|
|
|
|
|
export default class Report {
|
2020-11-30 19:51:20 -05:00
|
|
|
public client: Client;
|
|
|
|
|
|
|
|
constructor(client: Client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
2021-02-02 01:45:03 -05:00
|
|
|
public async createInquiry(userID: string, name: string, type: InqType, reason?: string) {
|
|
|
|
const report = await this.client.db.Score.findOne({ userID }).lean().exec();
|
|
|
|
const member = this.client.util.resolveMember(userID, this.client.guilds.get(this.client.config.guildID));
|
|
|
|
if (!report || !member) return null;
|
|
|
|
if (type === InqType.HARD && report.locked) return null;
|
|
|
|
const mod = await (new this.client.db.Inquiry({
|
|
|
|
iid: uuid(),
|
|
|
|
userID,
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
reason,
|
|
|
|
date: new Date(),
|
|
|
|
report,
|
|
|
|
}).save());
|
|
|
|
|
|
|
|
this.client.queue.addInquiry(mod.iid, userID, name, type, reason);
|
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public async soft(userID: string) {
|
2020-11-30 19:51:20 -05:00
|
|
|
const report = await this.client.db.Score.findOne({ userID });
|
|
|
|
if (!report) return null;
|
|
|
|
let totalScore: number;
|
|
|
|
let activityScore: number;
|
|
|
|
const moderationScore = Math.round(report.moderation);
|
|
|
|
let roleScore: number;
|
|
|
|
let cloudServicesScore: number;
|
|
|
|
const otherScore = Math.round(report.other);
|
|
|
|
let miscScore: number;
|
|
|
|
|
|
|
|
if (report.total < 200) totalScore = 0;
|
|
|
|
else if (report.total > 800) totalScore = 800;
|
|
|
|
else totalScore = Math.round(report.total);
|
|
|
|
|
|
|
|
if (report.activity < 10) activityScore = 0;
|
|
|
|
else if (report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12));
|
|
|
|
else activityScore = Math.round(report.activity);
|
|
|
|
|
|
|
|
if (report.roles <= 0) roleScore = 0;
|
|
|
|
else if (report.roles > 54) roleScore = 54;
|
|
|
|
else roleScore = Math.round(report.roles);
|
|
|
|
|
|
|
|
if (report.staff <= 0) miscScore = 0;
|
|
|
|
else miscScore = Math.round(report.staff);
|
|
|
|
|
|
|
|
if (report.cloudServices === 0) cloudServicesScore = 0;
|
|
|
|
else if (report.cloudServices > 10) cloudServicesScore = 10;
|
|
|
|
else cloudServicesScore = Math.round(report.cloudServices);
|
|
|
|
|
|
|
|
const historicalData = await this.client.db.ScoreHistorical.find({ userID: member.userID }).lean().exec();
|
|
|
|
const array: ScoreHistoricalRaw[] = [];
|
|
|
|
for (const data of historicalData) {
|
|
|
|
let total: number;
|
|
|
|
let activity: number;
|
|
|
|
const moderation = Math.round(data.report.moderation);
|
|
|
|
let role: number;
|
|
|
|
let cloud: number;
|
|
|
|
const other = Math.round(data.report.other);
|
|
|
|
let misc: number;
|
|
|
|
|
|
|
|
if (data.report.total < 200) total = 0;
|
|
|
|
else if (data.report.total > 800) total = 800;
|
|
|
|
else total = Math.round(data.report.total);
|
|
|
|
|
|
|
|
if (data.report.activity < 10) activity = 0;
|
|
|
|
else if (data.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activity = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12));
|
|
|
|
else activity = Math.round(data.report.activity);
|
|
|
|
|
|
|
|
if (data.report.roles <= 0) role = 0;
|
|
|
|
else if (data.report.roles > 54) role = 54;
|
|
|
|
else role = Math.round(data.report.roles);
|
|
|
|
|
|
|
|
if (data.report.staff <= 0) role = 0;
|
|
|
|
else misc = Math.round(data.report.staff);
|
|
|
|
|
|
|
|
if (data.report.cloudServices === 0) cloud = 0;
|
|
|
|
else if (data.report.cloudServices > 10) cloud = 10;
|
|
|
|
else cloud = Math.round(data.report.cloudServices);
|
|
|
|
|
|
|
|
data.report.total = total; data.report.activity = activity; data.report.moderation = moderation; data.report.roles = role; data.report.cloudServices = cloud; data.report.other = other; data.report.staff = misc;
|
|
|
|
|
|
|
|
array.push(data);
|
|
|
|
}
|
2021-02-02 01:45:03 -05:00
|
|
|
} */
|
2020-10-31 02:27:41 -04:00
|
|
|
}
|