mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
* docs: fix documentation in various places All stores: resolveID returns a nullable Snowflake GuildAuditLogs: ActionType also can be ALL MessageEmbed: make files property show up in the docs ClientApplication: resetSecret and resetToken return a promise ClientManager: status is readonly Guild: features is an array of strings and ban no longer accepts a number or string Guild: ban method no longer accepts a string or number GuildMember: ^ RichPresenceAssets: small and large Image are Snowflakes, also fixed parameter documentation for small and large image url method WebhookMessageOptions: file property is no longer a thing * docs: improve GuildAuditLogs documentation Prefix types with AuditLog to avoid confusion Document GuildAuditLogs' static Targets and Actions properties and add necessary typedefs Use typdefs over primitives where possible. * fix documentation for Guild#defaultRole
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
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 {
|
|
constructor(client, iterable) {
|
|
super(client, iterable, 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 {?Snowflake}
|
|
*/
|
|
resolveID(user) {
|
|
if (user instanceof GuildMember) return user.user.id;
|
|
if (user instanceof Message) return user.author.id;
|
|
return super.resolveID(user);
|
|
}
|
|
|
|
/**
|
|
* Obtains a user from Discord, or the user cache if it's already available.
|
|
* <warn>This is only available when using a bot account.</warn>
|
|
* @param {Snowflake} id ID of the user
|
|
* @param {boolean} [cache=true] Whether to cache the new user object if it isn't already
|
|
* @returns {Promise<User>}
|
|
*/
|
|
fetch(id, cache = true) {
|
|
const existing = this.get(id);
|
|
if (existing) return Promise.resolve(existing);
|
|
|
|
return this.client.api.users(id).get().then(data => this.create(data, cache));
|
|
}
|
|
}
|
|
|
|
module.exports = UserStore;
|