From 1e7386f06fe25c823f21f60f2bf51e24af9c5d25 Mon Sep 17 00:00:00 2001 From: Navy Date: Wed, 9 Jun 2021 22:35:56 +0300 Subject: [PATCH] require attachment logs be in nsfw + regex tweaks --- structure/client/components/observers/GuildLogging.js | 5 +++-- structure/client/components/settings/logging/MessageLog.js | 6 ++++++ .../client/components/settings/moderation/WordFilter.js | 7 +++++-- structure/language/languages/en_us/en_us_observers.lang | 3 +++ structure/language/languages/en_us/en_us_settings.lang | 3 +++ util/filterPresets.json | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/structure/client/components/observers/GuildLogging.js b/structure/client/components/observers/GuildLogging.js index abba962..797bd09 100644 --- a/structure/client/components/observers/GuildLogging.js +++ b/structure/client/components/observers/GuildLogging.js @@ -100,7 +100,7 @@ class GuildLogger extends Observer { name: `${message.author.tag} (${message.author.id})`, icon_url: message.author.displayAvatarURL({ size: 32 }) //eslint-disable-line camelcase }, - description: Util.escapeMarkdown(message.content)?.replace(/\\n/gu, ' '), + description: Util.escapeMarkdown(message.content)?.replace(/\\n/gu, ' ') || message.format('MSGLOG_NOCONTENT'), color: CONSTANTS.COLORS.RED, footer: { text: `Message deleted in #${message.channel.name} | Message ID: ${message.id}` @@ -121,7 +121,7 @@ class GuildLogger extends Observer { } const uploadedFiles = []; - if(message.attachments.size > 0 && messageLog.attachments) { + if(message.attachments.size > 0 && messageLog.attachments && logChannel.nsfw) { const imageExtensions = ['.png', '.webp', '.jpg', '.jpeg', '.gif']; const data = await this.client.storageManager.mongodb.messages.findOne({ id: message.id @@ -248,6 +248,7 @@ class GuildLogger extends Observer { let { member, content } = message; const { author, id } = message; + content = Util.escapeMarkdown(content); if (author.bot) continue; if (!member || member.partial) member = await guild.members.fetch(message.author.id).catch(() => { diff --git a/structure/client/components/settings/logging/MessageLog.js b/structure/client/components/settings/logging/MessageLog.js index 99b2ebb..9619856 100644 --- a/structure/client/components/settings/logging/MessageLog.js +++ b/structure/client/components/settings/logging/MessageLog.js @@ -163,8 +163,14 @@ class MessageLogsSetting extends Setting { const [bool] = args; const result = this.client.resolver.resolveBoolean(bool); + const channel = await guild.resolveChannel(setting.channel); if (result) { + + if (channel && !channel.nsfw) return { + error: true, + msg: message.format('S_MESSAGELOG_NSFW') + }; setting.attachments = true; index = 'S_MESSAGELOG_ATTACHMENTS'; diff --git a/structure/client/components/settings/moderation/WordFilter.js b/structure/client/components/settings/moderation/WordFilter.js index 6160db3..49b6ce4 100644 --- a/structure/client/components/settings/moderation/WordFilter.js +++ b/structure/client/components/settings/moderation/WordFilter.js @@ -81,11 +81,14 @@ module.exports = class WordFilter extends FilterSetting { if (method === 'regex') args = rest.map((arg) => Util.sanitiseRegex(arg, ['?', '\\', '(', ')', '|', '\\[', '\\]', '.', '-', '<'])); const resolved = await resolver.resolveMethod([first, ...args], { existing: setting[method], - allowedMethods: ['add', 'remove', 'set', 'reset'] + allowedMethods: ['add', 'remove', 'set', 'reset', 'list'] }); if (!resolved) return { error: true, - msg: message.format('ERR_INVALID_METHOD', { method: resolved.method || args[0] }) + msg: message.format('ERR_INVALID_METHOD', { method: first || args[0] }) + }; + else if (resolved.method === 'list') return { + msg: `\`${setting[method].join('`, `')}\`` }; else if (args.length < 1 && resolved.method !== 'reset') return { error: true, diff --git a/structure/language/languages/en_us/en_us_observers.lang b/structure/language/languages/en_us/en_us_observers.lang index cae84e4..d7bee7a 100644 --- a/structure/language/languages/en_us/en_us_observers.lang +++ b/structure/language/languages/en_us/en_us_observers.lang @@ -69,6 +69,9 @@ Link filter violation. [MSGLOG_DELETE_TITLE] {emoji_trash} {author}'s message was deleted in #{channel} +[MSGLOG_NOCONTENT] +**__NO TEXT CONTENT__** + [MSGLOG_FILTERED] The message was filtered: diff --git a/structure/language/languages/en_us/en_us_settings.lang b/structure/language/languages/en_us/en_us_settings.lang index bdaa059..537734e 100644 --- a/structure/language/languages/en_us/en_us_settings.lang +++ b/structure/language/languages/en_us/en_us_settings.lang @@ -778,6 +778,9 @@ Successfully reset the message logger bypass list. [S_MESSAGELOG_ATTACHMENTS] Successfully turned attachment logging **{changed}**. +[S_MESSAGELOG_NSFW] +To enable attachment logging the channel needs to be marked nsfw. + [S_MESSAGELOG_RESET] Successfully reset the chatlogs setting. diff --git a/util/filterPresets.json b/util/filterPresets.json index 7d26353..6848c85 100644 --- a/util/filterPresets.json +++ b/util/filterPresets.json @@ -4,7 +4,7 @@ "n(ae|ea|ji|j|y|i|x|!|1|\\||l)(gg?|qq|99?|bb)(?!(ht|el))((e|3)r|let|ur|\\s?nog|y|ah?|or)?s?", "(?