misc fixes
log parser and inhibitor time await unawaited calls
This commit is contained in:
parent
861169f083
commit
da85e3253c
@ -494,11 +494,11 @@ class DiscordClient extends Client
|
|||||||
{
|
{
|
||||||
if (this.#guildWrappers.has(id))
|
if (this.#guildWrappers.has(id))
|
||||||
return this.#guildWrappers.get(id)!;
|
return this.#guildWrappers.get(id)!;
|
||||||
let guild = this.guilds.cache.get(id);
|
let guild = this.guilds.cache.get(id) ?? null;
|
||||||
if (!guild)
|
if (!guild)
|
||||||
guild = await this.guilds.fetch({ guild: id, cache: true });
|
guild = await this.guilds.fetch({ guild: id, cache: true }).catch(() => null);
|
||||||
if (!guild)
|
if (!guild)
|
||||||
throw new Error('Guild does not exist');
|
return Promise.reject(new Error('Guild does not exist'));
|
||||||
|
|
||||||
const wrapper = new GuildWrapper(this, guild);
|
const wrapper = new GuildWrapper(this, guild);
|
||||||
this.#guildWrappers.set(id, wrapper);
|
this.#guildWrappers.set(id, wrapper);
|
||||||
|
@ -539,7 +539,7 @@ class ModerationManager implements Initialisable
|
|||||||
|
|
||||||
const guild = await this.#client.getGuildWrapper(i.guild!);
|
const guild = await this.#client.getGuildWrapper(i.guild!);
|
||||||
if (!guild)
|
if (!guild)
|
||||||
throw new Error('Missing guild');
|
throw new Error(`Missing guild for infraction: ${i.id}`);
|
||||||
// await guild.settings(); //just incase
|
// await guild.settings(); //just incase
|
||||||
|
|
||||||
let target = null;
|
let target = null;
|
||||||
|
@ -17,7 +17,9 @@ class ClientPermissions extends Inhibitor
|
|||||||
|
|
||||||
async execute (invoker: InvokerWrapper, command: Command)
|
async execute (invoker: InvokerWrapper, command: Command)
|
||||||
{
|
{
|
||||||
const channel = invoker.channel as GuildTextBasedChannel;
|
const channel = invoker.channel as GuildTextBasedChannel | null;
|
||||||
|
if (!channel)
|
||||||
|
return super._fail();
|
||||||
const missing = channel.permissionsFor(this.client.user!)?.missing(command.clientPermissions);
|
const missing = channel.permissionsFor(this.client.user!)?.missing(command.clientPermissions);
|
||||||
if (!missing || missing.length)
|
if (!missing || missing.length)
|
||||||
return super._fail({ error: true, missing: missing?.join(', ') || 'all', silent: true });
|
return super._fail({ error: true, missing: missing?.join(', ') || 'all', silent: true });
|
||||||
|
@ -78,6 +78,7 @@ class CommandHandler extends Observer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
const messageWrapper = new MessageWrapper(this.client, message);
|
const messageWrapper = new MessageWrapper(this.client, message);
|
||||||
const { command, parameters } = await this._getCommand(messageWrapper);
|
const { command, parameters } = await this._getCommand(messageWrapper);
|
||||||
if (!command)
|
if (!command)
|
||||||
@ -100,6 +101,8 @@ class CommandHandler extends Observer
|
|||||||
if (await this._parseResult(invoker, result))
|
if (await this._parseResult(invoker, result))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const end = Date.now();
|
||||||
|
this.logger.info(`Message parse took ${end - start}ms`);
|
||||||
await this._executeCommand(invoker, result.options ?? {});
|
await this._executeCommand(invoker, result.options ?? {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +225,7 @@ class CommandHandler extends Observer
|
|||||||
return [];
|
return [];
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
const start = Date.now();
|
||||||
for (const inhibitor of inhibitors.values())
|
for (const inhibitor of inhibitors.values())
|
||||||
{
|
{
|
||||||
if (inhibitor.guild && !invoker.inGuild())
|
if (inhibitor.guild && !invoker.inGuild())
|
||||||
@ -230,6 +234,8 @@ class CommandHandler extends Observer
|
|||||||
}
|
}
|
||||||
|
|
||||||
const errors = (await Promise.all(promises)).filter((result) => result.error);
|
const errors = (await Promise.all(promises)).filter((result) => result.error);
|
||||||
|
const end = Date.now();
|
||||||
|
this.logger.info(`Inhibitors took ${end - start}ms to complete`);
|
||||||
if (!errors.length)
|
if (!errors.length)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
@ -271,7 +277,7 @@ class CommandHandler extends Observer
|
|||||||
{
|
{
|
||||||
if (!(invoker.command instanceof SettingsCommand))
|
if (!(invoker.command instanceof SettingsCommand))
|
||||||
invoker.command.error(now);
|
invoker.command.error(now);
|
||||||
this.logger.error(`\n[${invoker.type.toUpperCase()}] Command ${debugstr} errored:\nGuild: ${invoker.guild?.name || 'dms'} (${invoker.guild?.id || ''})\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key].asString} (${options[key].rawValue})]`).join('\n')}\n${error.stack || error}`);
|
this.logger.error(`\n[${invoker.type.toUpperCase()}] Command ${debugstr} errored:\nGuild: ${invoker.inGuild() ? invoker.guild?.name : 'dms'} (${invoker.guild?.id || ''})\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key].asString} (${options[key].rawValue})]`).join('\n')}\n${error.stack || error}`);
|
||||||
this._generateError(invoker, { type: 'commandHandler' });
|
this._generateError(invoker, { type: 'commandHandler' });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -257,7 +257,7 @@ class LinkFilterSetting extends FilterSetting
|
|||||||
}
|
}
|
||||||
actionObject.trigger = words;
|
actionObject.trigger = words;
|
||||||
if (removed.length)
|
if (removed.length)
|
||||||
invoker.channel!.send(invoker.format(
|
await invoker.channel!.send(invoker.format(
|
||||||
'SETTING_LINKFILTER_WORD_IN_ACTION',
|
'SETTING_LINKFILTER_WORD_IN_ACTION',
|
||||||
{ words: removed.join('`, `') }
|
{ words: removed.join('`, `') }
|
||||||
));
|
));
|
||||||
|
@ -271,7 +271,7 @@ class WordFilterSetting extends FilterSetting
|
|||||||
}
|
}
|
||||||
actionObject.trigger = words;
|
actionObject.trigger = words;
|
||||||
if (removed.length)
|
if (removed.length)
|
||||||
invoker.channel!.send(invoker.format(
|
await invoker.channel!.send(invoker.format(
|
||||||
'SETTING_WORDFILTER_WORD_IN_ACTION',
|
'SETTING_WORDFILTER_WORD_IN_ACTION',
|
||||||
{ words: removed.join('`, `') }
|
{ words: removed.join('`, `') }
|
||||||
));
|
));
|
||||||
|
@ -135,7 +135,7 @@ abstract class FilterSetting extends Setting
|
|||||||
if (typeof time === 'number')
|
if (typeof time === 'number')
|
||||||
actionObject.duration = time;
|
actionObject.duration = time;
|
||||||
else
|
else
|
||||||
invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_TIMER_FAIL'));
|
await invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_TIMER_FAIL'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,14 +161,14 @@ abstract class FilterSetting extends Setting
|
|||||||
if (value < 0 || value > 100)
|
if (value < 0 || value > 100)
|
||||||
{
|
{
|
||||||
value = value < 0 ? 0 : 100;
|
value = value < 0 ? 0 : 100;
|
||||||
invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_RANGE', { value }));
|
await invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_RANGE', { value }));
|
||||||
}
|
}
|
||||||
actionObject.points = value;
|
actionObject.points = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
actionObject.points = null;
|
actionObject.points = null;
|
||||||
invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_FAIL'));
|
await invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_FAIL'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ abstract class FilterSetting extends Setting
|
|||||||
if (typeof time === 'number')
|
if (typeof time === 'number')
|
||||||
actionObject.expiration = time;
|
actionObject.expiration = time;
|
||||||
else
|
else
|
||||||
invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_EXPIRATION_FAIL'));
|
await invoker.channel!.send(invoker.format('SETTING_FILTER_ACTION_ADD_EXPIRATION_FAIL'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ abstract class FilterSetting extends Setting
|
|||||||
points = 0;
|
points = 0;
|
||||||
else if (points > 100)
|
else if (points > 100)
|
||||||
points = 100;
|
points = 100;
|
||||||
invoker.channel?.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_RANGE', { value: points }));
|
await invoker.channel?.send(invoker.format('SETTING_FILTER_ACTION_ADD_POINTS_RANGE', { value: points }));
|
||||||
}
|
}
|
||||||
|
|
||||||
action.points = points;
|
action.points = points;
|
||||||
|
Loading…
Reference in New Issue
Block a user