From 08bd4645f60c54667b0f5ceffbf39a0598472bfc Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 29 Oct 2019 18:20:51 +0000 Subject: [PATCH] All moderation inserts use util --- src/class/Util.ts | 6 +++--- src/commands/deleteaccount.ts | 3 +++ src/commands/lock.ts | 8 ++++++++ src/commands/unlock.ts | 7 +++++++ src/functions/checkLock.ts | 3 +++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index a86d9e5..a59d1a8 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -2,7 +2,7 @@ import { promisify } from 'util'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; -import { Message, PrivateChannel, Member } from 'eris'; +import { Message, PrivateChannel, Member, User } from 'eris'; import { outputFile } from 'fs-extra'; import uuid from 'uuid/v4'; import moment from 'moment'; @@ -155,7 +155,7 @@ export default class Util { * `3` - Unlock * `4` - Delete */ - public async createModerationLog(user: string, moderator: Member, type: number, reason?: string, duration?: number): Promise { + public async createModerationLog(user: string, moderator: Member|User, type: number, reason?: string, duration?: number): Promise { const moderatorID = moderator.id; const account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }] }); if (!account) return Promise.reject(new Error(`Account ${user} not found`)); @@ -195,7 +195,7 @@ export default class Util { .setTitle(embedTitle) .setColor(color) .addField('User', `${username} | <@${userID}>`, true) - .addField('Supervisor', `<@${moderatorID}>`, true) + .addField('Supervisor', moderatorID === this.client.user.id ? 'SYSTEM' : `<@${moderatorID}>`, true) .setFooter(this.client.user.username, this.client.user.avatarURL) .setTimestamp(); if (reason) embed.addField('Reason', reason || 'Not specified'); diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index 6a4e102..365205b 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -39,6 +39,8 @@ export default class DeleteAccount extends Command { const reason = args.slice(1).join(' '); const logInput = { username, userID, logID: uuid(), moderatorID: message.author.id, type: 4, date: new Date(), reason: null }; if (reason) logInput.reason = reason; + await this.client.util.createModerationLog(args[0], message.member, 4, reason); + /* const log = await new this.client.db.Moderation(logInput); await log.save(); @@ -56,6 +58,7 @@ export default class DeleteAccount extends Command { // @ts-ignore user.createMessage({ embed }).catch(); }); + */ this.client.util.transport.sendMail({ to: account.emailAddress, diff --git a/src/commands/lock.ts b/src/commands/lock.ts index 384cd52..7310046 100644 --- a/src/commands/lock.ts +++ b/src/commands/lock.ts @@ -29,13 +29,20 @@ export default class Lock extends Command { const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi); // @ts-ignore const momentMilliseconds = moment.duration(Number(lockLength[0]), lockLength[1]).asMilliseconds(); + /* expiry.setMilliseconds(momentMilliseconds); let processed: boolean = false; if (!momentMilliseconds) processed = true; + */ this.client.signale.debug(lockLength); this.client.signale.debug(expiry); this.client.signale.debug(momentMilliseconds); + const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' '); + + await this.client.util.createModerationLog(account.userID, message.member, 2, reason, momentMilliseconds); + + /* const moderation = new this.client.db.Moderation({ username: account.username, userID: account.userID, @@ -67,6 +74,7 @@ export default class Lock extends Command { }); // @ts-ignore this.client.createMessage('580950455581147146', { embed }); + */ this.client.util.transport.sendMail({ to: account.emailAddress, diff --git a/src/commands/unlock.ts b/src/commands/unlock.ts index c42ec21..11be5f8 100644 --- a/src/commands/unlock.ts +++ b/src/commands/unlock.ts @@ -23,6 +23,8 @@ export default class Unlock extends Command { await this.client.util.exec(`unlock ${account.username}`); await account.updateOne({ locked: false }); + await this.client.util.createModerationLog(account.userID, message.member, 3, args.slice(1).join(' ')); + /* const moderation = new this.client.db.Moderation({ username: account.username, userID: account.userID, @@ -33,7 +35,11 @@ export default class Unlock extends Command { date: new Date(), }); await moderation.save(); + */ + edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been unlocked by Supervisor ${message.author.username}#${message.author.discriminator}.***`); + + /* const embed = new RichEmbed(); embed.setTitle('Account Infraction | Unlock'); embed.setColor(15158332); @@ -49,6 +55,7 @@ export default class Unlock extends Command { }); // @ts-ignore this.client.createMessage('580950455581147146', { embed }); + */ } catch (error) { await this.client.util.handleError(error, message, this); } diff --git a/src/functions/checkLock.ts b/src/functions/checkLock.ts index eb4e3f9..93eca3a 100644 --- a/src/functions/checkLock.ts +++ b/src/functions/checkLock.ts @@ -15,6 +15,8 @@ export default function checkLock(client: Client) { await client.util.exec(`unlock ${account.username}`); await moderation.updateOne({ 'expiration.processed': true }); await account.updateOne({ locked: false }); + await client.util.createModerationLog(account.userID, client.user, 3, 'Auto'); + /* const mod = new client.db.Moderation({ username: account.username, userID: account.userID, @@ -39,6 +41,7 @@ export default function checkLock(client: Client) { }); // @ts-ignore client.createMessage('580950455581147146', { embed }); + */ client.signale.complete(`Unlocked account ${account.username} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`); } });