diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index 9446137..ba34d5e 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -1,5 +1,6 @@ const { default: Collection } = require("@discordjs/collection"); const { Guild } = require("discord.js"); +const { FilterUtil } = require("../../../utilities/index.js"); const MemberWrapper = require("./MemberWrapper.js"); class GuildWrapper { @@ -42,7 +43,6 @@ class GuildWrapper { const now = Date.now(); const time = data.created + data.time; const diff = time - now; - console.log(diff); if (diff < 5000) return this._reminder(data); const cb = { timeout: setTimeout(handler.bind(this), diff, data), data }; @@ -69,6 +69,17 @@ class GuildWrapper { await this.removeCallback(id); } + async filterText(member, text) { + const settings = await this.settings(); + const { wordfilter } = settings; + const { enabled, bypass } = wordfilter; + + if (!enabled) return text; + if (member.roles.cache.map((r) => r.id).some((r) => bypass.includes(r))) return text; + + return FilterUtil.filterText(text, wordfilter); + } + async checkInvite(code) { // Is maintained by the utility hook diff --git a/src/structure/client/wrappers/InvokerWrapper.js b/src/structure/client/wrappers/InvokerWrapper.js index 36709b1..6a3ad50 100644 --- a/src/structure/client/wrappers/InvokerWrapper.js +++ b/src/structure/client/wrappers/InvokerWrapper.js @@ -93,10 +93,17 @@ class InvokerWrapper { } async promptMessage(str, opts = {}) { + + if (str instanceof Object) { + opts = str; + str = opts.content; + } + + if(opts.index) str = this.format(opts.index, opts.params, opts.formatOpts); if (typeof str === 'string') { if (opts.emoji) str = `${Emojis[opts.emoji]} ${str}`; - if (opts.reply) str = `<@!${this.author.id}> ${str}`; + //if (opts.reply) str = `<@!${this.author.id}> ${str}`; } const data = { diff --git a/src/structure/client/wrappers/MessageWrapper.js b/src/structure/client/wrappers/MessageWrapper.js index 351d2c6..ac364dd 100644 --- a/src/structure/client/wrappers/MessageWrapper.js +++ b/src/structure/client/wrappers/MessageWrapper.js @@ -66,6 +66,10 @@ class MessageWrapper { this._subcommandGroup = grp; } + react(...opts) { + return this.message.react(...opts); + } + deferReply() { return undefined; } diff --git a/src/structure/components/commands/utility/Remind.js b/src/structure/components/commands/utility/Remind.js index fde4652..00a5398 100644 --- a/src/structure/components/commands/utility/Remind.js +++ b/src/structure/components/commands/utility/Remind.js @@ -1,4 +1,4 @@ -const { Util, FilterUtil } = require("../../../../utilities"); +const { Util } = require("../../../../utilities"); const { SlashCommand } = require("../../../interfaces"); class RemindCommand extends SlashCommand { @@ -35,11 +35,10 @@ class RemindCommand extends SlashCommand { async execute(invoker, { reminder, in: time }) { - const { guild, author, channel, subcommand: { name: subcommand } } = invoker; + const { member, guild, author, channel, subcommand: { name: subcommand } } = invoker; if (subcommand === 'create') { - const text = await this._filter(invoker, reminder.value); - // if(result) return { index: 'COMMAND_REMIND_CONTENT_FILTERED' }; + const text = await guild.filterText(member, reminder.value); await guild.createReminder(time.value, { reminder: text, user: author, channel }); return { index: 'COMMAND_REMIND_CONFIRM', params: { reminder: text, time: Util.humanise(time.value) } }; } else if (subcommand === 'delete') { @@ -89,24 +88,6 @@ class RemindCommand extends SlashCommand { return embed; } - async _filter(invoker, text) { - const { guild, member } = invoker; - const settings = await guild.settings(); - const { wordfilter: { enabled, explicit, fuzzy, regex, whitelist, bypass } } = settings; - - if (!enabled) return text; - if (member.roles.cache.map((r) => r.id).some((r) => bypass.includes(r))) return text; - - let result = FilterUtil.filterExplicit(text.split(' '), explicit); - if (result) return text.replace(result.match, '[FILTERED]'); - result = FilterUtil.filterRegex(text, regex, whitelist); - if (result) return text.replace(result.match, '[FILTERED]'); - result = FilterUtil.filterFuzzy(text.split(' '), fuzzy, whitelist); - if (result) return text.replace(result.match, '[FILTERED]'); - - return false; - } - } module.exports = RemindCommand; \ No newline at end of file diff --git a/src/structure/components/observers/Automoderation.js b/src/structure/components/observers/Automoderation.js index 3edfb86..b881db8 100644 --- a/src/structure/components/observers/Automoderation.js +++ b/src/structure/components/observers/Automoderation.js @@ -1,6 +1,6 @@ /* eslint-disable require-unicode-regexp */ const { inspect } = require('util'); -const similarity = require('similarity'); +// const similarity = require('similarity'); const { stripIndents } = require('common-tags'); const { Observer } = require('../../interfaces'); @@ -31,7 +31,7 @@ const CONSTANTS = { // TODO: // Clean up commented out code once testing of new code is done -// Implement missing automod features +// Implement missing automod features -- done module.exports = class AutoModeration extends Observer { diff --git a/src/utilities/FilterUtil.js b/src/utilities/FilterUtil.js index d8e6c5f..6e9ec4b 100644 --- a/src/utilities/FilterUtil.js +++ b/src/utilities/FilterUtil.js @@ -348,4 +348,23 @@ module.exports = class FilterUtility { } + /** + * Filters input text, replaces filtered words with [FILTERED] + * + * @static + * @param {String} text Text to filter + * @param {Object} settings Wordfilter settings + * @return {String} Filtered text + */ + static filterText(text, settings) { + const { explicit, whitelist, fuzzy, regex } = settings; + let result = FilterUtility.filterExplicit(text.split(' '), explicit); + if (result) return text.replace(result.match, '[FILTERED]'); + result = FilterUtility.filterRegex(text, regex, whitelist); + if (result) return text.replace(result.match, '[FILTERED]'); + result = FilterUtility.filterFuzzy(text.split(' '), fuzzy, whitelist); + if (result) return text.replace(result.match, '[FILTERED]'); + return text; + } + }; \ No newline at end of file