cache for fetchInvite in client
This commit is contained in:
parent
e261debb69
commit
36b66fb907
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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'),
|
||||||
|
Loading…
Reference in New Issue
Block a user