small fixes n tweaks

This commit is contained in:
Erik 2022-04-28 18:30:01 +03:00
parent a385d33206
commit ab0ac998a3
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
21 changed files with 59 additions and 45 deletions

View File

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

View File

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

View File

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

View File

@ -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**'
}
];

View File

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

View File

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

View File

@ -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**',
}
];

View File

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

View File

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

View File

@ -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**'
}
];
}

View File

@ -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**'
}
];
}

View File

@ -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**'
}
];
}

View File

@ -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**'
}
];
}

View File

@ -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**'
}
];
}

View File

@ -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**'
},
];

View File

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

View File

@ -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**'
}
];
}

View File

@ -54,7 +54,7 @@ class Autorole extends Setting {
},
{
name: 'GENERAL_MESSAGE',
value: setting.message || '`N/A`'
value: setting.message || '**N/A**'
}
];
}

View File

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

View File

@ -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)}`);
// });

View File

@ -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, '\\$&');