add x509 endpoints

merge-requests/27/merge
Matthew 2021-07-02 19:48:13 -04:00
parent f41a0525d6
commit 0b3a1808ed
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
4 changed files with 53 additions and 14 deletions

View File

@ -14,7 +14,8 @@ export default class Root extends Route {
this.server.client.once('ready', async () => { this.server.client.once('ready', async () => {
this.guild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID); this.guild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
this.directorRole = '662163685439045632'; this.directorRole = '662163685439045632';
this.directorLogs = <TextChannel>this.guild.channels.get('807444198969835550'); this.brsVotingChannel = <TextChannel>this.guild.channels.get('807444198969835550');
this.brsLogChannel = <TextChannel>this.guild.channels.get('858547883853873173');
this.chairman = '278620217221971968'; this.chairman = '278620217221971968';
}); });
} }
@ -23,7 +24,9 @@ export default class Root extends Route {
private directorRole: string; private directorRole: string;
private directorLogs: GuildTextableChannel; private brsVotingChannel: GuildTextableChannel;
private brsLogChannel: GuildTextableChannel;
private chairman: string; private chairman: string;
@ -91,7 +94,7 @@ export default class Root extends Route {
break; break;
case 'proc': case 'proc':
title = 'Proclamation'; title = 'Proposed Proclamation';
color = 0x9b89ff; color = 0x9b89ff;
break; break;
@ -285,7 +288,8 @@ export default class Root extends Route {
body: req.body.body, body: req.body.body,
}, },
); );
const msg = await this.directorLogs.createMessage({ embed }); const msg = await this.brsVotingChannel.createMessage({ embed });
await this.brsLogChannel.createMessage({ embed });
const eo = await this.server.client.db.ExecutiveOrder.create({ const eo = await this.server.client.db.ExecutiveOrder.create({
issuer: authenticated.director.userID, issuer: authenticated.director.userID,
@ -331,7 +335,8 @@ export default class Root extends Route {
body: req.body.body, body: req.body.body,
}, },
); );
const msg = await this.directorLogs.createMessage({ embed }); const msg = await this.brsVotingChannel.createMessage({ embed });
await this.brsLogChannel.createMessage({ embed });
const motion = await this.server.client.db.Motion.create({ const motion = await this.server.client.db.Motion.create({
issuer: authenticated.director.userID, issuer: authenticated.director.userID,
@ -378,7 +383,7 @@ export default class Root extends Route {
body: req.body.body, body: req.body.body,
}, },
); );
const msg = await this.directorLogs.createMessage({ embed }); const msg = await this.brsVotingChannel.createMessage({ embed });
await msg.addReaction('modSuccess:578750988907970567'); await msg.addReaction('modSuccess:578750988907970567');
await msg.addReaction('modError:578750737920688128'); await msg.addReaction('modError:578750737920688128');
await msg.addReaction('🙋'); await msg.addReaction('🙋');
@ -657,7 +662,7 @@ export default class Root extends Route {
}); });
if (eo.subject !== req.body.subject || eo.body !== req.body.body) { if (eo.subject !== req.body.subject || eo.body !== req.body.body) {
const message = await this.directorLogs.getMessage(eo.msg); const message = await this.brsVotingChannel.getMessage(eo.msg);
const embed = this.genEmbed( const embed = this.genEmbed(
eo.oID, eo.oID,
'eo', 'eo',
@ -711,7 +716,7 @@ export default class Root extends Route {
}); });
if (motion.subject !== req.body.subject || motion.body !== req.body.body) { if (motion.subject !== req.body.subject || motion.body !== req.body.body) {
const message = await this.directorLogs.getMessage(motion.msg); const message = await this.brsVotingChannel.getMessage(motion.msg);
const embed = this.genEmbed( const embed = this.genEmbed(
motion.oID, motion.oID,
'motion', 'motion',
@ -765,7 +770,7 @@ export default class Root extends Route {
}); });
if (proc.subject !== req.body.subject || proc.body !== req.body.body) { if (proc.subject !== req.body.subject || proc.body !== req.body.body) {
const message = await this.directorLogs.getMessage(proc.msg); const message = await this.brsVotingChannel.getMessage(proc.msg);
const embed = this.genEmbed( const embed = this.genEmbed(
proc.oID, proc.oID,
'proc', 'proc',
@ -819,7 +824,7 @@ export default class Root extends Route {
}); });
if (resolution.subject !== req.body.subject || resolution.body !== req.body.body) { if (resolution.subject !== req.body.subject || resolution.body !== req.body.body) {
const message = await this.directorLogs.getMessage(resolution.msg); const message = await this.brsVotingChannel.getMessage(resolution.msg);
const embed = this.genEmbed( const embed = this.genEmbed(
resolution.oID, resolution.oID,
'res', 'res',
@ -1008,7 +1013,7 @@ export default class Root extends Route {
}, },
); );
confirmationEmbed.addField('Results', `**Total:** ${total.length}\n**Yea:** ${yea}\n**Nay:** ${nay}\n**Present:** ${present}\n**Absent:** ${absent}`); confirmationEmbed.addField('Results', `**Total:** ${total.length}\n**Yea:** ${yea}\n**Nay:** ${nay}\n**Present:** ${present}\n**Absent:** ${absent}`);
await this.directorLogs.createMessage({ embed: confirmationEmbed }); await this.brsVotingChannel.createMessage({ embed: confirmationEmbed });
const totalDirectors = yea + nay + present + absent; const totalDirectors = yea + nay + present + absent;
if (yea / totalDirectors >= 0.6) { if (yea / totalDirectors >= 0.6) {
@ -1024,7 +1029,7 @@ export default class Root extends Route {
body: motion.body, body: motion.body,
}, },
); );
const resolutionMessage = await this.directorLogs.createMessage({ embed: resolutionEmbed }); const resolutionMessage = await this.brsVotingChannel.createMessage({ embed: resolutionEmbed });
const resolutionID = genUUID(); const resolutionID = genUUID();
await this.server.client.db.Resolution.create({ await this.server.client.db.Resolution.create({

View File

@ -1 +1,2 @@
export { default as keys } from './keys';
export { default as report } from './report'; export { default as report } from './report';

View File

@ -0,0 +1,33 @@
import { Route, Server } from '../../../class';
export default class Keys extends Route {
constructor(server: Server) {
super(server);
this.conf = {
path: '/keys',
};
}
protected pre() {
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();
});
}
public bind() {
this.pre();
this.router.get('/x509/:userID', async (req, res) => {
const memberDoc = await this.server.client.db.Member.findOne({ userID: req.params.userID }).lean().exec();
const member = this.mainGuild.members.get(req.params.userID);
if (!member || !memberDoc || !memberDoc?.x509) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND });
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: memberDoc.x509,
});
});
}
}

View File

@ -19,8 +19,8 @@ export default class Internal extends Route {
public bind() { public bind() {
this.router.get('/directory', async (req, res) => { this.router.get('/directory', async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
try { try {
res.setHeader('Access-Control-Allow-Origin', '*');
if (req.query.id) { if (req.query.id) {
let member = this.server.client.guilds.get(this.server.client.config.guildID).members.get(req.query.id.toString()); let member = this.server.client.guilds.get(this.server.client.config.guildID).members.get(req.query.id.toString());
if (!member) member = await this.server.client.getRESTGuildMember(this.server.client.config.guildID, req.query.id.toString()); if (!member) member = await this.server.client.getRESTGuildMember(this.server.client.config.guildID, req.query.id.toString());