fixes
parent
373a6b1cfc
commit
cffa0d1d30
|
@ -1,14 +1,18 @@
|
|||
/* eslint-disable no-bitwise */
|
||||
/* eslint-disable no-continue */
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { TextChannel } from 'eris';
|
||||
import { Route, Server, RichEmbed } from '../../../class';
|
||||
import { LocalStorage, Route, Server, RichEmbed } from '../../../class';
|
||||
|
||||
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',
|
||||
};
|
||||
|
@ -467,5 +471,49 @@ export default class Report extends Route {
|
|||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue