cleanup + misc fixes

This commit is contained in:
Erik 2022-05-07 23:21:01 +03:00
parent 5001852658
commit d9476e43b7
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
6 changed files with 48 additions and 26 deletions

View File

@ -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

View File

@ -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 = {

View File

@ -66,6 +66,10 @@ class MessageWrapper {
this._subcommandGroup = grp;
}
react(...opts) {
return this.message.react(...opts);
}
deferReply() {
return undefined;
}

View File

@ -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;

View File

@ -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 {

View File

@ -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;
}
};