[Board Register System] Bug Fixes & QOL Improvements #38

Closed
ghost wants to merge 5 commits from master into dev
5 changed files with 71 additions and 4924 deletions

4889
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,7 @@
"mathjs": "^7.6.0", "mathjs": "^7.6.0",
"moment": "^2.25.3", "moment": "^2.25.3",
"mongoose": "^5.11.15", "mongoose": "^5.11.15",
"nanoid": "^3.1.22",
"nodemailer": "^6.4.8", "nodemailer": "^6.4.8",
"pluris": "^0.2.5", "pluris": "^0.2.5",
"puppeteer": "^5.5.0", "puppeteer": "^5.5.0",

View File

@ -1,5 +1,5 @@
import { Guild, GuildTextableChannel, Member, TextChannel } from 'eris'; import { Guild, GuildTextableChannel, Member, TextChannel } from 'eris';
import { v4 as genUUID } from 'uuid'; import { nanoid } from 'nanoid';
import { Request } from 'express'; import { Request } from 'express';
import { RichEmbed, Route, Server } from '../../../class'; import { RichEmbed, Route, Server } from '../../../class';
import { StaffInterface } from '../../../models'; import { StaffInterface } from '../../../models';
@ -45,7 +45,7 @@ export default class Root extends Route {
private genEmbed( private genEmbed(
id: string, id: string,
type: 'eo' | 'motion' | 'proc' | 'res' | 'confirmMotion', type: 'eo' | 'motion' | 'proc' | 'res' | 'confirmMotion' | 'resFailed',
director: { director: {
user: StaffInterface, user: StaffInterface,
member: Member member: Member
@ -126,8 +126,13 @@ export default class Root extends Route {
color = 0x4a6cc5; color = 0x4a6cc5;
break; break;
case 'resFailed':
title = 'Resolution Failed';
color = 0xff474a;
break;
default: default:
throw new TypeError('You\'ve specified an invalid type for this action log. Valid types: "eo", "motion", "proc" and "res"'); throw new TypeError('You\'ve specified an invalid type for this action log. Valid types: "eo", "motion", "proc", "res", "confirmMotion", "resFailed"');
} }
const embed = new RichEmbed(); const embed = new RichEmbed();
@ -272,7 +277,7 @@ export default class Root extends Route {
}); });
} }
const id = genUUID(); const id = nanoid();
const embed = this.genEmbed( const embed = this.genEmbed(
id, id,
'eo', 'eo',
@ -318,7 +323,7 @@ export default class Root extends Route {
}); });
} }
const id = genUUID(); const id = nanoid();
const embed = this.genEmbed( const embed = this.genEmbed(
id, id,
'motion', 'motion',
@ -365,7 +370,7 @@ export default class Root extends Route {
}); });
} }
const id = genUUID(); const id = nanoid();
const embed = this.genEmbed( const embed = this.genEmbed(
id, id,
'proc', 'proc',
@ -1010,14 +1015,22 @@ 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.directorLogs.createMessage({ embed: confirmationEmbed });
const motionMessage = await this.directorLogs.getMessage(motion.msg);
await motionMessage.delete();
const issuer = this.guild.members.get(motion.issuer) || await this.guild.getRESTMember(motion.issuer);
const issuerProfile = await this.server.client.db.Staff.findOne({ userID: motion.issuer });
const totalDirectors = yea + nay + present + absent; const totalDirectors = yea + nay + present + absent;
if (yea / totalDirectors >= 0.6) { if (yea / totalDirectors >= 0.6) {
const resolutionID = nanoid();
const resolutionEmbed = this.genEmbed( const resolutionEmbed = this.genEmbed(
motion.oID, resolutionID,
'res', 'res',
{ {
user: authenticated.director, user: issuerProfile,
member: authenticated.member, member: issuer,
}, },
{ {
subject: motion.subject, subject: motion.subject,
@ -1025,7 +1038,6 @@ export default class Root extends Route {
}, },
); );
const resolutionMessage = await this.directorLogs.createMessage({ embed: resolutionEmbed }); const resolutionMessage = await this.directorLogs.createMessage({ embed: resolutionEmbed });
const resolutionID = genUUID();
await this.server.client.db.Resolution.create({ await this.server.client.db.Resolution.create({
issuer: motion.issuer, issuer: motion.issuer,
@ -1041,6 +1053,21 @@ export default class Root extends Route {
}, },
msg: resolutionMessage.id, msg: resolutionMessage.id,
}); });
} else {
const resFailedEmbed = this.genEmbed(
motion.oID,
'resFailed',
{
user: issuerProfile,
member: issuer,
},
{
subject: motion.subject,
body: motion.body,
},
);
await this.directorLogs.createMessage({ embed: resFailedEmbed });
} }
res.status(200).json({ res.status(200).json({

View File

@ -33,7 +33,7 @@ export default class MessageReactionAdd extends Event {
const proc = await this.client.db.Proclamation.findOne({ msg: message.id, processed: false }); const proc = await this.client.db.Proclamation.findOne({ msg: message.id, processed: false });
if (!proc?.votedDirectors.includes(reactor.id)) { if (proc && !proc?.votedDirectors.includes(reactor.id)) {
let type: 'yea' | 'nay' | 'present'; let type: 'yea' | 'nay' | 'present';
if (emoji.id === '578750988907970567') type = 'yea'; if (emoji.id === '578750988907970567') type = 'yea';
@ -81,7 +81,7 @@ export default class MessageReactionAdd extends Event {
const totalDirectors = message.channel.guild.members.filter((member) => member.roles.includes('662163685439045632')); const totalDirectors = message.channel.guild.members.filter((member) => member.roles.includes('662163685439045632'));
if (votes.yea / totalDirectors.length >= 0.6) { if (votes.yea / totalDirectors.length >= 0.6 || (votes.nay + votes.present) / totalDirectors.length >= 0.6) {
await proc.updateOne({ await proc.updateOne({
processed: true, processed: true,
results: { results: {
@ -92,47 +92,50 @@ export default class MessageReactionAdd extends Event {
await message.delete(`Proclamation with ID ${proc.oID} processed.`); await message.delete(`Proclamation with ID ${proc.oID} processed.`);
const approved = votes.yea / totalDirectors.length >= 0.6;
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setAuthor(message.embeds[0].author.name, message.embeds[0].author.icon_url); embed.setAuthor(message.embeds[0].author.name, message.embeds[0].author.icon_url);
embed.setTitle('Proclamation'); embed.setTitle('Proclamation');
embed.setDescription(`${proc.oID}\n\n_This action is available on the Board Register System Directory. You can make changes or edit it [here](https://board.ins/repository)._\n\n__This proclamation was confirmed at ${new Date().toLocaleString()}.__`); embed.setDescription(`${proc.oID}\n\n_This action is available on the Board Register System Directory. You can make changes or edit it [here](https://board.ins/repository)._\n\n__This proclamation was confirmed at ${new Date().toLocaleString()}.__`);
embed.addField('Subject', proc.subject); embed.addField('Subject', proc.subject);
embed.addField('Body', proc.body); embed.addField('Body', proc.body);
embed.setColor(0x29b350); embed.setColor(approved ? 0x29b350 : 0xff474a);
embed.setFooter('Library of Code sp-us | Board Register System', 'https://static.libraryofcode.org/library_of_code.png'); embed.setFooter('Library of Code sp-us | Board Register System', 'https://static.libraryofcode.org/library_of_code.png');
embed.setTimestamp(); embed.setTimestamp();
this.client.util.transporter.sendMail({ if (approved) {
to: 'all-staff@lists.libraryofcode.org', await this.client.util.transporter.sendMail({
from: 'Board Register System <internal@staff.libraryofcode.org>', to: 'all-staff@lists.libraryofcode.org',
subject: `PROCLAMATION ${proc.oID}`, from: 'Board Register System <internal@staff.libraryofcode.org>',
text: ` subject: `PROCLAMATION ${proc.oID}`,
PROCLAMATION ${proc.oID} text: `
PROCLAMATION ${proc.oID}
SPONSOR: SPONSOR:
${message.embeds[0].author.name.split('#').slice(0, 1)}, ${message.embeds[0].author.name.split('#').slice(1).join(' ').split(', ').slice(1).join(', ')} ${message.embeds[0].author.name.split('#').slice(0, 1)}, ${message.embeds[0].author.name.split('#').slice(1).join(' ').split(', ').slice(1).join(', ')}
VOTING RESULTS: VOTING RESULTS:
YEA: ${proc.results.yea} YEA: ${proc.results.yea}
NAY: ${proc.results.nay} NAY: ${proc.results.nay}
PRESENT ${proc.results.present} PRESENT ${proc.results.present}
SUBJECT: SUBJECT:
${proc.subject} ${proc.subject}
BODY: BODY:
${proc.body} ${proc.body}
_____________________________________________________________________ _____________________________________________________________________
LIBRARY OF CODE SP-US | BOARD OF DIRECTORS LIBRARY OF CODE SP-US | BOARD OF DIRECTORS
BOARD REGISTER SYSTEM https://board.ins/ BOARD REGISTER SYSTEM https://board.ins/
`, `,
}); });
}
await message.channel.createMessage({ embed }); await message.channel.createMessage({ embed });
} }
} }
} }
} }

View File

@ -2664,6 +2664,11 @@ nan@^2.14.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ== integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
nanoid@^3.1.22:
version "3.1.22"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.22.tgz#b35f8fb7d151990a8aebd5aa5015c03cf726f844"
integrity sha512-/2ZUaJX2ANuLtTvqTlgqBQNJoQO398KyJgZloL0PZkC0dpysjncRUPsFe3DUPzz/y3h+u7C46np8RMuvF3jsSQ==
napi-build-utils@^1.0.1: napi-build-utils@^1.0.1:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806" resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"