From 36b66fb907117078c7f7a7986b0d8157ff596640 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 13 Jul 2022 11:42:42 +0300 Subject: [PATCH] cache for fetchInvite in client --- src/structure/DiscordClient.js | 14 +++++++++++++- src/structure/components/observers/GuildLogging.js | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/structure/DiscordClient.js b/src/structure/DiscordClient.js index 7da8a54..8f27e7e 100644 --- a/src/structure/DiscordClient.js +++ b/src/structure/DiscordClient.js @@ -1,4 +1,4 @@ -const { Client, Collection } = require('discord.js'); +const { Client, Collection, DataResolver } = require('discord.js'); const chalk = require('chalk'); const { inspect } = require('util'); @@ -48,6 +48,7 @@ class DiscordClient extends Client { }; this.guildWrappers = new Collection(); this.userWrappers = new Collection(); + this.invites = new Collection(); this._defaultConfig = {}; this._activity = 0; @@ -317,6 +318,17 @@ class DiscordClient extends Client { } + async fetchInvite(invite, opts) { + const code = DataResolver.resolveInviteCode(invite); + const existing = this.invites.get(code); + if (existing && (!existing.expiresTimestamp || existing.expiresTimestamp > Date.now())) return existing; + + const fetched = await super.fetchInvite(code, opts); + this.invites.set(fetched.code, fetched); + return fetched; + + } + resolveUsers(...opts) { return this.resolver.resolveUsers(...opts); } diff --git a/src/structure/components/observers/GuildLogging.js b/src/structure/components/observers/GuildLogging.js index da6b3bf..87a1d70 100644 --- a/src/structure/components/observers/GuildLogging.js +++ b/src/structure/components/observers/GuildLogging.js @@ -433,11 +433,13 @@ class GuildLogger extends Observer { value }); + // TODO figure out how to do messages longer than 2k if (content && content.length > cutOff) fields.push({ name: '\u200b', - value: content.substring(cutOff) + value: content.substring(cutOff, cutOff*2) }); + // TODO Links can be long, figure out a way to ensure a field here doesn't exceed the limit if (uploaded.length) fields.push({ name: wrapper.format('BULK_DELETE_ATTACHMENTS'), value: uploaded.join('\n'),