|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { Emoji, GuildTextableChannel, Member, Message } from 'eris';
|
|
|
|
|
import { Client, Event } from '../class';
|
|
|
|
|
import { Client, Event, RichEmbed } from '../class';
|
|
|
|
|
|
|
|
|
|
export default class MessageReactionAdd extends Event {
|
|
|
|
|
public client: Client;
|
|
|
|
@ -17,8 +17,11 @@ export default class MessageReactionAdd extends Event {
|
|
|
|
|
private directorRole: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async run(message: Message<GuildTextableChannel>, _emoji: Emoji, reactor: Member) {
|
|
|
|
|
public async run(message: Message<GuildTextableChannel>, emoji: Emoji, reactor: Member) {
|
|
|
|
|
if (message.channel.id !== this.directorLogs) return;
|
|
|
|
|
if (!(message instanceof Message)) {
|
|
|
|
|
message = <Message<GuildTextableChannel>>(await (message as Message).channel.getMessage((message as Message).id));
|
|
|
|
|
}
|
|
|
|
|
if (message.author.id !== this.client.user.id) return;
|
|
|
|
|
|
|
|
|
|
if (!reactor.roles[0]) {
|
|
|
|
@ -28,46 +31,79 @@ export default class MessageReactionAdd extends Event {
|
|
|
|
|
if (!reactor.roles.includes(this.directorRole)) return;
|
|
|
|
|
|
|
|
|
|
const proc = await this.client.db.Proclamation.findOne({ msg: message.id, processed: false });
|
|
|
|
|
if (proc) {
|
|
|
|
|
if (proc.votedDirectors?.includes(message.author.id)) return;
|
|
|
|
|
|
|
|
|
|
let yea = await message.getReaction('modSuccess:578750988907970567');
|
|
|
|
|
yea = yea.filter((val) => !val.bot);
|
|
|
|
|
let nay = await message.getReaction('modError:578750737920688128');
|
|
|
|
|
nay = nay.filter((val) => !val.bot);
|
|
|
|
|
let present = await message.getReaction('🙋');
|
|
|
|
|
present = present.filter((val) => !val.bot);
|
|
|
|
|
if (!proc?.votedDirectors.includes(reactor.id)) {
|
|
|
|
|
let type: 'yea' | 'nay' | 'present';
|
|
|
|
|
|
|
|
|
|
const totalDirectors = message.channel.guild.members.filter((member) => member.roles.includes(this.directorRole)).length;
|
|
|
|
|
if (emoji.id === '578750988907970567') type = 'yea';
|
|
|
|
|
else if (emoji.id === '578750737920688128') type = 'nay';
|
|
|
|
|
else if (emoji.name === '🙋') type = 'present';
|
|
|
|
|
|
|
|
|
|
const processed = totalDirectors === (yea.length + nay.length + present.length) || Date.now() - proc.at > 604800000;
|
|
|
|
|
const absent = totalDirectors - (yea.length + nay.length + present.length);
|
|
|
|
|
const votes = proc.results;
|
|
|
|
|
|
|
|
|
|
await proc.updateOne({
|
|
|
|
|
results: {
|
|
|
|
|
yea: yea.length,
|
|
|
|
|
nay: nay.length,
|
|
|
|
|
present: present.length,
|
|
|
|
|
absent,
|
|
|
|
|
},
|
|
|
|
|
processed,
|
|
|
|
|
votedDirectors: [...(proc.votedDirectors || []), message.author.id],
|
|
|
|
|
});
|
|
|
|
|
const inTheMajority = yea.length > nay.length + present.length;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'yea':
|
|
|
|
|
votes.yea++;
|
|
|
|
|
await proc.updateOne({
|
|
|
|
|
results: {
|
|
|
|
|
...proc.results,
|
|
|
|
|
yea: votes.yea,
|
|
|
|
|
},
|
|
|
|
|
votedDirectors: [...proc.votedDirectors, reactor.id],
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (processed) {
|
|
|
|
|
const author = this.client.users.get(proc.issuer) || await this.client.getRESTUser(proc.issuer);
|
|
|
|
|
case 'nay':
|
|
|
|
|
votes.nay++;
|
|
|
|
|
await proc.updateOne({
|
|
|
|
|
results: {
|
|
|
|
|
...proc.results,
|
|
|
|
|
nay: votes.nay,
|
|
|
|
|
},
|
|
|
|
|
votedDirectors: [...proc.votedDirectors, reactor.id],
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (inTheMajority) {
|
|
|
|
|
await author.createMessage(`__**Proclamation Majority Vote Received**__\nThe Proclamation you created at Library of Code sp-us, titled **${proc.subject}** (\`${proc.oID}\`) received the majority vote.`);
|
|
|
|
|
await message.channel.createMessage(`__**Proclamation Results**__\nProclamation issued by ${author.mention} **received** the majority vote. Proclamation ID: ${proc.oID}\n\n__Results:__\n**Yea:** ${yea.length}\n**Nay:** ${nay.length}\n**Present:** ${present.length}\n**Absent:** ${absent}`);
|
|
|
|
|
} else {
|
|
|
|
|
await author.createMessage(`__**Proclamation Majority Vote Lost**__\nThe Proclamation you created at Library of Code sp-us, titled **${proc.subject}** (\`${proc.oID}\`) lost the majority vote.`);
|
|
|
|
|
await message.channel.createMessage(`__**Proclamation Results**__\nProclamation issued by ${author.mention} **lost** the majority vote. Proclamation ID: ${proc.oID}\n\n__Results:__\n**Yea:** ${yea.length}\n**Nay:** ${nay.length}\n**Present:** ${present.length}\n**Absent:** ${absent}`);
|
|
|
|
|
}
|
|
|
|
|
case 'present':
|
|
|
|
|
votes.present++;
|
|
|
|
|
await proc.updateOne({
|
|
|
|
|
results: {
|
|
|
|
|
...proc.results,
|
|
|
|
|
present: votes.present,
|
|
|
|
|
},
|
|
|
|
|
votedDirectors: [...proc.votedDirectors, reactor.id],
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reactor.user.createMessage(`__**Vote Recorded**__\nYour vote on the proclamation with ID \`${proc.id}\` at Library of Code sp-us was successfully recorded.`);
|
|
|
|
|
const totalDirectors = message.channel.guild.members.filter((member) => member.roles.includes('662163685439045632'));
|
|
|
|
|
|
|
|
|
|
if (votes.yea / totalDirectors.length >= 0.6) {
|
|
|
|
|
await proc.updateOne({
|
|
|
|
|
processed: true,
|
|
|
|
|
results: {
|
|
|
|
|
...votes,
|
|
|
|
|
absent: totalDirectors.length - (votes.present + votes.nay + votes.present),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await message.delete(`Proclamation with ID ${proc.oID} processed.`);
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setAuthor(message.embeds[0].author.name, message.embeds[0].author.icon_url);
|
|
|
|
|
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.addField('Subject', proc.subject);
|
|
|
|
|
embed.addField('Body', proc.body);
|
|
|
|
|
embed.setColor(0x29b350);
|
|
|
|
|
embed.setFooter('Library of Code sp-us | Board Register System', 'https://static.libraryofcode.org/library_of_code.png');
|
|
|
|
|
embed.setTimestamp();
|
|
|
|
|
|
|
|
|
|
await message.channel.createMessage({ embed });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|