From 91304024d601c1a992ba7a232cd3c07478c037d5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 2 Oct 2020 18:00:05 -0400 Subject: [PATCH] logs for score changes --- .../comm.libraryofcode.org/routes/report.ts | 26 +++++++++++++- src/commands/score.ts | 36 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/api/comm.libraryofcode.org/routes/report.ts b/src/api/comm.libraryofcode.org/routes/report.ts index 8582337..1a0c5ef 100644 --- a/src/api/comm.libraryofcode.org/routes/report.ts +++ b/src/api/comm.libraryofcode.org/routes/report.ts @@ -1,4 +1,5 @@ -import { Route, Server } from '../../../class'; +import { TextChannel } from 'eris'; +import { Route, Server, RichEmbed } from '../../../class'; export default class Report extends Route { constructor(server: Server) { @@ -69,6 +70,18 @@ export default class Report extends Route { await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 0, reason: req.body.reason, date: new Date() } } }); await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { inquiries: { name: merchant.name, reason: req.body.reason, date: new Date() } } }); + const embed = new RichEmbed(); + embed.setTitle('Inquiry Notification'); + embed.setColor('#800080'); + const mem = this.server.client.util.resolveMember(member.userID, this.server.client.guilds.get(this.server.client.config.guildID)); + embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${member.userID}>`, true); + embed.addField('Type', 'HARD', true); + embed.addField('Department/Service', merchant.name.toUpperCase(), true); + embed.addField('Reason', req.body.reason ?? 'N/A', true); + embed.setTimestamp(); + embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL); + const chan = this.server.client.guilds.get(this.server.client.config.guildID).channels.get('611584771356622849'); + chan.createMessage({ embed }).catch(() => {}); return res.status(200).json({ code: this.constants.codes.SUCCESS, @@ -108,6 +121,17 @@ export default class Report extends Route { await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 1, reason: 'N/A', date: new Date() } } }); await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { softInquiries: { name: merchant.name, date: new Date() } } }); + const embed = new RichEmbed(); + embed.setTitle('Inquiry Notification'); + embed.setColor('#00FFFF'); + const mem = this.server.client.util.resolveMember(member.userID, this.server.client.guilds.get(this.server.client.config.guildID)); + embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${member.userID}>`, true); + embed.addField('Type', 'SOFT', true); + embed.addField('Department/Service', merchant.name.toUpperCase(), true); + embed.setTimestamp(); + embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL); + const chan = this.server.client.guilds.get(this.server.client.config.guildID).channels.get('611584771356622849'); + chan.createMessage({ embed }).catch(() => {}); return res.status(200).json({ code: this.constants.codes.SUCCESS, diff --git a/src/commands/score.ts b/src/commands/score.ts index e6e3a94..4239436 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -1,5 +1,5 @@ /* eslint-disable default-case */ -import { Message, User } from 'eris'; +import { Message, User, TextChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Score extends Command { @@ -53,6 +53,17 @@ export default class Score extends Command { user = message.author; if (!user) return this.error(message.channel, 'Member not found.'); await this.client.db.Score.updateOne({ userID: user.id }, { $addToSet: { softInquiries: { name: `${user.username} via Discord`, date: new Date() } } }); + const embed = new RichEmbed(); + embed.setTitle('Inquiry Notification'); + embed.setColor('#00FFFF'); + const mem = this.client.util.resolveMember(user.id, this.client.guilds.get(this.client.config.guildID)); + embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${user.id}>`, true); + embed.addField('Type', 'SOFT', true); + embed.addField('Department/Service', `${user.username} via Discord`, true); + embed.setTimestamp(); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + const log = this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849'); + log.createMessage({ embed }).catch(() => {}); check = true; } else { user = this.client.util.resolveMember(args[0], this.mainGuild).user; @@ -70,6 +81,18 @@ export default class Score extends Command { if (!score) return this.error(message.channel, 'Score not calculated yet.'); if (score.locked) return this.error(message.channel, 'The score report you have requested has been locked.'); await this.client.db.Score.updateOne({ userID: user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } }); + const embed = new RichEmbed(); + embed.setTitle('Inquiry Notification'); + embed.setColor('#800080'); + const mem = this.client.util.resolveMember(score.userID, this.client.guilds.get(this.client.config.guildID)); + embed.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${score.userID}>`, true); + embed.addField('Type', 'HARD', true); + embed.addField('Department/Service', name, true); + embed.addField('Reason', reason ?? 'N/A', true); + embed.setTimestamp(); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + const log = this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849'); + log.createMessage({ embed }).catch(() => {}); if (score.notify === true) { await this.client.getDMChannel(user.id).then((chan) => { chan.createMessage(`__**Community Score - Hard Pull Notification**__\n*You have signed up to be notified whenever your hard score has been pulled. See \`?score\` for more information.*\n\n**Department/Service:** ${name.toUpperCase()}`); @@ -169,6 +192,17 @@ export default class Score extends Command { break; } await this.client.db.Score.updateOne({ userID: user.id }, { $addToSet: { softInquiries: { name, date: new Date() } } }); + const embed2 = new RichEmbed(); + embed2.setTitle('Inquiry Notification'); + embed2.setColor('#00FFFF'); + const mem = this.client.util.resolveMember(score.userID, this.client.guilds.get(this.client.config.guildID)); + embed2.addField('Member', `${mem.user.username}#${mem.user.discriminator} | <@${score.userID}>`, true); + embed2.addField('Type', 'SOFT', true); + embed2.addField('Department/Service', name, true); + embed2.setTimestamp(); + embed2.setFooter(this.client.user.username, this.client.user.avatarURL); + const log = this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849'); + log.createMessage({ embed: embed2 }).catch(() => {}); } } if (args[1] === 'hard' && this.checkCustomPermissions(this.client.util.resolveMember(message.author.id, this.mainGuild), 6)) {