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`);
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
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
.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.`);
for(const observer of observers.values()) {

View File

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

View File

@ -159,10 +159,6 @@ module.exports = class AutoModeration extends Observer {
}
log += `\nNormalised: ${content}`;
const catcher = (ln) => {
return (error) => this.logger.debug(`Issue with promise on line ${ln}:\n${error.stack}`);
};
// match: what was matched |
// matched: did it match at all ? |
// matcher: what gets shown in the message logs |
@ -616,6 +612,7 @@ module.exports = class AutoModeration extends Observer {
const { guild, author, guildWrapper: wrapper } = 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 (!guild || author.bot || message.filtered) return;

View File

@ -188,7 +188,7 @@ class CommandHandler extends Observer {
this._generateError(invoker, { error, type: 'command' });
} else {
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' });
}
return;

View File

@ -168,17 +168,17 @@ class InviteFilterSetting extends FilterSetting {
},
{
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
},
{
name: 'SETTING_FILTER_ACTIONS',
value: setting.actions.reduce((acc, val) => {
value: setting.actions?.reduce((acc, val) => {
let str = `**${val.type}**`;
if (val.points) str += ` (${val.points} points)`;
if (val.duration) str += ` for ${Util.humanise(val.duration)}`;