diff --git a/src/client/DiscordClient.ts b/src/client/DiscordClient.ts index b6d5711..fdbec24 100644 --- a/src/client/DiscordClient.ts +++ b/src/client/DiscordClient.ts @@ -490,14 +490,29 @@ class DiscordClient extends Client return this.localeLoader.format(language, index, params, code); } - getGuildWrapper (id: string) + async getGuildWrapper (id: string) { if (this.#guildWrappers.has(id)) - return this.#guildWrappers.get(id); - if (!this.guilds.cache.has(id)) - throw new Error('Guild is not present on client'); + return this.#guildWrappers.get(id)!; + let guild = this.guilds.cache.get(id); + if (!guild) + guild = await this.guilds.fetch({ guild: id, cache: true }); + if (!guild) + throw new Error('Guild does not exist'); - const wrapper = new GuildWrapper(this, this.guilds.cache.get(id) as Guild); + const wrapper = new GuildWrapper(this, guild); + this.#guildWrappers.set(id, wrapper); + return wrapper; + } + + getGuildWrapperSync (id: string) + { + if (this.#guildWrappers.has(id)) + return this.#guildWrappers.get(id)!; + const guild = this.guilds.cache.get(id); + if (!guild) + return null; + const wrapper = new GuildWrapper(this, guild); this.#guildWrappers.set(id, wrapper); return wrapper; } @@ -510,7 +525,7 @@ class DiscordClient extends Client { const id = typeof resolveable === 'string' ? resolveable : resolveable.id; - if (this.#userWrappers.has(id)) + if (this.#userWrappers.has(id) && !fetch) return this.#userWrappers.get(id) || null; if (!fetch) diff --git a/src/client/components/EventHooker.ts b/src/client/components/EventHooker.ts index d5dadfa..7f6dc45 100644 --- a/src/client/components/EventHooker.ts +++ b/src/client/components/EventHooker.ts @@ -79,7 +79,7 @@ class EventHooker { if (arg && typeof arg === 'object' && 'guild' in arg && arg.guild) { - const wrapper = this.#target.getGuildWrapper(arg.guild!.id); + const wrapper = await this.#target.getGuildWrapper(arg.guild!.id); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore arg.guildWrapper = wrapper; diff --git a/src/client/components/commands/administration/Modstats.ts b/src/client/components/commands/administration/Modstats.ts index 78b8a38..1ade63f 100644 --- a/src/client/components/commands/administration/Modstats.ts +++ b/src/client/components/commands/administration/Modstats.ts @@ -71,11 +71,8 @@ class ModstatsCommand extends SlashCommand (result.data[log.executor][log.type] as number)++; } - for (const user of Object.keys(result)) + for (const user of Object.keys(result.data)) { - if ([ 'time', 'totals' ].includes(user)) - continue; - let sum = 0; if (!result.totals.sum) result.totals.sum = 0; diff --git a/src/client/components/observers/Automoderation.ts b/src/client/components/observers/Automoderation.ts index ce23aba..57cb7d9 100644 --- a/src/client/components/observers/Automoderation.ts +++ b/src/client/components/observers/Automoderation.ts @@ -409,7 +409,7 @@ export default class AutoModeration extends Observer implements Initialisable const [ , actionType ] = customId.split('_'); const { permissions } = this.client; - const guild = this.client.getGuildWrapper(interaction.guildId); + const guild = await this.client.getGuildWrapper(interaction.guildId); if (!guild) return; const moderator = await guild.memberWrapper(interaction.user.id); diff --git a/src/client/components/observers/GuildLogging.ts b/src/client/components/observers/GuildLogging.ts index 5f2e225..a8a390b 100644 --- a/src/client/components/observers/GuildLogging.ts +++ b/src/client/components/observers/GuildLogging.ts @@ -409,7 +409,7 @@ class GuildLogger extends Observer if (!guild || partial) return; - const wrapper = this.client.getGuildWrapper(guild.id); + const wrapper = await this.client.getGuildWrapper(guild.id); if (!wrapper) return; const settings = await wrapper.settings(); diff --git a/src/client/components/observers/UtilityHook.ts b/src/client/components/observers/UtilityHook.ts index 9a759ec..113a688 100644 --- a/src/client/components/observers/UtilityHook.ts +++ b/src/client/components/observers/UtilityHook.ts @@ -226,7 +226,7 @@ class UtilityHook extends Observer if (!message.guildId) return; - const guild = this.client.getGuildWrapper(message.guildId); + const guild = await this.client.getGuildWrapper(message.guildId); if (!guild) return; const channel = await guild.resolveChannel(message.channelId); @@ -258,7 +258,9 @@ class UtilityHook extends Observer return; const { guild: g, message, customId, author, channel, values } = interaction; let { member } = interaction; - const guild = this.client.getGuildWrapper(g?.id ?? ''); + if (!g) + return; + const guild = await this.client.getGuildWrapper(g.id); if (!guild || !member || !customId?.includes('selfrole') || !message || !values) return; const { selfrole } = await guild.settings(); diff --git a/src/client/components/wrappers/InteractionWrapper.ts b/src/client/components/wrappers/InteractionWrapper.ts index 83e76a1..c1fe7ea 100644 --- a/src/client/components/wrappers/InteractionWrapper.ts +++ b/src/client/components/wrappers/InteractionWrapper.ts @@ -37,7 +37,7 @@ class InteractionWrapper constructor (client: DiscordClient, interaction: Interaction) { if (interaction.guildId) - this.#guild = (client.getGuildWrapper(interaction.guildId) ?? null) as If; + this.#guild = client.getGuildWrapperSync(interaction.guildId) as If; else this.#guild = null as If; diff --git a/src/client/components/wrappers/MessageWrapper.ts b/src/client/components/wrappers/MessageWrapper.ts index d6b3412..57c6b1f 100644 --- a/src/client/components/wrappers/MessageWrapper.ts +++ b/src/client/components/wrappers/MessageWrapper.ts @@ -21,7 +21,7 @@ class MessageWrapper this.#client = client; this.#message = message; if (message.guildId) - this.#guild = (client.getGuildWrapper(message.guildId) ?? null) as If; + this.#guild = client.getGuildWrapperSync(message.guildId) as If; else this.#guild = null as If; diff --git a/src/constants/FilterPresets.ts b/src/constants/FilterPresets.ts index 736ff8d..2aede2d 100644 --- a/src/constants/FilterPresets.ts +++ b/src/constants/FilterPresets.ts @@ -18,15 +18,16 @@ const FilterPresets: { "slurs": [ "n(ae|ji|j|y|i|x|!|1|\\||l)(gg?|qq?|99?|bb)((e|3)r|let|ur|\\s?nog|y|ah?|or)s?", "nick\\s?(&\\s)?(gurr?|ger|ga)", - "(fur\\s?)?f(e|a|4|x)(gg?|qq|99?)(otry|ots|ot|y|s)?", + "(fur\\s?)?f(e|a|4|x)(gg?|qq?|99?)(otry|ots|ot|y|s)?", "(fur\\s?)?fgg?ts?", "negro(id|e)?s?", "g(o|0)(o|0)k", "(?