cache for fetchInvite in client

This commit is contained in:
Erik 2022-07-13 11:42:42 +03:00
parent e261debb69
commit 36b66fb907
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,4 @@
const { Client, Collection } = require('discord.js'); const { Client, Collection, DataResolver } = require('discord.js');
const chalk = require('chalk'); const chalk = require('chalk');
const { inspect } = require('util'); const { inspect } = require('util');
@ -48,6 +48,7 @@ class DiscordClient extends Client {
}; };
this.guildWrappers = new Collection(); this.guildWrappers = new Collection();
this.userWrappers = new Collection(); this.userWrappers = new Collection();
this.invites = new Collection();
this._defaultConfig = {}; this._defaultConfig = {};
this._activity = 0; 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) { resolveUsers(...opts) {
return this.resolver.resolveUsers(...opts); return this.resolver.resolveUsers(...opts);
} }

View File

@ -433,11 +433,13 @@ class GuildLogger extends Observer {
value value
}); });
// TODO figure out how to do messages longer than 2k
if (content && content.length > cutOff) fields.push({ if (content && content.length > cutOff) fields.push({
name: '\u200b', 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({ if (uploaded.length) fields.push({
name: wrapper.format('BULK_DELETE_ATTACHMENTS'), name: wrapper.format('BULK_DELETE_ATTACHMENTS'),
value: uploaded.join('\n'), value: uploaded.join('\n'),