misc fixes

This commit is contained in:
Erik 2022-04-06 21:37:21 +03:00
parent 7315060127
commit 0a24904cf4
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
11 changed files with 54 additions and 32 deletions

View File

@ -37,7 +37,8 @@
"attachments", "attachments",
"permissions", "permissions",
"webhooks", "webhooks",
"wordwatcher" "wordwatcher",
"users"
] ]
}, },
"mariadb": { "mariadb": {

View File

@ -82,8 +82,8 @@ class DiscordClient extends Client {
//Initialize components, localization, and observers. //Initialize components, localization, and observers.
await this.localeLoader.loadLanguages(); await this.localeLoader.loadLanguages();
await this.storageManager.initialize(); await this.storageManager.initialize();
await this.moderationManager.initialize();
await this.registry.loadComponents('components/inhibitors', Inhibitor); await this.registry.loadComponents('components/inhibitors', Inhibitor);
await this.registry.loadComponents('components/observers', Observer); await this.registry.loadComponents('components/observers', Observer);
@ -97,8 +97,9 @@ class DiscordClient extends Client {
this.logger.info(`Built client in ${Date.now()-beforeTime}ms.`); this.logger.info(`Built client in ${Date.now()-beforeTime}ms.`);
const ready = this.ready();
await super.login(); await super.login();
await this.ready(); await ready;
return this; return this;

View File

@ -61,7 +61,7 @@ class ModerationManager {
//TODO: Load infractions for non-cached guilds... //TODO: Load infractions for non-cached guilds...
this.client.storageManager.mongodb.infractions.find({ this.client.storageManager.mongodb.infractions.find({
duration: { $gt: 0 }, duration: { $gt: 0 },
guild: { $in: this.client.guilds.cache.keyArray() }, guild: { $in: this.client.guilds.cache.map((g) => g.id) },
_callbacked: false _callbacked: false
}).then((results) => { }).then((results) => {
this.logger.info(`Filtering ${results.length} infractions for callback.`); this.logger.info(`Filtering ${results.length} infractions for callback.`);
@ -222,6 +222,15 @@ class ModerationManager {
} }
/**
*
*
* @param {class} Infraction
* @param {User | GuildMember} target
* @param {object} info
* @return {Infraction}
* @memberof ModerationManager
*/
async _handleTarget(Infraction, target, info) { async _handleTarget(Infraction, target, info) {
// wrapper: guildWrapper // wrapper: guildWrapper
@ -287,7 +296,7 @@ class ModerationManager {
}; };
const infraction = new Infraction(this.client, { const infraction = new Infraction(this.client, {
target: targetWrapper, target,
type, type,
interaction: info.interaction || null, interaction: info.interaction || null,
arguments: info.arguments, arguments: info.arguments,
@ -308,7 +317,7 @@ class ModerationManager {
if (Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[response.escalation.type]) { if (Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[response.escalation.type]) {
const escalationClass = Constant.Infractions[response.escalation.type]; const escalationClass = Constant.Infractions[response.escalation.type];
const escalationInfraction = new escalationClass(this.client, { const escalationInfraction = new escalationClass(this.client, {
target: targetWrapper, target,
message: info.message || null, message: info.message || null,
arguments: info.arguments, arguments: info.arguments,
type: escalationClass.type, type: escalationClass.type,
@ -363,7 +372,7 @@ class ModerationManager {
if (!undoClass) return false; if (!undoClass) return false;
const guild = this.client.guilds.resolve(i.guild); const guild = this.client.guilds.resolve(i.guild);
await guild.settings(); //just incase //await guild.settings(); //just incase
let target = null; let target = null;
if (i.targetType === 'USER') { if (i.targetType === 'USER') {

View File

@ -89,11 +89,15 @@ class InteractionWrapper {
if (opts.reply) str = `<@!${this.author.id}> ${str}`; if (opts.reply) str = `<@!${this.author.id}> ${str}`;
} }
if (opts.editInteraction) await this.editReply(str); const data = {
else await this.channel.send(str, { content: str,
files: opts.files, embeds: [opts.embed], files: opts.files,
embeds: opts.embed ? [opts.embed] : [],
disableMentions: opts.disableMentions disableMentions: opts.disableMentions
}).then((msg) => { };
if (opts.editInteraction) await this.editReply(data);
else await this.channel.send(data).then((msg) => {
if (opts.delete) msg.delete(); if (opts.delete) msg.delete();
}); });

View File

@ -45,6 +45,7 @@ class MuteInfraction extends Infraction {
try { try {
this.member.roles.add(role, this._reason); this.member.roles.add(role, this._reason);
} catch (e) { } catch (e) {
this.client.logger.debug(`Mute fail, type 1:\n${e.stack}`);
return this._fail('C_MUTE_1FAIL'); return this._fail('C_MUTE_1FAIL');
} }
break; break;
@ -107,7 +108,7 @@ class MuteInfraction extends Infraction {
const role = await this.client.resolver.resolveRole(this.guild._settings.mute.role, true, this.guild); const role = await this.client.resolver.resolveRole(this.guild._settings.mute.role, true, this.guild);
if (!role) { if (!role) {
this.guild._updateSettings({ this.guild.updateSettings({
mute: { mute: {
...this.guild._settings.mute, ...this.guild._settings.mute,
role: null role: null

View File

@ -75,6 +75,8 @@ module.exports = class AutoModeration extends Observer {
if (this.executing[filterResult.filter].includes(member.id)) return; if (this.executing[filterResult.filter].includes(member.id)) return;
this.executing[filterResult.filter].push(member.id); this.executing[filterResult.filter].push(member.id);
// Setting this true initially and negate if it fails, otherwise it won't show up as sanctioned in the msg logs
filterResult.sanctioned = true;
const InfractionClass = CONSTANTS.Infractions[action.type]; const InfractionClass = CONSTANTS.Infractions[action.type];
const result = await this.client.moderationManager.handleAutomod(InfractionClass, member, { const result = await this.client.moderationManager.handleAutomod(InfractionClass, member, {
wrapper, wrapper,
@ -262,7 +264,7 @@ module.exports = class AutoModeration extends Observer {
//const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } }); //const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } });
//if (res) res.delete({ timeout: 10000 }).catch(catcher(240)); //if (res) res.delete({ timeout: 10000 }).catch(catcher(240));
setTimeout(() => { setTimeout(() => {
res.delete().catch(() => { /**/ }); res.delete?.().catch(() => { /**/ });
}, 10000); }, 10000);
} }
this.client.rateLimiter.queueDelete(msg.channel, msg).catch(catcher(269)); this.client.rateLimiter.queueDelete(msg.channel, msg).catch(catcher(269));
@ -515,7 +517,7 @@ module.exports = class AutoModeration extends Observer {
//const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } }); //const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } });
//if (res) res.delete({ timeout: 10000 }); //if (res) res.delete({ timeout: 10000 });
setTimeout(() => { setTimeout(() => {
res.delete().catch(() => { /**/ }); res.delete?.().catch(() => { /**/ });
}, 10000); }, 10000);
} }
@ -581,7 +583,7 @@ module.exports = class AutoModeration extends Observer {
const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter'); const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter');
//if (res) res.delete({ timeout: 10000 }); //if (res) res.delete({ timeout: 10000 });
setTimeout(() => { setTimeout(() => {
res.delete().catch(() => { /**/ }); res.delete?.().catch(() => { /**/ });
}, 10000); }, 10000);
} }
// msg.filtered.sactioned = true; // msg.filtered.sactioned = true;
@ -623,7 +625,7 @@ module.exports = class AutoModeration extends Observer {
if (!silent) { if (!silent) {
const res = await this.client.rateLimiter.limitSend(channel, wrapper.format('M_FILTER_DELETE', { user: author.id }), undefined, 'mentionFilter'); const res = await this.client.rateLimiter.limitSend(channel, wrapper.format('M_FILTER_DELETE', { user: author.id }), undefined, 'mentionFilter');
setTimeout(() => { setTimeout(() => {
res.delete().catch(() => { /**/ }); res.delete?.().catch(() => { /**/ });
}, 10000); }, 10000);
} }

View File

@ -442,7 +442,7 @@ class GuildLogger extends Observer {
{ {
author: Util.escapeMarkdown(author.tag), author: Util.escapeMarkdown(author.tag),
channel: channel.name, channel: channel.name,
pinned: wrapper.format('PIN_TOGGLE', { toggle: newMessage.pinned }, true) pinned: wrapper.format('PIN_TOGGLE', { toggle: newMessage.pinned }, { code: true })
}), }),
description: wrapper.format('MSGLOG_EDIT_JUMP', { guild: guild.id, channel: channel.id, message: oldMessage.id }), description: wrapper.format('MSGLOG_EDIT_JUMP', { guild: guild.id, channel: channel.id, message: oldMessage.id }),
color: CONSTANTS.COLORS.LIGHT_BLUE color: CONSTANTS.COLORS.LIGHT_BLUE

View File

@ -82,9 +82,9 @@ class Automod extends Setting {
if (useprevious) setting.usePrevious = useprevious.value; if (useprevious) setting.usePrevious = useprevious.value;
if (threshold) { // TODO: Flesh this out more if (threshold) { // TODO: Flesh this out more
if (!setting.threshold[threshold.value]) setting.threshold[threshold.value] = {}; if (!setting.thresholds[threshold.value]) setting.thresholds[threshold.value] = {};
if (infraction) setting.threshold[threshold.value].type = infraction.value; if (infraction) setting.thresholds[threshold.value].type = infraction.value;
if (length) setting.threshold[threshold.value].length = length.value; if (length) setting.thresholds[threshold.value].length = length.value;
} }
return { index: 'SETTING_SUCCESS_ALT' }; return { index: 'SETTING_SUCCESS_ALT' };

View File

@ -141,7 +141,7 @@ class FilterSetting extends Setting {
} }
//Should it force the action if automod is enabled //Should it force the action if automod is enabled
if (settings.autoModeration?.enabled) { if (settings.automod?.enabled) {
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_ADD_FORCE' }); const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_ADD_FORCE' });
if (content.error) return content; if (content.error) return content;
@ -195,7 +195,7 @@ class FilterSetting extends Setting {
if (!actions.length) return { error: true, message: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') }; if (!actions.length) return { error: true, message: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') };
const embed = this._createActionEmbed(interaction, actions); const embed = this._createActionEmbed(interaction, actions);
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_REMOVE_START', time: 60, embeds: [embed] }); const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_REMOVE_START', time: 60, embed });
if (content.error) return content; if (content.error) return content;
if (['cancel', 'abort', 'exit'].includes(content)) return { if (['cancel', 'abort', 'exit'].includes(content)) return {
@ -224,10 +224,14 @@ class FilterSetting extends Setting {
const action = actions[index]; const action = actions[index];
//Which property do you want to edit? //Which property do you want to edit?
const prop = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_SELECT' });
if (content.error) return content;
const properties = Object.keys(action); const properties = Object.keys(action);
const prop = await this._prompt(interaction, {
index: 'SETTING_FILTER_ACTION_EDIT_SELECT',
params: { properties: properties.join('`, `') },
embed: null
});
if (prop.error) return prop;
if (!properties.includes(prop)) return { if (!properties.includes(prop)) return {
error: true, error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP') message: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP')
@ -244,7 +248,7 @@ class FilterSetting extends Setting {
async _editExpiration(interaction, actions, action) { async _editExpiration(interaction, actions, action) {
if (!interaction.guild._settings.moderationPoints?.enabled) return { if (!interaction.guild._settings.modpoints?.enabled) return {
error: true, error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
}; };
@ -279,7 +283,7 @@ class FilterSetting extends Setting {
async _editPoints(interaction, actions, action) { async _editPoints(interaction, actions, action) {
if (!interaction.guild._settings.moderationPoints?.enabled) return { if (!interaction.guild._settings.modpoints?.enabled) return {
error: true, error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
}; };

View File

@ -205,7 +205,7 @@ class Infraction {
executor: this.executorId, executor: this.executorId,
executorTag: this.executor.display, executorTag: this.executor.display,
target: this.targetId, target: this.targetId,
targetTag: this.target.display, targetTag: this.target.display || this.target.username || this.target.name,
targetType: this.targetType, targetType: this.targetType,
type: this.type, type: this.type,
case: this.case, case: this.case,

View File

@ -171,12 +171,12 @@ class Setting extends Component {
} }
// Helper function for prompting for user response by editing the interaction response // Helper function for prompting for user response by editing the interaction response
async _prompt(interaction, { message= '', params = {}, embeds = [], index, time = 120 }) { async _prompt(interaction, { message= '', params = {}, embed, index, time = 120 }) {
if (!message.length && !index && !embeds.length) throw new Error('Must declare either message, index or embeds'); if (!message.length && !index && !embed) throw new Error('Must declare either message, index or embeds');
const response = await interaction.promptMessage( const response = await interaction.promptMessage(
index ? interaction.format(index, params) : message, index ? interaction.format(index, params) : message,
{ time, editInteraction: true, embeds } { time, editInteraction: true, embed }
); );
if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') }; if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') };