mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Datastore cleanup (#1892)
* Start Store cleanup * wip store cleanup * fix iterables initiating datastores * handle the possibility of a datastore with no holds and no its own 'create' method * more cleanup (instances that need more than just client/data) * missed RoleStore extras * not sure how eslint didn't catch that tab... * avoid re-getting the channel we already have... * cleanup resolvers and refactor them into DataStores * ^ * and remove * fix some bugs * fix lint * fix documentation maybe? * formatting * fix presences * really fix presences this time * bad fix was bad... let;s see how bad this one is.. * forgot to save a file * make presence resolving take userresolveables too * fix tabs in jsdocs * fix bad fix from last night that caused issues, with better fix... * oops
This commit is contained in:
@@ -10,18 +10,44 @@ const { Error } = require('../errors');
|
||||
*/
|
||||
class GuildMemberStore extends DataStore {
|
||||
constructor(guild, iterable) {
|
||||
super(guild.client, iterable);
|
||||
super(guild.client, iterable, GuildMember);
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
create(data, cache = true) {
|
||||
const existing = this.get(data.user.id);
|
||||
if (existing) return existing;
|
||||
create(data, cache) {
|
||||
return super.create(data, cache, { extras: [this.guild] });
|
||||
}
|
||||
|
||||
const member = new GuildMember(this.guild, data);
|
||||
if (cache) this.set(member.id, member);
|
||||
/**
|
||||
* Data that resolves to give a GuildMember object. This can be:
|
||||
* * A GuildMember object
|
||||
* * A User resolvable
|
||||
* @typedef {GuildMember|UserResolveable} GuildMemberResolvable
|
||||
*/
|
||||
|
||||
return member;
|
||||
/**
|
||||
* Resolves a GuildMemberResolvable to a GuildMember object.
|
||||
* @param {GuildMemberResolvable} member The user that is part of the guild
|
||||
* @returns {?GuildMember}
|
||||
*/
|
||||
resolve(member) {
|
||||
const memberResolveable = super.resolve(member);
|
||||
if (memberResolveable) return memberResolveable;
|
||||
const userResolveable = this.client.users.resolveID(member);
|
||||
if (userResolveable) return super.resolve(userResolveable);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a GuildMemberResolvable to an member ID string.
|
||||
* @param {GuildMemberResolvable} member The user that is part of the guild
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveID(member) {
|
||||
const memberResolveable = super.resolveID(member);
|
||||
if (memberResolveable) return memberResolveable;
|
||||
const userResolveable = this.client.users.resolveID(member);
|
||||
return this.has(userResolveable) ? userResolveable : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,10 +90,10 @@ class GuildMemberStore extends DataStore {
|
||||
*/
|
||||
fetch(options) {
|
||||
if (!options) return this._fetchMany();
|
||||
const user = this.client.resolver.resolveUserID(options);
|
||||
const user = this.resolveID(options);
|
||||
if (user) return this._fetchSingle({ user, cache: true });
|
||||
if (options.user) {
|
||||
options.user = this.client.resolver.resolveUserID(options.user);
|
||||
options.user = this.resolveID(options.user);
|
||||
if (options.user) return this._fetchSingle(options);
|
||||
}
|
||||
return this._fetchMany(options);
|
||||
|
||||
Reference in New Issue
Block a user