From 9dc6fddc79e458796690581f5f699dcb17da33ba Mon Sep 17 00:00:00 2001 From: nolan Date: Thu, 4 Jun 2020 12:59:09 -0500 Subject: [PATCH] major moderation changes --- .eslintrc.json | 1 - language/languages/en_us/en_us_general.lang | 7 +- package.json | 1 + storage/providers/Mongodb.js | 16 ++- structure/client/DiscordClient.js | 3 +- structure/client/Resolver.js | 16 ++- .../components/commands/developer/Evaluate.js | 5 +- .../components/commands/moderation/Kick.js | 18 ++- .../components/commands/utility/Arguments.js | 66 +++------- .../components/observers/CommandHandler.js | 60 ++++----- .../settings/moderation/DmInfraction.js | 47 ++++++++ .../settings/moderation/ModerationLog.js | 9 +- .../components/settings/moderation/Silent.js | 2 +- structure/extensions/Guild.js | 6 + structure/extensions/User.js | 31 ++++- structure/interfaces/Argument.js | 3 +- structure/moderation/ModerationManager.js | 24 ++-- structure/moderation/infractions/Kick.js | 7 +- structure/moderation/interfaces/Infraction.js | 114 +++++++++++++----- util/Util.js | 8 +- util/defaults/defaultGuild.json | 3 + util/defaults/defaultUser.json | 0 util/defaults/index.js | 3 + yarn.lock | 5 + 24 files changed, 314 insertions(+), 141 deletions(-) create mode 100644 structure/client/components/settings/moderation/DmInfraction.js create mode 100644 util/defaults/defaultGuild.json create mode 100644 util/defaults/defaultUser.json create mode 100644 util/defaults/index.js diff --git a/.eslintrc.json b/.eslintrc.json index 686714a..33eb943 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -79,7 +79,6 @@ "max-classes-per-file": "warn", "max-nested-callbacks": "warn", "new-parens": "warn", - "newline-per-chained-call": "warn", "no-alert": "warn", "no-array-constructor": "warn", "no-bitwise": "warn", diff --git a/language/languages/en_us/en_us_general.lang b/language/languages/en_us/en_us_general.lang index 738d74c..ae27c28 100644 --- a/language/languages/en_us/en_us_general.lang +++ b/language/languages/en_us/en_us_general.lang @@ -168,12 +168,15 @@ Failed to {infraction} **{target}** because {reason}. an error occured. [INFRACTION_DESCRIPTION] -**Action:** {type} +**{type}** **Moderator:** {moderator} **Reason:** {reason} +[INFRACTION_DESCRIPTIONPOINTS] +**Points:** {points} | **Total Points**: {total} + [INFRACTION_DESCRIPTIONJUMPTO] -**Jump To:** [{type}]({link}) +**[Jump To {name}]({link})** [INFRACTION_DESCRIPTIONDURATION] **Duration:** {duration} \ No newline at end of file diff --git a/package.json b/package.json index 28acf54..e1fb1e7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "mysql": "^2.18.1", "node-fetch": "^2.6.0", "similarity": "^1.2.1", + "timestring": "^6.0.0", "winston": "^3.2.1", "winston-transport": "^4.3.0" } diff --git a/storage/providers/Mongodb.js b/storage/providers/Mongodb.js index a58f1b6..e0e016c 100644 --- a/storage/providers/Mongodb.js +++ b/storage/providers/Mongodb.js @@ -316,7 +316,21 @@ class MongoDBProvider extends Provider { }); - } + } + + aggregate({ collection, query }) { + + return new Promise((resolve, reject) => { + + if(!this._initialized) reject(new Error('MongoDB not connected')); + this.db.collection(collection).aggregate(query, (err, item) => { + if(err) return reject(err); + return resolve(item.toArray()); + }); + + }); + + } } diff --git a/structure/client/DiscordClient.js b/structure/client/DiscordClient.js index 697d550..beb6f4b 100644 --- a/structure/client/DiscordClient.js +++ b/structure/client/DiscordClient.js @@ -13,6 +13,7 @@ const ModerationManager = require('../moderation/ModerationManager.js'); const { Guild, GuildMember, User, Message } = require('../../structure/extensions/'); //eslint-disable-line no-unused-vars const { Command, Observer, Inhibitor, Setting } = require('../../structure/interfaces/'); +const { DefaultGuild } = require('../../util/defaults/'); class DiscordClient extends Client { @@ -68,7 +69,7 @@ class DiscordClient extends Client { get defaultConfig() { if(this._defaultConfig) return this._defaultConfig; const settings = this.registry.components.filter((c) => c.type === 'setting' && c.resolve === 'GUILD'); - let def = {}; + let def = DefaultGuild; for(const setting of settings.values()) { if(setting.default !== null) { def = { diff --git a/structure/client/Resolver.js b/structure/client/Resolver.js index ea3ddd0..2249bfd 100644 --- a/structure/client/Resolver.js +++ b/structure/client/Resolver.js @@ -1,4 +1,5 @@ -/* eslint-disable no-useless-escape */ +const timestring = require('timestring'); + class Resolver { constructor(client) { @@ -380,8 +381,7 @@ class Resolver { const channel = CM.cache.filter(filter).filter((c) => { if (!strict) return c.name.toLowerCase().includes(ch); return c.name.toLowerCase() === ch; - }) - .first(); + }).first(); if(channel) resolved.push(channel); @@ -456,6 +456,16 @@ class Resolver { return result ? result[0] : false; } + resolveTime(string) { + let time = null; + try { + time = timestring(string); + } catch(err) { + return null; + } + return time; + } + async infinite(args = [], resolvers = [], strict, guild) { let parsed = [], //eslint-disable-line prefer-const diff --git a/structure/client/components/commands/developer/Evaluate.js b/structure/client/components/commands/developer/Evaluate.js index 313c589..e959e0e 100644 --- a/structure/client/components/commands/developer/Evaluate.js +++ b/structure/client/components/commands/developer/Evaluate.js @@ -1,6 +1,7 @@ const { inspect } = require('util'); const { username } = require('os').userInfo(); + let _storage = null; //eslint-disable-line const { Command } = require('../../../../interfaces/'); @@ -32,7 +33,8 @@ class Evaluate extends Command { description: 'Hides the output from the channel.' } ], - showUsage: true + showUsage: true, + keepQuotes: true }); } @@ -42,6 +44,7 @@ class Evaluate extends Command { params = params.join(' '); // eslint-disable-next-line no-unused-vars const { guild, author, member } = message; + console.log(params); try { let evaled = eval(params); //eslint-disable-line no-eval diff --git a/structure/client/components/commands/moderation/Kick.js b/structure/client/components/commands/moderation/Kick.js index 019a2e6..5042851 100644 --- a/structure/client/components/commands/moderation/Kick.js +++ b/structure/client/components/commands/moderation/Kick.js @@ -20,7 +20,7 @@ class KickCommand extends Command { name: 'points', aliases: ['point', 'modpoints', 'modpoint', 'pts', 'pt'], type: 'INTEGER', - types: ['VERBAL'], + types: ['VERBAL', 'FLAG'], usage: '', default: (guild) => { return guild._settings.moderationPoints.points.KICK; @@ -29,6 +29,16 @@ class KickCommand extends Command { ignoreInvalid: true, required: true }, + { + name: 'expiration', + aliases: ['expire', 'expires', 'expirations'], + type: 'TIME', + types: ['FLAG'], + usage: '