Final fixes

merge-requests/25/head
Hiroyuki 2021-03-31 22:38:25 -04:00
parent c6cb9be40a
commit f88d47ae01
No known key found for this signature in database
GPG Key ID: C15AC26538975A24
2 changed files with 60 additions and 30 deletions

View File

@ -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();
@ -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 = genUUID();
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

@ -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,17 +92,20 @@ 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) {
await this.client.util.transporter.sendMail({
to: 'all-staff@lists.libraryofcode.org', to: 'all-staff@lists.libraryofcode.org',
from: 'Board Register System <internal@staff.libraryofcode.org>', from: 'Board Register System <internal@staff.libraryofcode.org>',
subject: `PROCLAMATION ${proc.oID}`, subject: `PROCLAMATION ${proc.oID}`,
@ -129,10 +132,10 @@ export default class MessageReactionAdd extends Event {
BOARD REGISTER SYSTEM https://board.ins/ BOARD REGISTER SYSTEM https://board.ins/
`, `,
}); });
}
await message.channel.createMessage({ embed }); await message.channel.createMessage({ embed });
} }
} }
} }
} }