fixes
parent
ee2038b26b
commit
373a6b1cfc
|
@ -4,8 +4,11 @@ import { TextChannel } from 'eris';
|
|||
import { Route, Server, RichEmbed } from '../../../class';
|
||||
|
||||
export default class Report extends Route {
|
||||
public timeout: Set<string>;
|
||||
|
||||
constructor(server: Server) {
|
||||
super(server);
|
||||
this.timeout = new Set();
|
||||
this.conf = {
|
||||
path: '/report',
|
||||
};
|
||||
|
@ -345,5 +348,124 @@ export default class Report extends Route {
|
|||
return this.handleError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
this.router.get('/web', async (req, res) => {
|
||||
try {
|
||||
res.setHeader('Access-Control-Allow-Origin', 'report.libraryofcode.org');
|
||||
if (this.timeout.has(req.ip)) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
if (!req.query.pin) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
const args = req.query.pin.toString();
|
||||
this.timeout.add(req.ip);
|
||||
setTimeout(() => this.timeout.delete(req.ip), 1800000);
|
||||
let score = await this.server.client.db.Score.findOne({ pin: [Number(args.split('-')[0]), Number(args.split('-')[1]), Number(args.split('-')[2])] }).lean().exec();
|
||||
if (!score) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
const member = await this.server.client.getRESTGuildMember(this.constants.discord.SERVER_ID, score.userID);
|
||||
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
let updated = false;
|
||||
if (req.query.staff) {
|
||||
// eslint-disable-next-line no-shadow
|
||||
const args = req.query.staff.toString();
|
||||
const staffScore = await this.server.client.db.Score.findOne({ pin: [Number(args.split('-')[0]), Number(args.split('-')[1]), Number(args.split('-')[2])] }).lean().exec();
|
||||
if (!staffScore) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
if (!staffScore.staff) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
this.timeout.delete(req.ip);
|
||||
if (staffScore.userID === score.userID) {
|
||||
updated = true;
|
||||
await this.server.client.db.Score.updateOne({ userID: score.userID }, { $addToSet: { softInquiries: { name: `${member.username} via report.libraryofcode.org @ IP ${req.ip}`, date: new Date() } } });
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Inquiry Notification');
|
||||
embed.setColor('#00FFFF');
|
||||
embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`, true);
|
||||
embed.addField('Type', 'SOFT', true);
|
||||
embed.addField('Department/Service', `${member.username} via report.libraryofcode.org @ IP ${req.ip}`.toUpperCase(), true);
|
||||
embed.setTimestamp();
|
||||
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
|
||||
const chan = <TextChannel> this.server.client.guilds.get(this.server.client.config.guildID).channels.get('611584771356622849');
|
||||
chan.createMessage({ embed }).catch(() => {});
|
||||
} else {
|
||||
await this.server.client.db.Score.updateOne({ userID: score.userID }, { $addToSet: { softInquiries: { name: 'Library of Code sp-us | Staff Team via report.libraryofcode.org', date: new Date() } } });
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Inquiry Notification');
|
||||
embed.setColor('#00FFFF');
|
||||
embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`, true);
|
||||
embed.addField('Type', 'SOFT', true);
|
||||
embed.addField('Department/Service', 'Library of Code sp-us | Staff Team via report.libraryofcode.org'.toUpperCase(), true);
|
||||
embed.setTimestamp();
|
||||
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
|
||||
const chan = <TextChannel> this.server.client.guilds.get(this.server.client.config.guildID).channels.get('611584771356622849');
|
||||
chan.createMessage({ embed }).catch(() => {});
|
||||
}
|
||||
} else if (!updated) {
|
||||
await this.server.client.db.Score.updateOne({ userID: score.userID }, { $addToSet: { softInquiries: { name: `${member.username} via report.libraryofcode.org @ IP ${req.ip}`, date: new Date() } } });
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Inquiry Notification');
|
||||
embed.setColor('#00FFFF');
|
||||
embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${member.user.id}>`, true);
|
||||
embed.addField('Type', 'SOFT', true);
|
||||
embed.addField('Department/Service', `${member.username} via report.libraryofcode.org @ IP ${req.ip}`.toUpperCase(), true);
|
||||
embed.setTimestamp();
|
||||
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
|
||||
const chan = <TextChannel> this.server.client.guilds.get(this.server.client.config.guildID).channels.get('611584771356622849');
|
||||
chan.createMessage({ embed }).catch(() => {});
|
||||
}
|
||||
score = await this.server.client.db.Score.findOne({ pin: [Number(args.split('-')[0]), Number(args.split('-')[1]), Number(args.split('-')[2])] }).lean().exec();
|
||||
|
||||
let totalScore = '0';
|
||||
let activityScore = '0';
|
||||
let moderationScore = '0';
|
||||
let roleScore = '0';
|
||||
let cloudServicesScore = '0';
|
||||
let otherScore = '0';
|
||||
let miscScore = '0';
|
||||
|
||||
if (score.total < 200) totalScore = '---';
|
||||
else if (score.total > 800) totalScore = '800';
|
||||
else totalScore = `${score.total}`;
|
||||
|
||||
if (score.activity < 10) activityScore = '---';
|
||||
else if (score.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)));
|
||||
else activityScore = `${score.activity}`;
|
||||
|
||||
if (score.roles <= 0) roleScore = '---';
|
||||
else if (score.roles > 54) roleScore = '54';
|
||||
else roleScore = `${score.roles}`;
|
||||
|
||||
moderationScore = `${score.moderation}`;
|
||||
|
||||
if (score.other === 0) otherScore = '---';
|
||||
else otherScore = `${score.other}`;
|
||||
|
||||
if (score.staff <= 0) miscScore = '---';
|
||||
else miscScore = `${score.staff}`;
|
||||
|
||||
if (score.cloudServices === 0) cloudServicesScore = '---';
|
||||
else if (score.cloudServices > 10) cloudServicesScore = '10';
|
||||
else cloudServicesScore = `${score.cloudServices}`;
|
||||
|
||||
const moderations = await this.server.client.db.Moderation.find({ userID: score.userID });
|
||||
|
||||
|
||||
return res.status(200).json({
|
||||
name: `${member.username}#${member.discriminator}`,
|
||||
userID: score.userID,
|
||||
pin: score.pin?.join('-'),
|
||||
score: totalScore,
|
||||
activityScore,
|
||||
cloudServicesScore,
|
||||
moderationScore,
|
||||
roleScore,
|
||||
otherScore,
|
||||
miscScore,
|
||||
notify: score.notify,
|
||||
locked: !!score.locked,
|
||||
totalModerations: moderations?.length > 0 ? moderations.length : 0,
|
||||
inquiries: score.inquiries?.length > 0 ? score.inquiries : [],
|
||||
softInquiries: score.softInquiries?.length > 0 ? score.softInquiries : [],
|
||||
lastUpdated: score.lastUpdate,
|
||||
});
|
||||
} catch (err) {
|
||||
return this.handleError(err, res);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ export default class Internal extends Route {
|
|||
|
||||
this.router.get('/score', async (req, res) => {
|
||||
try {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Origin', 'report.libraryofcode.org');
|
||||
if (this.timeout.has(req.ip)) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
if (!req.query.pin) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
|
||||
const args = req.query.pin.toString();
|
||||
|
|
Loading…
Reference in New Issue