bugfixes & cleanup

This commit is contained in:
Erik 2022-09-10 10:50:20 +03:00
parent df3a11668f
commit 41209796bb
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
6 changed files with 25 additions and 28 deletions

View File

@ -55,7 +55,7 @@ class BaseClient extends EventEmitter {
this.logger.status(`Starting bot shards`); this.logger.status(`Starting bot shards`);
await this.shardingManager.spawn().catch((error) => { await this.shardingManager.spawn().catch((error) => {
this.logger.error(`Fatal error during shard spawning:\n${error.stack || error}`); this.logger.error(`Fatal error during shard spawning:\n${error.stack || inspect(error)}`);
// eslint-disable-next-line no-process-exit // eslint-disable-next-line no-process-exit
process.exit(); // Prevent a boot loop when shards die due to an error in the client process.exit(); // Prevent a boot loop when shards die due to an error in the client
}); });

View File

@ -29,7 +29,7 @@ class Dispatcher {
const observers = this.client.registry.components const observers = this.client.registry.components
.filter((c) => c._type === 'observer' && !c.disabled) .filter((c) => c._type === 'observer' && !c.disabled)
.sort((a, b) => a.priority - b.priority); .sort((a, b) => a.priority - b.priority); // Lowest number first
this.logger.debug(`Starting dispatch on ${observers.size} observers.`); this.logger.debug(`Starting dispatch on ${observers.size} observers.`);
for(const observer of observers.values()) { for(const observer of observers.values()) {

View File

@ -170,18 +170,22 @@ class ModerationManager {
if (!silent) { if (!silent) {
for (const [, data] of Object.entries(successes)) { for (const [, data] of Object.entries(successes)) {
const { dictionary, targetType } = data.infraction; const { dictionary, targetType } = data.infraction;
const reason = data.escalation ? const reason = Util.escapeMarkdown(data.infraction.reason);
invoker.format('INFRACTION_ESCALATIONREASON') : // data.escalation ?
Util.escapeMarkdown(data.infraction.reason); // invoker.format('INFRACTION_ESCALATIONREASON') :
const str = `${Emojis.success} ${invoker.format('INFRACTION_SUCCESS', { // Util.escapeMarkdown(data.infraction.reason);
const str = `${data.escalation ? Emojis.escalated : Emojis.success} ${invoker.format('INFRACTION_SUCCESS', {
infraction: dictionary.past, infraction: dictionary.past,
targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`, targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`,
target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '), target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '),
text: !data.escalation ? text: ` ${reason.length > 120 ?
` ${reason.length > 120 ?
`for: \`${reason.substring(0, 117)}...\`` : `for: \`${reason.substring(0, 117)}...\`` :
`for: \`${reason}\``}` : `for: \`${reason}\``}`
` because \`${reason}\`` // !data.escalation ?
// ` ${reason.length > 120 ?
// `for: \`${reason.substring(0, 117)}...\`` :
// `for: \`${reason}\``}` :
// ` because \`${reason}\``
})}`; })}`;
data.escalation ? string += str : string = `${str}\n${string}`; //eslint-disable-line data.escalation ? string += str : string = `${str}\n${string}`; //eslint-disable-line
} }
@ -199,15 +203,11 @@ class ModerationManager {
} }
} }
if(silent) await invoker.deleteReply(); if (silent) {
// if (success && silent) { //Delete message if silent. await invoker.deleteReply();
// try { await invoker.delete().catch(() => null);
// await interaction.delete(); }
// } catch (e) { } //eslint-disable-line no-empty
// }
//if (string) interaction.reply(string);
// return succeeded;
return string.length ? string : null; return string.length ? string : null;
} }

View File

@ -159,10 +159,6 @@ module.exports = class AutoModeration extends Observer {
} }
log += `\nNormalised: ${content}`; log += `\nNormalised: ${content}`;
const catcher = (ln) => {
return (error) => this.logger.debug(`Issue with promise on line ${ln}:\n${error.stack}`);
};
// match: what was matched | // match: what was matched |
// matched: did it match at all ? | // matched: did it match at all ? |
// matcher: what gets shown in the message logs | // matcher: what gets shown in the message logs |
@ -616,6 +612,7 @@ module.exports = class AutoModeration extends Observer {
const { guild, author, guildWrapper: wrapper } = message; const { guild, author, guildWrapper: wrapper } = message;
let { channel } = message; let { channel } = message;
if (!channel) return; // Idk how or why but the channel is sometimes null? I have absolutely no clue how this could ever be the case
if (channel.partial) channel = await channel.fetch(); if (channel.partial) channel = await channel.fetch();
if (!guild || author.bot || message.filtered) return; if (!guild || author.bot || message.filtered) return;

View File

@ -188,7 +188,7 @@ class CommandHandler extends Observer {
this._generateError(invoker, { error, type: 'command' }); this._generateError(invoker, { error, type: 'command' });
} else { } else {
if (!(invoker.command instanceof SettingsCommand)) invoker.command.error(now); if (!(invoker.command instanceof SettingsCommand)) invoker.command.error(now);
this.logger.error(`Command ${debugstr} errored:\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key]._rawValue}]`).join('\n')}\n${error.stack || error}`); this.logger.error(`Command ${debugstr} errored:\nGuild: ${invoker.guild?.name || 'dms'} (${invoker.guild?.id || ''})\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key]._rawValue}]`).join('\n')}\n${error.stack || error}`);
this._generateError(invoker, { type: 'commandHandler' }); this._generateError(invoker, { type: 'commandHandler' });
} }
return; return;

View File

@ -168,17 +168,17 @@ class InviteFilterSetting extends FilterSetting {
}, },
{ {
name: 'GENERAL_IGNORED', name: 'GENERAL_IGNORED',
value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**', value: setting.ignore?.map((channel) => `<#${channel}>`).join(', ') || '**N/A**',
inline: true inline: true
}, },
{ {
name: 'GENERAL_BYPASS', name: 'GENERAL_BYPASS',
value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**', value: setting.bypass?.map((role) => `<@&${role}>`).join(', ') || '**N/A**',
inline: true inline: true
}, },
{ {
name: 'SETTING_FILTER_ACTIONS', name: 'SETTING_FILTER_ACTIONS',
value: setting.actions.reduce((acc, val) => { value: setting.actions?.reduce((acc, val) => {
let str = `**${val.type}**`; let str = `**${val.type}**`;
if (val.points) str += ` (${val.points} points)`; if (val.points) str += ` (${val.points} points)`;
if (val.duration) str += ` for ${Util.humanise(val.duration)}`; if (val.duration) str += ` for ${Util.humanise(val.duration)}`;