From 1e242f2027b8f4bfa20c4af3990fdb5051ed725b Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 21:24:39 -0500 Subject: [PATCH 01/10] remove training message handler --- src/events/Training.ts | 29 ----------------------------- src/events/index.ts | 1 - 2 files changed, 30 deletions(-) delete mode 100644 src/events/Training.ts diff --git a/src/events/Training.ts b/src/events/Training.ts deleted file mode 100644 index f178a3c..0000000 --- a/src/events/Training.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* eslint-disable no-unreachable */ -import { Message } from 'eris'; -import { Client, Event, LocalStorage } from '../class'; - -export default class Training extends Event { - public client: Client; - - public storage: LocalStorage; - - constructor(client: Client) { - super(client); - this.event = 'messageCreate'; - this.storage = new LocalStorage('training'); - } - - public async run(message: Message) { - return; - try { - if (message.channel.id !== '485680288123584525') return; - await this.storage.set(message.id, { - content: message.content, - date: new Date(), - score: -1, - }); - } catch (err) { - this.client.util.handleError(err, message); - } - } -} diff --git a/src/events/index.ts b/src/events/index.ts index 277d16c..9caf386 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -2,4 +2,3 @@ export { default as CallBackHandler } from './CallBackHandler'; export { default as CommandHandler } from './CommandHandler'; export { default as guildMemberAdd } from './guildMemberAdd'; export { default as ready } from './ready'; -export { default as Training } from './Training'; From 51fc884b22330629cd08cee2b658509e390040b9 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 21:25:01 -0500 Subject: [PATCH 02/10] remove training db model --- src/models/NNTrainingData.ts | 13 ------------- src/models/index.ts | 1 - 2 files changed, 14 deletions(-) delete mode 100644 src/models/NNTrainingData.ts diff --git a/src/models/NNTrainingData.ts b/src/models/NNTrainingData.ts deleted file mode 100644 index fbff45b..0000000 --- a/src/models/NNTrainingData.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Document, Schema, model } from 'mongoose'; - -export interface NNTrainingDataInterface extends Document { - name: string, - data: [{ input: any, output: object }]; -} - -const NNTrainingData: Schema = new Schema({ - name: String, - data: Array, -}); - -export default model('NNTrainingData', NNTrainingData); diff --git a/src/models/index.ts b/src/models/index.ts index 59a8b60..e6dd9f3 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -5,7 +5,6 @@ export { default as Inquiry, InquiryInterface, InqType } from './Inquiry'; export { default as Member, MemberInterface } from './Member'; export { default as Merchant, MerchantInterface } from './Merchant'; export { default as Moderation, ModerationInterface } from './Moderation'; -export { default as NNTrainingData, NNTrainingDataInterface } from './NNTrainingData'; export { default as Note, NoteInterface } from './Note'; export { default as PagerNumber, PagerNumberInterface, PagerNumberRaw } from './PagerNumber'; export { default as Promo, PromoInterface } from './Promo'; From 0427867cc920a88260bd511a3fdeba0f443f5b73 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 21:26:01 -0500 Subject: [PATCH 03/10] remove training model from Client bind --- src/class/Client.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/class/Client.ts b/src/class/Client.ts index 876622b..bfc49c2 100644 --- a/src/class/Client.ts +++ b/src/class/Client.ts @@ -12,7 +12,6 @@ import { Member, MemberInterface, Merchant, MerchantInterface, Moderation, ModerationInterface, - NNTrainingData, NNTrainingDataInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Promo, PromoInterface, @@ -44,7 +43,7 @@ export default class Client extends eris.Client { public stripe: Stripe; - public db: { Customer: mongoose.Model, CustomerPortal: mongoose.Model, File: mongoose.Model, Inquiry: mongoose.Model, Member: mongoose.Model, Merchant: mongoose.Model, Moderation: mongoose.Model, NNTrainingData: mongoose.Model, Note: mongoose.Model, PagerNumber: mongoose.Model, Promo: mongoose.Model, Rank: mongoose.Model, Redirect: mongoose.Model, Score: mongoose.Model, ScoreHistorical: mongoose.Model, Staff: mongoose.Model, Stat: mongoose.Model, local: { muted: LocalStorage } }; + public db: { Customer: mongoose.Model, CustomerPortal: mongoose.Model, File: mongoose.Model, Inquiry: mongoose.Model, Member: mongoose.Model, Merchant: mongoose.Model, Moderation: mongoose.Model, Note: mongoose.Model, PagerNumber: mongoose.Model, Promo: mongoose.Model, Rank: mongoose.Model, Redirect: mongoose.Model, Score: mongoose.Model, ScoreHistorical: mongoose.Model, Staff: mongoose.Model, Stat: mongoose.Model, local: { muted: LocalStorage } }; constructor(token: string, options?: eris.ClientOptions) { super(token, options); @@ -52,7 +51,7 @@ export default class Client extends eris.Client { this.events = new Collection(); this.intervals = new Collection(); this.queue = new Queue(this); - this.db = { Customer, CustomerPortal, File, Inquiry, Member, Merchant, Moderation, NNTrainingData, Note, PagerNumber, Promo, Rank, Redirect, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } }; + this.db = { Customer, CustomerPortal, File, Inquiry, Member, Merchant, Moderation, Note, PagerNumber, Promo, Rank, Redirect, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } }; } get report() { From 88c31b491c08089d8f411ae3e1fac4c0de1d5283 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 6 Mar 2021 23:30:41 -0500 Subject: [PATCH 04/10] fixes to setnick cmd --- src/commands/setnick.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/setnick.ts b/src/commands/setnick.ts index 0515127..ed87658 100644 --- a/src/commands/setnick.ts +++ b/src/commands/setnick.ts @@ -5,8 +5,8 @@ export default class Setnick extends Command { constructor(client: Client) { super(client); this.name = 'setnick'; - this.description = 'Changes the nickname of a member'; - this.usage = 'setnick [new nickname]'; + this.description = 'Changes the nickname of a member.'; + this.usage = `${this.client.config.prefix}setnick [new nickname]`; this.permissions = 2; this.guildOnly = true; this.enabled = true; From 232458c0e0911d638d53c8f34b239bb9e3a2f408 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Thu, 11 Mar 2021 01:13:18 -0500 Subject: [PATCH 05/10] fix profile usage terminology --- src/commands/profile.ts | 2 +- src/commands/profile_bio.ts | 2 +- src/commands/profile_github.ts | 2 +- src/commands/profile_gitlab.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/profile.ts b/src/commands/profile.ts index 20978a4..d27e7fa 100644 --- a/src/commands/profile.ts +++ b/src/commands/profile.ts @@ -10,7 +10,7 @@ export default class Profile extends Command { super(client); this.name = 'profile'; this.description = 'Manages your profile on CR.'; - this.usage = 'profile \n*Provide no value in subcommand to clear data.*'; + this.usage = `${this.client.config.prefix}profile \n*Provide no value in subcommand to clear data.*`; this.permissions = 0; this.enabled = true; this.subcmds = [Profile_Bio, Profile_GitHub, Profile_Gitlab]; diff --git a/src/commands/profile_bio.ts b/src/commands/profile_bio.ts index f26cb76..85487c1 100644 --- a/src/commands/profile_bio.ts +++ b/src/commands/profile_bio.ts @@ -6,7 +6,7 @@ export default class Profile_Bio extends Command { super(client); this.name = 'bio'; this.description = 'Updates your bio on your profile.'; - this.usage = `${this.client.config.prefix}bio `; + this.usage = `${this.client.config.prefix}profile bio `; this.permissions = 0; this.enabled = true; } diff --git a/src/commands/profile_github.ts b/src/commands/profile_github.ts index 7989140..56ced5c 100644 --- a/src/commands/profile_github.ts +++ b/src/commands/profile_github.ts @@ -6,7 +6,7 @@ export default class Profile_GitHub extends Command { super(client); this.name = 'github'; this.description = 'Updates your GitHub information on your profile.'; - this.usage = `${this.client.config.prefix}github `; + this.usage = `${this.client.config.prefix}profile github `; this.permissions = 0; this.enabled = true; } diff --git a/src/commands/profile_gitlab.ts b/src/commands/profile_gitlab.ts index 7cb84eb..e3b29cf 100644 --- a/src/commands/profile_gitlab.ts +++ b/src/commands/profile_gitlab.ts @@ -6,7 +6,7 @@ export default class Profile_GitLab extends Command { super(client); this.name = 'gitlab'; this.description = 'Updates your GitLab information on your profile.'; - this.usage = `${this.client.config.prefix}gitlab `; + this.usage = `${this.client.config.prefix}profile gitlab `; this.permissions = 0; this.enabled = true; } From 8e5f78adf45ec801aaf2cf1ec7f8635138dfdaef Mon Sep 17 00:00:00 2001 From: Matthew R Date: Thu, 11 Mar 2021 01:15:11 -0500 Subject: [PATCH 06/10] fix usage termi --- src/commands/addredirect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/addredirect.ts b/src/commands/addredirect.ts index 98a5da5..7714e85 100644 --- a/src/commands/addredirect.ts +++ b/src/commands/addredirect.ts @@ -6,7 +6,7 @@ export default class AddRedirect extends Command { super(client); this.name = 'addredirect'; this.description = 'Adds a redirect link for \'loc.sh\''; - this.usage = 'addredirect '; + this.usage = `${this.client.config.prefix}addredirect `; this.aliases = ['ar']; this.permissions = 6; this.enabled = true; From d3c631f25fdbc94ffbcac6fc5dae0e9adcc6e8aa Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 22 Mar 2021 17:34:21 -0400 Subject: [PATCH 07/10] limit report history docs to 31 --- src/commands/score_hist.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/score_hist.ts b/src/commands/score_hist.ts index f14afe8..a628623 100644 --- a/src/commands/score_hist.ts +++ b/src/commands/score_hist.ts @@ -27,7 +27,7 @@ export default class Score_Hist extends Command { if (!args[0] || !this.checkCustomPermissions(this.client.util.resolveMember(message.author.id, this.mainGuild), 4)) { user = message.author; if (!user) return this.error(message.channel, 'Member not found.'); - const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).lean().exec(); + const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).limit(31).lean().exec(); if (!hists) return this.error(message.channel, 'No history found.'); if (hists.length < 1) return this.error(message.channel, 'No history found.'); const histArray: [{ name: string, value: string }?] = []; @@ -177,7 +177,7 @@ export default class Score_Hist extends Command { user = this.client.util.resolveMember(sc.userID, this.mainGuild)?.user; } if (!user) return this.error(message.channel, 'Member not found.'); - const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).lean().exec(); + const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).limit(31).lean().exec(); if (!hists) return this.error(message.channel, 'No history found.'); if (hists.length < 1) return this.error(message.channel, 'No history found.'); const histArray: [{ name: string, value: string }?] = []; From 48aeb72a9d420b6232237f7abdbfa7df703a4fed Mon Sep 17 00:00:00 2001 From: Matthew R Date: Tue, 23 Mar 2021 20:58:15 -0400 Subject: [PATCH 08/10] more merge conflict fixes --- src/configs/channels.json | 9 --------- src/configs/emotes.json | 17 ----------------- 2 files changed, 26 deletions(-) diff --git a/src/configs/channels.json b/src/configs/channels.json index d2d1d42..f7ac350 100644 --- a/src/configs/channels.json +++ b/src/configs/channels.json @@ -1,15 +1,6 @@ -<<<<<<< HEAD -{ - "moderation": { - "modlogs": "446080867065135115", - "automod": "" - } -} -======= { "moderation": { "modlogs": "446080867065135115", "automod": "" } } ->>>>>>> Hiroyuki/communityrelations-master diff --git a/src/configs/emotes.json b/src/configs/emotes.json index eca8f56..3f0a0ab 100644 --- a/src/configs/emotes.json +++ b/src/configs/emotes.json @@ -1,19 +1,3 @@ -<<<<<<< HEAD -{ - "whois": { - "titleAndDepartment": "<:loc:607695848612167700>", - "email": "<:email:699786452267040878>", - "gitlab": "<:gitlab:699788655748841492>", - "github": "<:github:699786469404835939>", - "bio": "<:bio:699786408193294416>" - }, - "statusMessages": { - "success": "<:modSuccess:578750988907970567>", - "loading": "", - "error": "<:modError:578750737920688128>" - } -} -======= { "whois": { "titleAndDepartment": "<:loc:607695848612167700>", @@ -28,4 +12,3 @@ "error": "<:modError:578750737920688128>" } } ->>>>>>> Hiroyuki/communityrelations-master From d5b009b186a53439d6320c5c24079169c3d2345a Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Wed, 24 Mar 2021 00:15:53 -0400 Subject: [PATCH 09/10] Proclamation and Motion Quorum fixes --- .eslintrc.json | 3 +- src/api/board.ins/routes/root.ts | 7 +++ src/events/messageReactionAdd.ts | 101 ++++++++++++++++++++----------- src/models/Proclamation.ts | 4 +- 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 70d1a95..8c7630b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -41,7 +41,8 @@ "keyword-spacing": "off", "no-multiple-empty-lines": "off", "consistent-return": "off", - "no-continue": "off" + "no-continue": "off", + "no-plusplus": "off" }, "ignorePatterns": "**/*.js" } diff --git a/src/api/board.ins/routes/root.ts b/src/api/board.ins/routes/root.ts index 54098c3..0274264 100644 --- a/src/api/board.ins/routes/root.ts +++ b/src/api/board.ins/routes/root.ts @@ -349,6 +349,13 @@ export default class Root extends Route { oID: id, processed: false, msg: msg.id, + results: { + yea: 0, + nay: 0, + present: 0, + absent: 0, + }, + votedDirectors: [], }); res.status(200).json({ diff --git a/src/events/messageReactionAdd.ts b/src/events/messageReactionAdd.ts index a346e60..ad4daee 100644 --- a/src/events/messageReactionAdd.ts +++ b/src/events/messageReactionAdd.ts @@ -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, _emoji: Emoji, reactor: Member) { + public async run(message: Message, emoji: Emoji, reactor: Member) { if (message.channel.id !== this.directorLogs) return; + if (!(message instanceof Message)) { + message = >(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,76 @@ 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, + }, + }); + 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, + }, + }); + 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, + }, + }); + 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 }); + } } } } + diff --git a/src/models/Proclamation.ts b/src/models/Proclamation.ts index fbc0fdf..ab1f87d 100644 --- a/src/models/Proclamation.ts +++ b/src/models/Proclamation.ts @@ -12,7 +12,6 @@ export interface ProclamationInterface extends Document { present: number; absent: number; }; - acceptedAt: number; msg: string; processed?: boolean; votedDirectors: string[]; @@ -30,10 +29,9 @@ const Proclamation = new Schema({ present: Number, absent: Number, }, - acceptedAt: Number, msg: { type: String, required: true, unique: true }, processed: Boolean, - votedDirectors: Array, + votedDirectors: { type: Array, required: true }, }); export default model('Proclamations', Proclamation); From 1c3291b182ab3c79e2ff644038367f722933e6ae Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Wed, 24 Mar 2021 00:20:02 -0400 Subject: [PATCH 10/10] More fixes --- src/api/board.ins/routes/root.ts | 4 ++-- src/events/messageReactionAdd.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/api/board.ins/routes/root.ts b/src/api/board.ins/routes/root.ts index 0274264..3d8219f 100644 --- a/src/api/board.ins/routes/root.ts +++ b/src/api/board.ins/routes/root.ts @@ -968,8 +968,8 @@ export default class Root extends Route { confirmationEmbed.addField('Results', `**Total:** ${total.length}\n**Yea:** ${yea}\n**Nay:** ${nay}\n**Present:** ${present}\n**Absent:** ${absent}`); await this.directorLogs.createMessage({ embed: confirmationEmbed }); - const excludingYea = nay + present + absent; - if (yea > excludingYea) { + const totalDirectors = yea + nay + present + absent; + if (yea / totalDirectors >= 0.6) { const resolutionEmbed = this.genEmbed( motion.oID, 'res', diff --git a/src/events/messageReactionAdd.ts b/src/events/messageReactionAdd.ts index ad4daee..5beeb44 100644 --- a/src/events/messageReactionAdd.ts +++ b/src/events/messageReactionAdd.ts @@ -49,6 +49,7 @@ export default class MessageReactionAdd extends Event { ...proc.results, yea: votes.yea, }, + votedDirectors: [...proc.votedDirectors, reactor.id], }); break; @@ -59,6 +60,7 @@ export default class MessageReactionAdd extends Event { ...proc.results, nay: votes.nay, }, + votedDirectors: [...proc.votedDirectors, reactor.id], }); break; @@ -69,6 +71,7 @@ export default class MessageReactionAdd extends Event { ...proc.results, present: votes.present, }, + votedDirectors: [...proc.votedDirectors, reactor.id], }); break;