diff --git a/src/structure/client/wrappers/InteractionWrapper.js b/src/structure/client/wrappers/InteractionWrapper.js index 90860ca..946329f 100644 --- a/src/structure/client/wrappers/InteractionWrapper.js +++ b/src/structure/client/wrappers/InteractionWrapper.js @@ -1,6 +1,5 @@ const { Guild } = require('discord.js'); const GuildWrapper = require('./GuildWrapper.js'); -const { Emojis } = require('../../../constants'); class InteractionWrapper { @@ -56,6 +55,10 @@ class InteractionWrapper { // return this.reply(options); // } + userWrapper() { + return this.client.getUserWrapper(this.author.id); + } + async reply(options) { if(options.fetchReply === undefined) options.fetchReply = true; return this.interaction.reply(options); diff --git a/src/structure/components/observers/Automoderation.js b/src/structure/components/observers/Automoderation.js index ac10fae..b6f8ce0 100644 --- a/src/structure/components/observers/Automoderation.js +++ b/src/structure/components/observers/Automoderation.js @@ -305,7 +305,7 @@ module.exports = class AutoModeration extends Observer { const member = message.member || await guild.members.fetch(author.id).catch(); const settings = await wrapper.settings(); const { wordwatcher: setting } = settings; - const { words, bypass, ignore, channel: _logChannel, actions } = setting; + const { words, regex, bypass, ignore, channel: _logChannel, actions } = setting; const roles = member?.roles.cache.map((r) => r.id) || []; if (!_logChannel || words.length === 0 || roles.some((r) => bypass.includes(r.id)) || ignore.includes(channel.id)) return; @@ -322,9 +322,19 @@ module.exports = class AutoModeration extends Observer { } let match = null; - for (const reg of words) { - match = content.match(new RegExp(`(?:^|\\s)(${reg})`, 'iu')); - if (match) break; + for (const reg of regex) { + //match = content.match(new RegExp(`(?:^|\\s)(${reg})`, 'iu')); + match = content.match(new RegExp(reg, 'iu')); + if (match) { + [match] = match; + break; + } + } + + if (!match) for (const word of words) { + if (!content.includes(word)) continue; + match = content.substring(content.indexOf(word), word.length); + break; } if (!match) return; @@ -337,7 +347,7 @@ module.exports = class AutoModeration extends Observer { `, // ** User:** <@${ author.id }> color: 15120384, fields: context.reverse().reduce((acc, val) => { - const text = val.content.length ? Util.escapeMarkdown(val.content).replace(match[1], '**__$&__**') : '**NO CONTENT**'; + const text = val.content.length ? Util.escapeMarkdown(val.content).replace(match, '**__$&__**') : '**NO CONTENT**'; acc.push({ name: `${val.author.tag} (${val.author.id}) - ${val.id}`, value: text.length < 1024 ? text : text.substring(0, 1013) + '...' @@ -350,7 +360,7 @@ module.exports = class AutoModeration extends Observer { }, []) }; - // TODO: Add action buttons + // TODO: Add action buttons -- done? const components = []; for (const action of actions) { components.push({ @@ -446,7 +456,7 @@ module.exports = class AutoModeration extends Observer { let success = false; if (action.type !== 'DELETE') { - const member = msg.member || await guild.members.fetch(msg.author.id).catch(() => null); + const member = msg?.member || await guild.members.fetch(msg.author.id).catch(() => null); if (member) success = await this._moderate(action, guild, targetChannel, member, guild.format('WORDWATCHER_ACTION'), filterObj, moderator); else diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 2a496d2..73f1ba5 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -226,7 +226,8 @@ class CommandHandler extends Observer { // But for now I'm followin discord's structure for commands if (!group) { subcommand = command.subcommand(first)?.raw; - params = [second, ...rest]; + params = []; + if (second) params.push(second, ...rest); } else { subcommand = command.subcommand(second)?.raw; params = rest; @@ -238,7 +239,7 @@ class CommandHandler extends Observer { } - return { options: { args, parameters: params }, verbose: true }; + return { options: args, verbose: true }; } diff --git a/src/structure/components/settings/administration/IgnoreChannels.js b/src/structure/components/settings/administration/IgnoreChannels.js index 23f8db1..b46996b 100644 --- a/src/structure/components/settings/administration/IgnoreChannels.js +++ b/src/structure/components/settings/administration/IgnoreChannels.js @@ -74,11 +74,11 @@ class IgnoreSetting extends Setting { return [ { name: 'GENERAL_CHANNELS', - value: setting.channels.map((c) => `<#${c}>`).join(', ') || '`N/A`' + value: setting.channels.map((c) => `<#${c}>`).join(', ') || '**N/A**' }, { name: 'GENERAL_BYPASS', - value: setting.bypass.map((r) => `<@&${r}>`).join(', ') || '`N/A`' + value: setting.bypass.map((r) => `<@&${r}>`).join(', ') || '**N/A**' } ]; diff --git a/src/structure/components/settings/administration/Protection.js b/src/structure/components/settings/administration/Protection.js index ee88e60..9b68302 100644 --- a/src/structure/components/settings/administration/Protection.js +++ b/src/structure/components/settings/administration/Protection.js @@ -97,7 +97,7 @@ class ProtectionSetting extends Setting { inline: true }, { name: 'GENERAL_ROLES', - value: setting.roles.length ? setting.roles.map((r) => `<@&${r}>`).join(' ') : '`N/A`', + value: setting.roles.length ? setting.roles.map((r) => `<@&${r}>`).join(' ') : '**N/A**', inline: true } ]; diff --git a/src/structure/components/settings/logging/Errors.js b/src/structure/components/settings/logging/Errors.js index f5f225d..16bb568 100644 --- a/src/structure/components/settings/logging/Errors.js +++ b/src/structure/components/settings/logging/Errors.js @@ -72,7 +72,7 @@ class MessageLog extends Setting { }, { name: 'GENERAL_CHANNEL', - value: setting.channel ? `<#${setting.channel}>` : '`N/A`', + value: setting.channel ? `<#${setting.channel}>` : '**N/A**', inline: true } ]; diff --git a/src/structure/components/settings/logging/Members.js b/src/structure/components/settings/logging/Members.js index c0518c3..6508080 100644 --- a/src/structure/components/settings/logging/Members.js +++ b/src/structure/components/settings/logging/Members.js @@ -56,14 +56,14 @@ class MemberLog extends Setting { return [ { name: 'GENERAL_CHANNEL', - value: setting.channel ? `<#${setting.channel}>` : '`N/A`', + value: setting.channel ? `<#${setting.channel}>` : '**N/A**', inline: true }, { name: 'SETTING_MEMBERLOG_JOIN', - value: setting.join || '`N/A`', + value: setting.join || '**N/A**', }, { name: 'SETTING_MEMBERLOG_LEAVE', - value: setting.leave || '`N/A`', + value: setting.leave || '**N/A**', } ]; diff --git a/src/structure/components/settings/logging/Messages.js b/src/structure/components/settings/logging/Messages.js index 7ac8c86..1c23668 100644 --- a/src/structure/components/settings/logging/Messages.js +++ b/src/structure/components/settings/logging/Messages.js @@ -136,7 +136,7 @@ class MessageLog extends Setting { }, { name: 'GENERAL_CHANNEL', - value: setting.channel ? `<#${setting.channel}>` : '`N/A`', + value: setting.channel ? `<#${setting.channel}>` : '**N/A**', inline: true }, { @@ -146,12 +146,12 @@ class MessageLog extends Setting { }, { name: 'GENERAL_BYPASS', - value: setting.bypass.map((r) => `<@&${r}>`).join(', ') || '`N/A`', + value: setting.bypass.map((r) => `<@&${r}>`).join(', ') || '**N/A**', inline: true }, { name: 'GENERAL_IGNORED', - value: setting.ignore.map((c) => `<#${c}>`).join(', ') || '`N/A`', + value: setting.ignore.map((c) => `<#${c}>`).join(', ') || '**N/A**', inline: true } ]; diff --git a/src/structure/components/settings/logging/Nicknames.js b/src/structure/components/settings/logging/Nicknames.js index dc2dc4e..5a6b1ea 100644 --- a/src/structure/components/settings/logging/Nicknames.js +++ b/src/structure/components/settings/logging/Nicknames.js @@ -41,7 +41,7 @@ class Nicknames extends Setting { }, { name: 'GENERAL_CHANNEL', - value: setting.channel ? `<#${setting.channel}>` : '`N/A`', + value: setting.channel ? `<#${setting.channel}>` : '**N/A**', inline: true } ]; diff --git a/src/structure/components/settings/moderation/AutoModeration.js b/src/structure/components/settings/moderation/AutoModeration.js index 7933675..10af473 100644 --- a/src/structure/components/settings/moderation/AutoModeration.js +++ b/src/structure/components/settings/moderation/AutoModeration.js @@ -109,7 +109,7 @@ class Automod extends Setting { value: Object.entries(setting.thresholds).reduce((acc, [points, action]) => { acc.push(`**${points}:** \`${action.type}\`${action.length ? ', ' + Util.humanise(action.length) : ''}`); return acc; - }, []).join('\n') || '`N/A`' + }, []).join('\n') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/moderation/Grantable.js b/src/structure/components/settings/moderation/Grantable.js index b352f80..6af72ad 100644 --- a/src/structure/components/settings/moderation/Grantable.js +++ b/src/structure/components/settings/moderation/Grantable.js @@ -73,7 +73,7 @@ class Grantable extends Setting { }, { name: 'GENERAL_ROLES', - value: setting.roles.map((id) => `<@&${id}>`).join(', ') || '`N/A`' + value: setting.roles.map((id) => `<@&${id}>`).join(', ') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/moderation/InviteFilter.js b/src/structure/components/settings/moderation/InviteFilter.js index be67c95..f5f302f 100644 --- a/src/structure/components/settings/moderation/InviteFilter.js +++ b/src/structure/components/settings/moderation/InviteFilter.js @@ -148,17 +148,17 @@ class InviteFilterSetting extends FilterSetting { { name: '\u200b', value: '\u200b', inline: true }, { name: 'SETTING_FILTER_WHITELIST', - value: setting.whitelist.join(', ') || '`N/A`', + value: setting.whitelist.join(', ') || '**N/A**', inline: true }, { name: 'GENERAL_IGNORED', - value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '`N/A`', + value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**', inline: true }, { name: 'GENERAL_BYPASS', - value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '`N/A`', + value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**', inline: true }, { @@ -174,7 +174,7 @@ class InviteFilterSetting extends FilterSetting { : '`' + val.trigger + '`'}`; //result.trigger instanceof Array ? result.trigger.join(', ') : result.trigger acc.push(str); return acc; - }, []).join('\n') || '`N/A`' + }, []).join('\n') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/moderation/LinkFilter.js b/src/structure/components/settings/moderation/LinkFilter.js index 9812c89..f6171c0 100644 --- a/src/structure/components/settings/moderation/LinkFilter.js +++ b/src/structure/components/settings/moderation/LinkFilter.js @@ -160,27 +160,27 @@ class LinkFilterSetting extends FilterSetting { { name: '\u200b', value: '\u200b', inline: true }, { name: 'SETTING_FILTER_WHITELIST', - value: setting.whitelist.join(', ') || '`N/A`', + value: setting.whitelist.join(', ') || '**N/A**', inline: true }, { name: 'SETTING_FILTER_GREYLIST', - value: setting.greylist.join(', ') || '`N/A`', + value: setting.greylist.join(', ') || '**N/A**', inline: true }, { name: 'SETTING_FILTER_BLACKLIST', - value: setting.blacklist.join(', ') || '`N/A`', + value: setting.blacklist.join(', ') || '**N/A**', inline: true }, { name: 'GENERAL_IGNORED', - value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '`N/A`', + value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**', inline: true }, { name: 'GENERAL_BYPASS', - value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '`N/A`', + value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**', inline: true }, { @@ -196,7 +196,7 @@ class LinkFilterSetting extends FilterSetting { : '`' + val.trigger + '`'}`; //result.trigger instanceof Array ? result.trigger.join(', ') : result.trigger acc.push(str); return acc; - }, []).join('\n') || '`N/A`' + }, []).join('\n') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/moderation/MentionFilter.js b/src/structure/components/settings/moderation/MentionFilter.js index 574bb0a..293223a 100644 --- a/src/structure/components/settings/moderation/MentionFilter.js +++ b/src/structure/components/settings/moderation/MentionFilter.js @@ -157,12 +157,12 @@ class MentionFilter extends FilterSetting { }, { name: 'GENERAL_IGNORED', - value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '`N/A`', + value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**', inline: false }, { name: 'GENERAL_BYPASS', - value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '`N/A`', + value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**', inline: false }, { @@ -178,7 +178,7 @@ class MentionFilter extends FilterSetting { : '`' + val.trigger + '`'}`; //result.trigger instanceof Array ? result.trigger.join(', ') : result.trigger acc.push(str); return acc; - }, []).join('\n') || '`N/A`' + }, []).join('\n') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/moderation/ModerationPoints.js b/src/structure/components/settings/moderation/ModerationPoints.js index f360d15..bfb2ee9 100644 --- a/src/structure/components/settings/moderation/ModerationPoints.js +++ b/src/structure/components/settings/moderation/ModerationPoints.js @@ -128,7 +128,7 @@ class ModerationPoints extends Setting { }, { name: 'SETTING_MODPOINTS_ASSOCIATIONS', - value: Object.entries(setting.associations).map(([type, pts]) => `**${type}**: \`${pts}\``).join('\n') || '`N/A`' + value: Object.entries(setting.associations).map(([type, pts]) => `**${type}**: \`${pts}\``).join('\n') || '**N/A**' }, ]; diff --git a/src/structure/components/settings/moderation/Mute.js b/src/structure/components/settings/moderation/Mute.js index 27047f3..3116c55 100644 --- a/src/structure/components/settings/moderation/Mute.js +++ b/src/structure/components/settings/moderation/Mute.js @@ -281,7 +281,7 @@ class MuteSetting extends Setting { return [ { name: 'SETTING_MUTE_ROLE', - value: setting.role ? `<@&${setting.role}>` : '`N/A`', + value: setting.role ? `<@&${setting.role}>` : '**N/A**', inline: true }, { @@ -297,7 +297,7 @@ class MuteSetting extends Setting { }, { name: 'SETTING_MUTE_DEFAULT', - value: setting.default ? Util.humanise(setting.default) : '`N/A`', + value: setting.default ? Util.humanise(setting.default) : '**N/A**', inline: true }, { name: '\u200b', value: '\u200b', inline: true } diff --git a/src/structure/components/settings/utility/StickyRole.js b/src/structure/components/settings/utility/StickyRole.js index 5820f23..b650dad 100644 --- a/src/structure/components/settings/utility/StickyRole.js +++ b/src/structure/components/settings/utility/StickyRole.js @@ -81,7 +81,7 @@ class Autorole extends Setting { }, { name: 'GENERAL_ROLES', - value: setting.roles.map((role) => `<@&${role}>`).join(' ') || '`N/A`' + value: setting.roles.map((role) => `<@&${role}>`).join(' ') || '**N/A**' } ]; } diff --git a/src/structure/components/settings/utility/Welcomer.js b/src/structure/components/settings/utility/Welcomer.js index 689cd48..73590fa 100644 --- a/src/structure/components/settings/utility/Welcomer.js +++ b/src/structure/components/settings/utility/Welcomer.js @@ -54,7 +54,7 @@ class Autorole extends Setting { }, { name: 'GENERAL_MESSAGE', - value: setting.message || '`N/A`' + value: setting.message || '**N/A**' } ]; } diff --git a/src/structure/interfaces/CommandOption.js b/src/structure/interfaces/CommandOption.js index 8d8146d..d7a01f2 100644 --- a/src/structure/interfaces/CommandOption.js +++ b/src/structure/interfaces/CommandOption.js @@ -52,7 +52,7 @@ class CommandOption { this.value = undefined; - this._rawValue = options._rawValue || null; //Raw value input from Discord. + this._rawValue = options._rawValue ?? null; //Raw value input from Discord. -- use ?? where the value is potentially false, otherwise we end up with false -> null } diff --git a/src/structure/interfaces/commands/SettingsCommand.js b/src/structure/interfaces/commands/SettingsCommand.js index 720d063..94cc59a 100644 --- a/src/structure/interfaces/commands/SettingsCommand.js +++ b/src/structure/interfaces/commands/SettingsCommand.js @@ -171,11 +171,11 @@ class SettingsCommand extends SlashCommand { const dataFields = await setting.fields(guild); // eslint-disable-next-line no-return-assign dataFields.forEach((field) => { - if(field.name.length > 1)field.name = guild.format(field.name); + if(field.name.length > 1) field.name = guild.format(field.name); }); embed.fields.push(...dataFields); - await invoker.editReply({ embeds: [embed] }); + await invoker.reply({ embeds: [embed] }); // .catch((error) => { // this.client.logger.error(`${error.stack || error}\nError context: ${JSON.stringify(embed)}`); // }); diff --git a/src/utilities/Util.js b/src/utilities/Util.js index c47ac86..2a8ea00 100644 --- a/src/utilities/Util.js +++ b/src/utilities/Util.js @@ -152,7 +152,7 @@ class Util { * @return {string} The sanitised expression * @memberof Util */ - static sanitiseRegex(input, allowed = ['?', '\\', '(', ')', '|']) { + static sanitiseRegex(input, allowed = ['?', '\\', '(', ')', '|', '.', '\\[', '\\]', '-']) { if (!input) throw new Error('Missing input'); const reg = new RegExp(`[${this.regChars.filter((char) => !allowed.includes(char)).join('')}]`, 'gu'); return input.replace(reg, '\\$&');