mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +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:
@@ -1,18 +1,46 @@
|
||||
const DataStore = require('./DataStore');
|
||||
const User = require('../structures/User');
|
||||
const GuildMember = require('../structures/GuildMember');
|
||||
const Message = require('../structures/Message');
|
||||
|
||||
/**
|
||||
* A data store to store User models.
|
||||
* @extends {DataStore}
|
||||
*/
|
||||
class UserStore extends DataStore {
|
||||
create(data, cache = true) {
|
||||
const existing = this.get(data.id);
|
||||
if (existing) return existing;
|
||||
constructor(client, iterable) {
|
||||
super(client, iterable, User);
|
||||
}
|
||||
|
||||
const user = new User(this.client, data);
|
||||
if (cache) this.set(user.id, user);
|
||||
return user;
|
||||
/**
|
||||
* Data that resolves to give a User object. This can be:
|
||||
* * A User object
|
||||
* * A Snowflake
|
||||
* * A Message object (resolves to the message author)
|
||||
* * A GuildMember object
|
||||
* @typedef {User|Snowflake|Message|GuildMember} UserResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a UserResolvable to a User object.
|
||||
* @param {UserResolvable} user The UserResolvable to identify
|
||||
* @returns {?User}
|
||||
*/
|
||||
resolve(user) {
|
||||
if (user instanceof GuildMember) return user.user;
|
||||
if (user instanceof Message) return user.author;
|
||||
return super.resolve(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a UserResolvable to a user ID string.
|
||||
* @param {UserResolvable} user The UserResolvable to identify
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveID(user) {
|
||||
if (user instanceof GuildMember) return user.user.id;
|
||||
if (user instanceof Message) return user.author.id;
|
||||
return super.resolveID(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user