community-relations/src/api/comm.libraryofcode.org/routes/report.ts

542 lines
28 KiB
TypeScript

/* eslint-disable no-bitwise */
/* eslint-disable no-continue */
import jwt from 'jsonwebtoken';
import { v4 as uuid } from 'uuid';
import { TextChannel } from 'eris';
import { LocalStorage, Route, Server, RichEmbed } from '../../../class';
import { ScoreHistoricalRaw } from '../../../models/ScoreHistorical';
export default class Report extends Route {
public timeout: Set<string>;
public acceptedOffers: LocalStorage;
constructor(server: Server) {
super(server);
this.timeout = new Set();
this.acceptedOffers = new LocalStorage('accepted-offers');
this.conf = {
path: '/report',
};
}
public bind() {
this.router.all('*', (_req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
next();
});
this.router.post('/hard', async (req, res) => {
try {
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID || !req.body.reason) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
if (req.body.reason?.length < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR });
const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec();
if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const member = await this.server.client.db.Score.findOne({ userID: req.body.userID, 'pin.2': req.body.pin }).lean().exec();
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const mem = this.server.client.util.resolveMember(member.userID, this.server.client.guilds.get(this.server.client.config.guildID));
if (!mem) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.codes.NOT_FOUND });
if (member.locked) return res.status(403).json({ code: this.constants.codes.PERMISSION_DENIED, message: this.constants.messages.PERMISSION_DENIED });
if (merchant?.type !== 1) return res.status(403).json({ code: this.constants.codes.PERMISSION_DENIED, message: this.constants.messages.PERMISSION_DENIED });
const flags = [];
if (mem.user.publicFlags) {
if ((mem.user.publicFlags & (1 << 0)) === 1 << 0) flags.push('DISCORD_EMPLOYEE');
if ((mem.user.publicFlags & (1 << 1)) === 1 << 1) flags.push('PARTNERED_SERVER_OWNER');
if ((mem.user.publicFlags & (1 << 2)) === 1 << 2) flags.push('HYPESQUAD_EVENTS');
if ((mem.user.publicFlags & (1 << 3)) === 1 << 3) flags.push('BUG_HUNTER_1');
if ((mem.user.publicFlags & (1 << 6)) === 1 << 6) flags.push('HOUSE_BRAVERY');
if ((mem.user.publicFlags & (1 << 7)) === 1 << 7) flags.push('HOUSE_BRILLIANCE');
if ((mem.user.publicFlags & (1 << 8)) === 1 << 8) flags.push('HOUSE_BALANCE');
if ((mem.user.publicFlags & (1 << 9)) === 1 << 9) flags.push('EARLY_SUPPORTER');
if ((mem.user.publicFlags & (1 << 10)) === 1 << 10) flags.push('TEAM_USER');
if ((mem.user.publicFlags & (1 << 12)) === 1 << 12) flags.push('SYSTEM');
if ((mem.user.publicFlags & (1 << 14)) === 1 << 14) flags.push('BUG_HUNTER_2');
if ((mem.user.publicFlags & (1 << 16)) === 1 << 16) flags.push('VERIFIED_BOT');
if ((mem.user.publicFlags & (1 << 17)) === 1 << 17) flags.push('EARLY_VERIFIED_BOT_DEVELOPER');
}
const set = [];
const accounts = await this.server.client.db.Score.find().lean().exec();
for (const sc of accounts) {
if (sc.total < 200) { continue; }
if (sc.total > 800) { set.push(800); continue; }
set.push(sc.total);
}
let totalScore: number;
let activityScore: number;
const moderationScore = Math.round(member.moderation);
let roleScore: number;
let cloudServicesScore: number;
const otherScore = Math.round(member.other);
let miscScore: number;
if (member.total < 200) totalScore = 0;
else if (member.total > 800) totalScore = 800;
else totalScore = Math.round(member.total);
if (member.activity < 10) activityScore = 0;
else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12));
else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0;
else if (member.roles > 54) roleScore = 54;
else roleScore = Math.round(member.roles);
if (member.staff <= 0) miscScore = 0;
else miscScore = Math.round(member.staff);
if (member.cloudServices === 0) cloudServicesScore = 0;
else if (member.cloudServices > 10) cloudServicesScore = 10;
else cloudServicesScore = Math.round(member.cloudServices);
const inquiries: [{ id?: string, name: string, date: Date }?] = [];
if (member.inquiries?.length > 0) {
for (const inq of member.inquiries) {
const testDate = (new Date(new Date(inq.date).setHours(1460)));
if (testDate > new Date()) inquiries.push({ id: inq.id, name: inq.name, date: inq.date });
}
}
const historicalData = await this.server.client.db.ScoreHistorical.find({ userID: member.userID }).lean().exec();
const array: ScoreHistoricalRaw[] = [];
for (const data of historicalData) {
delete data.report?.softInquiries;
array.push(data);
}
if (member.notify) {
const chan = await this.server.client.getDMChannel(member.userID);
try {
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:** ${merchant.name.toUpperCase()}`);
} catch (err) {
this.server.client.util.signale.error(`Unable to DM user: ${member.userID} | ${err}`);
}
}
await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 0, reason: req.body.reason, date: new Date() } } });
const reportID = uuid();
await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { inquiries: { id: reportID, name: merchant.name, reason: req.body.reason, date: new Date(), report: member } } });
const embed = new RichEmbed();
embed.setTitle('Inquiry Notification');
embed.setDescription(reportID);
embed.setColor('#800080');
embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${member.userID}>`, true);
embed.addField('Type', 'HARD', true);
embed.addField('Department/Service', merchant.name.toUpperCase(), true);
embed.addField('Reason', req.body.reason ?? 'N/A', 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(() => {});
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
memberInformation: {
username: mem.user.username,
discriminator: mem.user.discriminator,
joinedServerAt: new Date(mem.joinedAt),
createdAt: new Date(mem.createdAt),
avatarURL: mem.avatarURL,
flags,
nitroBoost: mem.premiumSince === null,
},
percentile: Math.round(this.server.client.util.percentile(set, member.total)),
totalScore,
activityScore,
roleScore,
moderationScore,
cloudServicesScore,
miscScore,
otherScore,
inquiries,
historical: array ?? [],
},
});
} catch (err) {
return this.handleError(err, res);
}
});
this.router.post('/v2/soft', async (req, res) => {
try {
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec();
if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const member = await this.server.client.db.Score.findOne({ userID: req.body.userID }).lean().exec();
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
let totalScore: number;
if (member.total < 200) totalScore = 0;
else if (member.total > 800) totalScore = 800;
else totalScore = Math.round(member.total);
await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 1, reason: 'N/A', date: new Date() } } });
await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { softInquiries: { name: merchant.name, date: new Date() } } });
const embed = new RichEmbed();
embed.setTitle('Inquiry Notification');
embed.setColor('#00FFFF');
const mem = this.server.client.util.resolveMember(member.userID, this.server.client.guilds.get(this.server.client.config.guildID));
if (!mem) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.codes.NOT_FOUND });
embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${member.userID}>`, true);
embed.addField('Type', 'SOFT', true);
embed.addField('Department/Service', merchant.name.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(() => {});
if (!merchant.privileged) {
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
totalScore,
},
});
}
const flags = [];
if (mem.user.publicFlags) {
if ((mem.user.publicFlags & (1 << 0)) === 1 << 0) flags.push('DISCORD_EMPLOYEE');
if ((mem.user.publicFlags & (1 << 1)) === 1 << 1) flags.push('PARTNERED_SERVER_OWNER');
if ((mem.user.publicFlags & (1 << 2)) === 1 << 2) flags.push('HYPESQUAD_EVENTS');
if ((mem.user.publicFlags & (1 << 3)) === 1 << 3) flags.push('BUG_HUNTER_1');
if ((mem.user.publicFlags & (1 << 6)) === 1 << 6) flags.push('HOUSE_BRAVERY');
if ((mem.user.publicFlags & (1 << 7)) === 1 << 7) flags.push('HOUSE_BRILLIANCE');
if ((mem.user.publicFlags & (1 << 8)) === 1 << 8) flags.push('HOUSE_BALANCE');
if ((mem.user.publicFlags & (1 << 9)) === 1 << 9) flags.push('EARLY_SUPPORTER');
if ((mem.user.publicFlags & (1 << 10)) === 1 << 10) flags.push('TEAM_USER');
if ((mem.user.publicFlags & (1 << 12)) === 1 << 12) flags.push('SYSTEM');
if ((mem.user.publicFlags & (1 << 14)) === 1 << 14) flags.push('BUG_HUNTER_2');
if ((mem.user.publicFlags & (1 << 16)) === 1 << 16) flags.push('VERIFIED_BOT');
if ((mem.user.publicFlags & (1 << 17)) === 1 << 17) flags.push('EARLY_VERIFIED_BOT_DEVELOPER');
}
const set = [];
const accounts = await this.server.client.db.Score.find().lean().exec();
for (const sc of accounts) {
if (sc.total < 200) { continue; }
if (sc.total > 800) { set.push(800); continue; }
set.push(sc.total);
}
let activityScore: number;
const moderationScore = Math.round(member.moderation);
let roleScore: number;
let cloudServicesScore: number;
const otherScore = Math.round(member.other);
let miscScore: number;
if (member.activity < 10) activityScore = 0;
else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12));
else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0;
else if (member.roles > 54) roleScore = 54;
else roleScore = Math.round(member.roles);
if (member.staff <= 0) miscScore = 0;
else miscScore = Math.round(member.staff);
if (member.cloudServices === 0) cloudServicesScore = 0;
else if (member.cloudServices > 10) cloudServicesScore = 10;
else cloudServicesScore = Math.round(member.cloudServices);
const historicalData = await this.server.client.db.ScoreHistorical.find({ userID: member.userID }).lean().exec();
const array: ScoreHistoricalRaw[] = [];
for (const data of historicalData) {
delete data.report?.softInquiries;
delete data.report?.inquiries;
array.push(data);
}
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
memberInformation: {
username: mem.user.username,
discriminator: mem.user.discriminator,
joinedServerAt: new Date(mem.joinedAt),
createdAt: new Date(mem.createdAt),
avatarURL: mem.avatarURL,
flags,
nitroBoost: mem.premiumSince === null,
},
totalScore,
percentile: Math.round(this.server.client.util.percentile(set, member.total)),
activityScore,
moderationScore,
roleScore,
cloudServicesScore,
otherScore,
miscScore,
historical: array ?? [],
},
});
} catch (err) {
return this.handleError(err, res);
}
});
this.router.post('/soft', async (req, res) => {
try {
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec();
if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const member = await this.server.client.db.Score.findOne({ userID: req.body.userID, 'pin.2': req.body.pin }).lean().exec();
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const mem = this.server.client.util.resolveMember(member.userID, this.server.client.guilds.get(this.server.client.config.guildID));
if (!mem) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.codes.NOT_FOUND });
let totalScore: number;
if (member.total < 200) totalScore = 0;
else if (member.total > 800) totalScore = 800;
else totalScore = Math.round(member.total);
await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 1, reason: 'N/A', date: new Date() } } });
await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { softInquiries: { name: merchant.name, date: new Date() } } });
const embed = new RichEmbed();
embed.setTitle('Inquiry Notification');
embed.setColor('#00FFFF');
embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${member.userID}>`, true);
embed.addField('Type', 'SOFT', true);
embed.addField('Department/Service', merchant.name.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(() => {});
if (!merchant.privileged) {
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
totalScore,
},
});
}
let activityScore: number;
const moderationScore = Math.round(member.moderation);
let roleScore: number;
let cloudServicesScore: number;
const otherScore = Math.round(member.other);
let miscScore: number;
if (member.activity < 10) activityScore = 0;
else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12));
else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0;
else if (member.roles > 54) roleScore = 54;
else roleScore = Math.round(member.roles);
if (member.staff <= 0) miscScore = 0;
else miscScore = Math.round(member.staff);
if (member.cloudServices === 0) cloudServicesScore = 0;
else if (member.cloudServices > 10) cloudServicesScore = 10;
else cloudServicesScore = Math.round(member.cloudServices);
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
totalScore,
activityScore,
moderationScore,
roleScore,
cloudServicesScore,
otherScore,
miscScore,
},
});
} catch (err) {
return this.handleError(err, res);
}
});
this.router.get('/web', async (req, res) => {
try {
res.setHeader('Access-Control-Allow-Origin', '*');
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);
}
});
this.router.get('/offer', async (req, res) => {
try {
res.setHeader('Access-Control-Allow-Origin', '*');
if (!req.query.code) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (await this.acceptedOffers.get(req.query.code.toString())) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
let offer: {
userID?: string,
staffID?: string,
channelID?: string,
messageID?: string,
pin?: string,
name?: string,
department?: string,
date?: Date,
};
try {
offer = <{
userID?: string,
staffID?: string,
channelID?: string,
messageID?: string,
pin?: string,
name?: string,
department?: string,
date?: Date,
}> jwt.verify(req.query.code.toString(), this.server.client.config.internalKey);
} catch {
return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
}
const chan = <TextChannel> this.server.client.guilds.get(this.constants.discord.SERVER_ID).channels.get(offer.channelID);
await chan.createMessage(`__**PRE-APPROVED OFFER ACCEPTED**__\n<@${offer.staffID}>`);
const message = await chan.getMessage(offer.messageID);
const args = [];
args.push(offer.userID, 'hard');
`${offer.department}:${offer.name}`.split(' ').forEach((item) => args.push(item));
await this.server.client.commands.get('score').run(message, args);
await this.acceptedOffers.set(req.query.code.toString(), true);
return res.sendStatus(200);
} catch (err) {
return this.handleError(err, res);
}
});
}
}