-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Tropicallism/main
I hope it will work fine :))
- Loading branch information
Showing
21 changed files
with
5,918 additions
and
5,938 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
'use strict'; | ||
|
||
const CachedManager = require('./CachedManager'); | ||
const GuildMember = require('../structures/GuildMember'); | ||
const Message = require('../structures/Message'); | ||
const ThreadMember = require('../structures/ThreadMember'); | ||
const User = require('../structures/User'); | ||
|
||
/** | ||
* Manages API methods for users and stores their cache. | ||
* @extends {CachedManager} | ||
*/ | ||
class BlockedManager extends CachedManager { | ||
constructor(client, iterable) { | ||
super(client, User, iterable); | ||
} | ||
|
||
/** | ||
* The cache of this manager | ||
* @type {Collection<Snowflake, User>} | ||
* @name BlockedManager#cache | ||
*/ | ||
|
||
/** | ||
* 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 | ||
* * A ThreadMember object | ||
* @typedef {User|Snowflake|Message|GuildMember|ThreadMember} UserResolvable | ||
*/ | ||
|
||
/** | ||
* Resolves a {@link UserResolvable} to a {@link User} object. | ||
* @param {UserResolvable} user The UserResolvable to identify | ||
* @returns {?User} | ||
*/ | ||
resolve(user) { | ||
if (user instanceof GuildMember || user instanceof ThreadMember) return user.user; | ||
if (user instanceof Message) return user.author; | ||
return super.resolve(user); | ||
} | ||
|
||
/** | ||
* Resolves a {@link UserResolvable} to a {@link User} id. | ||
* @param {UserResolvable} user The UserResolvable to identify | ||
* @returns {?Snowflake} | ||
*/ | ||
resolveId(user) { | ||
if (user instanceof ThreadMember) return user.id; | ||
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. | ||
* @param {UserResolvable} user The user to fetch | ||
* @param {BaseFetchOptions} [options] Additional options for this fetch | ||
* @returns {Promise<User>} | ||
*/ | ||
async fetch(user, { cache = true, force = false } = {}) { | ||
const id = this.resolveId(user); | ||
if (!force) { | ||
const existing = this.cache.get(id); | ||
if (existing && !existing.partial) return existing; | ||
} | ||
|
||
const data = await this.client.api.users(id).get(); | ||
return this._add(data, cache); | ||
} | ||
} | ||
|
||
module.exports = BlockedManager; | ||
'use strict'; | ||
|
||
const CachedManager = require('./CachedManager'); | ||
const GuildMember = require('../structures/GuildMember'); | ||
const Message = require('../structures/Message'); | ||
const ThreadMember = require('../structures/ThreadMember'); | ||
const User = require('../structures/User'); | ||
|
||
/** | ||
* Manages API methods for users and stores their cache. | ||
* @extends {CachedManager} | ||
*/ | ||
class BlockedManager extends CachedManager { | ||
constructor(client, iterable) { | ||
super(client, User, iterable); | ||
} | ||
|
||
/** | ||
* The cache of this manager | ||
* @type {Collection<Snowflake, User>} | ||
* @name BlockedManager#cache | ||
*/ | ||
|
||
/** | ||
* 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 | ||
* * A ThreadMember object | ||
* @typedef {User|Snowflake|Message|GuildMember|ThreadMember} UserResolvable | ||
*/ | ||
|
||
/** | ||
* Resolves a {@link UserResolvable} to a {@link User} object. | ||
* @param {UserResolvable} user The UserResolvable to identify | ||
* @returns {?User} | ||
*/ | ||
resolve(user) { | ||
if (user instanceof GuildMember || user instanceof ThreadMember) return user.user; | ||
if (user instanceof Message) return user.author; | ||
return super.resolve(user); | ||
} | ||
|
||
/** | ||
* Resolves a {@link UserResolvable} to a {@link User} id. | ||
* @param {UserResolvable} user The UserResolvable to identify | ||
* @returns {?Snowflake} | ||
*/ | ||
resolveId(user) { | ||
if (user instanceof ThreadMember) return user.id; | ||
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. | ||
* @param {UserResolvable} user The user to fetch | ||
* @param {BaseFetchOptions} [options] Additional options for this fetch | ||
* @returns {Promise<User>} | ||
*/ | ||
async fetch(user, { cache = true, force = false } = {}) { | ||
const id = this.resolveId(user); | ||
if (!force) { | ||
const existing = this.cache.get(id); | ||
if (existing && !existing.partial) return existing; | ||
} | ||
|
||
const data = await this.client.api.users(id).get(); | ||
return this._add(data, cache); | ||
} | ||
} | ||
|
||
module.exports = BlockedManager; |
Oops, something went wrong.