chore: consistency/prettier (#3852)

* chore: consistency/prettier

* chore: rebase

* chore: rebase

* chore: include typings

* fix: include typings file in prettier lint-staged
This commit is contained in:
Crawl
2020-02-29 14:35:57 +01:00
committed by GitHub
parent 6650d50a56
commit c065156a88
127 changed files with 5198 additions and 4513 deletions

View File

@@ -34,9 +34,9 @@ class BaseManager {
this.cacheType = cacheType;
/**
* Holds the cache for the data model
* @type {Collection}
*/
* Holds the cache for the data model
* @type {Collection}
*/
this.cache = new cacheType(...cacheOptions);
if (iterable) for (const i of iterable) this.add(i);
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Channel = require('../structures/Channel');
const BaseManager = require('./BaseManager');
const Channel = require('../structures/Channel');
const { Events } = require('../util/Constants');
/**
@@ -14,10 +14,10 @@ class ChannelManager extends BaseManager {
}
/**
* The cache of Channels
* @type {Collection<Snowflake, Channel>}
* @name ChannelManager#cache
*/
* The cache of Channels
* @type {Collection<Snowflake, Channel>}
* @name ChannelManager#cache
*/
add(data, guild, cache = true) {
const existing = this.cache.get(data.id);

View File

@@ -1,9 +1,9 @@
'use strict';
const { ChannelTypes } = require('../util/Constants');
const BaseManager = require('./BaseManager');
const GuildChannel = require('../structures/GuildChannel');
const PermissionOverwrites = require('../structures/PermissionOverwrites');
const { ChannelTypes } = require('../util/Constants');
/**
* Manages API methods for GuildChannels and stores their cache.

View File

@@ -1,11 +1,11 @@
'use strict';
const Collection = require('../util/Collection');
const BaseManager = require('./BaseManager');
const { TypeError } = require('../errors');
const GuildEmoji = require('../structures/GuildEmoji');
const ReactionEmoji = require('../structures/ReactionEmoji');
const Collection = require('../util/Collection');
const DataResolver = require('../util/DataResolver');
const { TypeError } = require('../errors');
/**
* Manages API methods for GuildEmojis and stores their cache.
@@ -22,10 +22,10 @@ class GuildEmojiManager extends BaseManager {
}
/**
* The cache of GuildEmojis
* @type {Collection<Snowflake, GuildEmoji>}
* @name GuildEmojiManager#cache
*/
* The cache of GuildEmojis
* @type {Collection<Snowflake, GuildEmoji>}
* @name GuildEmojiManager#cache
*/
add(data, cache) {
return super.add(data, cache, { extras: [this.guild] });
@@ -58,14 +58,17 @@ class GuildEmojiManager extends BaseManager {
for (let role of roles instanceof Collection ? roles.values() : roles) {
role = this.guild.roles.resolve(role);
if (!role) {
return Promise.reject(new TypeError('INVALID_TYPE', 'options.roles',
'Array or Collection of Roles or Snowflakes', true));
return Promise.reject(
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
);
}
data.roles.push(role.id);
}
}
return this.client.api.guilds(this.guild.id).emojis.post({ data, reason })
return this.client.api
.guilds(this.guild.id)
.emojis.post({ data, reason })
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Collection = require('../util/Collection');
const { TypeError } = require('../errors');
const Collection = require('../util/Collection');
/**
* Manages API methods for roles belonging to emojis and stores their cache.
@@ -56,8 +56,7 @@ class GuildEmojiRoleManager {
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true));
}
const newRoles = [...new Set(roleOrRoles.concat(...this._roles.values()))];
@@ -75,8 +74,7 @@ class GuildEmojiRoleManager {
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolveID(r));
if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true));
}
const newRoles = this._roles.keyArray().filter(role => !roleOrRoles.includes(role));

View File

@@ -1,21 +1,21 @@
'use strict';
const BaseManager = require('./BaseManager');
const DataResolver = require('../util/DataResolver');
const Guild = require('../structures/Guild');
const GuildChannel = require('../structures/GuildChannel');
const GuildEmoji = require('../structures/GuildEmoji');
const GuildMember = require('../structures/GuildMember');
const Invite = require('../structures/Invite');
const Role = require('../structures/Role');
const {
Events,
VerificationLevels,
DefaultMessageNotifications,
ExplicitContentFilterLevels,
} = require('../util/Constants');
const Guild = require('../structures/Guild');
const GuildChannel = require('../structures/GuildChannel');
const GuildMember = require('../structures/GuildMember');
const DataResolver = require('../util/DataResolver');
const Permissions = require('../util/Permissions');
const { resolveColor } = require('../util/Util');
const GuildEmoji = require('../structures/GuildEmoji');
const Invite = require('../structures/Invite');
const Role = require('../structures/Role');
/**
* Manages API methods for Guilds and stores their cache.
@@ -91,11 +91,15 @@ class GuildManager extends BaseManager {
* @returns {?Guild}
*/
resolve(guild) {
if (guild instanceof GuildChannel ||
if (
guild instanceof GuildChannel ||
guild instanceof GuildMember ||
guild instanceof GuildEmoji ||
guild instanceof Role ||
(guild instanceof Invite && guild.guild)) return super.resolve(guild.guild);
(guild instanceof Invite && guild.guild)
) {
return super.resolve(guild.guild);
}
return super.resolve(guild);
}
@@ -108,11 +112,15 @@ class GuildManager extends BaseManager {
* @returns {?Snowflake}
*/
resolveID(guild) {
if (guild instanceof GuildChannel ||
if (
guild instanceof GuildChannel ||
guild instanceof GuildMember ||
guild instanceof GuildEmoji ||
guild instanceof Role ||
(guild instanceof Invite && guild.guild)) return super.resolveID(guild.guild.id);
(guild instanceof Invite && guild.guild)
) {
return super.resolveID(guild.guild.id);
}
return super.resolveID(guild);
}
@@ -132,15 +140,18 @@ class GuildManager extends BaseManager {
* @param {VerificationLevel} [options.verificationLevel] The verification level for the guild
* @returns {Promise<Guild>} The guild that was created
*/
async create(name, {
channels = [],
defaultMessageNotifications,
explicitContentFilter,
icon = null,
region,
roles = [],
verificationLevel,
} = {}) {
async create(
name,
{
channels = [],
defaultMessageNotifications,
explicitContentFilter,
icon = null,
region,
roles = [],
verificationLevel,
} = {},
) {
icon = await DataResolver.resolveImage(icon);
if (typeof verificationLevel !== 'undefined' && typeof verificationLevel !== 'number') {
verificationLevel = VerificationLevels.indexOf(verificationLevel);
@@ -167,16 +178,19 @@ class GuildManager extends BaseManager {
if (role.permissions) role.permissions = Permissions.resolve(role.permissions);
}
return new Promise((resolve, reject) =>
this.client.api.guilds.post({ data: {
name,
region,
icon,
verification_level: verificationLevel,
default_message_notifications: defaultMessageNotifications,
explicit_content_filter: explicitContentFilter,
channels,
roles,
} })
this.client.api.guilds
.post({
data: {
name,
region,
icon,
verification_level: verificationLevel,
default_message_notifications: defaultMessageNotifications,
explicit_content_filter: explicitContentFilter,
channels,
roles,
},
})
.then(data => {
if (this.client.guilds.cache.has(data.id)) return resolve(this.client.guilds.cache.get(data.id));

View File

@@ -1,10 +1,10 @@
'use strict';
const BaseManager = require('./BaseManager');
const GuildMember = require('../structures/GuildMember');
const { Events, OPCodes } = require('../util/Constants');
const Collection = require('../util/Collection');
const { Error, TypeError } = require('../errors');
const GuildMember = require('../structures/GuildMember');
const Collection = require('../util/Collection');
const { Events, OPCodes } = require('../util/Constants');
/**
* Manages API methods for GuildMembers and stores their cache.
@@ -148,10 +148,15 @@ class GuildMemberManager extends BaseManager {
*/
prune({ days = 7, dry = false, count = true, reason } = {}) {
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
return this.client.api.guilds(this.guild.id).prune[dry ? 'get' : 'post']({ query: {
days,
compute_prune_count: count,
}, reason })
return this.client.api
.guilds(this.guild.id)
.prune[dry ? 'get' : 'post']({
query: {
days,
compute_prune_count: count,
},
reason,
})
.then(data => data.pruned);
}
@@ -174,7 +179,9 @@ class GuildMemberManager extends BaseManager {
if (options.days) options['delete-message-days'] = options.days;
const id = this.client.users.resolveID(user);
if (!id) return Promise.reject(new Error('BAN_RESOLVE_ID', true));
return this.client.api.guilds(this.guild.id).bans[id].put({ query: options })
return this.client.api
.guilds(this.guild.id)
.bans[id].put({ query: options })
.then(() => {
if (user instanceof GuildMember) return user;
const _user = this.client.users.resolve(id);
@@ -200,21 +207,25 @@ class GuildMemberManager extends BaseManager {
unban(user, reason) {
const id = this.client.users.resolveID(user);
if (!id) return Promise.reject(new Error('BAN_RESOLVE_ID'));
return this.client.api.guilds(this.guild.id).bans[id].delete({ reason })
return this.client.api
.guilds(this.guild.id)
.bans[id].delete({ reason })
.then(() => this.client.users.resolve(user));
}
_fetchSingle({ user, cache }) {
const existing = this.cache.get(user);
if (existing && !existing.partial) return Promise.resolve(existing);
return this.client.api.guilds(this.guild.id).members(user).get()
return this.client.api
.guilds(this.guild.id)
.members(user)
.get()
.then(data => this.add(data, cache));
}
_fetchMany({ limit = 0, withPresences: presences = false, user: user_ids, query } = {}) {
return new Promise((resolve, reject) => {
if (this.guild.memberCount === this.cache.size && (!query && !limit && !presences && !user_ids)) {
if (this.guild.memberCount === this.cache.size && !query && !limit && !presences && !user_ids) {
resolve(this.cache);
return;
}
@@ -237,9 +248,11 @@ class GuildMemberManager extends BaseManager {
for (const member of members.values()) {
if (option) fetchedMembers.set(member.id, member);
}
if (this.guild.memberCount <= this.cache.size ||
if (
this.guild.memberCount <= this.cache.size ||
(option && members.size < 1000) ||
(limit && fetchedMembers.size >= limit)) {
(limit && fetchedMembers.size >= limit)
) {
this.guild.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
let fetched = option ? fetchedMembers : this.cache;
if (user_ids && !Array.isArray(user_ids) && fetched.size) fetched = fetched.first();

View File

@@ -1,7 +1,7 @@
'use strict';
const Collection = require('../util/Collection');
const { TypeError } = require('../errors');
const Collection = require('../util/Collection');
/**
* Manages API methods for roles of a GuildMember and stores their cache.
@@ -49,7 +49,7 @@ class GuildMemberRoleManager {
get hoist() {
const hoistedRoles = this._roles.filter(role => role.hoist);
if (!hoistedRoles.size) return null;
return hoistedRoles.reduce((prev, role) => !prev || role.comparePositionTo(prev) > 0 ? role : prev);
return hoistedRoles.reduce((prev, role) => (!prev || role.comparePositionTo(prev) > 0 ? role : prev));
}
/**
@@ -60,7 +60,7 @@ class GuildMemberRoleManager {
get color() {
const coloredRoles = this._roles.filter(role => role.color);
if (!coloredRoles.size) return null;
return coloredRoles.reduce((prev, role) => !prev || role.comparePositionTo(prev) > 0 ? role : prev);
return coloredRoles.reduce((prev, role) => (!prev || role.comparePositionTo(prev) > 0 ? role : prev));
}
/**
@@ -69,7 +69,7 @@ class GuildMemberRoleManager {
* @readonly
*/
get highest() {
return this._roles.reduce((prev, role) => role.comparePositionTo(prev) > 0 ? role : prev, this._roles.first());
return this._roles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this._roles.first());
}
/**
@@ -82,8 +82,7 @@ class GuildMemberRoleManager {
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
if (roleOrRoles.includes(null)) {
throw new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true);
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
}
const newRoles = [...new Set(roleOrRoles.concat(...this._roles.values()))];
@@ -91,8 +90,7 @@ class GuildMemberRoleManager {
} else {
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
if (roleOrRoles === null) {
throw new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true);
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
}
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles.id].put({ reason });
@@ -113,8 +111,7 @@ class GuildMemberRoleManager {
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
if (roleOrRoles.includes(null)) {
throw new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true);
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
}
const newRoles = this._roles.filter(role => !roleOrRoles.includes(role));
@@ -122,8 +119,7 @@ class GuildMemberRoleManager {
} else {
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
if (roleOrRoles === null) {
throw new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true);
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
}
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles.id].delete({ reason });

View File

@@ -2,82 +2,82 @@
const BaseManager = require('./BaseManager');
const Message = require('../structures/Message');
const LimitedCollection = require('../util/LimitedCollection');
const Collection = require('../util/Collection');
const LimitedCollection = require('../util/LimitedCollection');
/**
* Manages API methods for Messages and holds their cache.
* @extends {BaseManager}
*/
* Manages API methods for Messages and holds their cache.
* @extends {BaseManager}
*/
class MessageManager extends BaseManager {
constructor(channel, iterable) {
super(channel.client, iterable, Message, LimitedCollection, channel.client.options.messageCacheMaxSize);
/**
* The channel that the messages belong to
* @type {TextBasedChannel}
*/
* The channel that the messages belong to
* @type {TextBasedChannel}
*/
this.channel = channel;
}
/**
* The cache of Messages
* @type {LimitedCollection<Snowflake, Message>}
* @name MessageManager#cache
*/
* The cache of Messages
* @type {LimitedCollection<Snowflake, Message>}
* @name MessageManager#cache
*/
add(data, cache) {
return super.add(data, cache, { extras: [this.channel] });
}
/**
* The parameters to pass in when requesting previous messages from a channel. `around`, `before` and
* `after` are mutually exclusive. All the parameters are optional.
* @typedef {Object} ChannelLogsQueryOptions
* @property {number} [limit=50] Number of messages to acquire
* @property {Snowflake} [before] ID of a message to get the messages that were posted before it
* @property {Snowflake} [after] ID of a message to get the messages that were posted after it
* @property {Snowflake} [around] ID of a message to get the messages that were posted around it
*/
* The parameters to pass in when requesting previous messages from a channel. `around`, `before` and
* `after` are mutually exclusive. All the parameters are optional.
* @typedef {Object} ChannelLogsQueryOptions
* @property {number} [limit=50] Number of messages to acquire
* @property {Snowflake} [before] ID of a message to get the messages that were posted before it
* @property {Snowflake} [after] ID of a message to get the messages that were posted after it
* @property {Snowflake} [around] ID of a message to get the messages that were posted around it
*/
/**
* Gets a message, or messages, from this channel.
* <info>The returned Collection does not contain reaction users of the messages if they were not cached.
* Those need to be fetched separately in such a case.</info>
* @param {Snowflake|ChannelLogsQueryOptions} [message] The ID of the message to fetch, or query parameters.
* @param {boolean} [cache=true] Whether to cache the message(s)
* @returns {Promise<Message>|Promise<Collection<Snowflake, Message>>}
* @example
* // Get message
* channel.messages.fetch('99539446449315840')
* .then(message => console.log(message.content))
* .catch(console.error);
* @example
* // Get messages
* channel.messages.fetch({ limit: 10 })
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
* @example
* // Get messages and filter by user ID
* channel.messages.fetch()
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
* .catch(console.error);
*/
* Gets a message, or messages, from this channel.
* <info>The returned Collection does not contain reaction users of the messages if they were not cached.
* Those need to be fetched separately in such a case.</info>
* @param {Snowflake|ChannelLogsQueryOptions} [message] The ID of the message to fetch, or query parameters.
* @param {boolean} [cache=true] Whether to cache the message(s)
* @returns {Promise<Message>|Promise<Collection<Snowflake, Message>>}
* @example
* // Get message
* channel.messages.fetch('99539446449315840')
* .then(message => console.log(message.content))
* .catch(console.error);
* @example
* // Get messages
* channel.messages.fetch({ limit: 10 })
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
* @example
* // Get messages and filter by user ID
* channel.messages.fetch()
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
* .catch(console.error);
*/
fetch(message, cache = true) {
return typeof message === 'string' ? this._fetchId(message, cache) : this._fetchMany(message, cache);
}
/**
* Fetches the pinned messages of this channel and returns a collection of them.
* <info>The returned Collection does not contain any reaction data of the messages.
* Those need to be fetched separately.</info>
* @param {boolean} [cache=true] Whether to cache the message(s)
* @returns {Promise<Collection<Snowflake, Message>>}
* @example
* // Get pinned messages
* channel.fetchPinned()
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
*/
* Fetches the pinned messages of this channel and returns a collection of them.
* <info>The returned Collection does not contain any reaction data of the messages.
* Those need to be fetched separately.</info>
* @param {boolean} [cache=true] Whether to cache the message(s)
* @returns {Promise<Collection<Snowflake, Message>>}
* @example
* // Get pinned messages
* channel.fetchPinned()
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
*/
fetchPinned(cache = true) {
return this.client.api.channels[this.channel.id].pins.get().then(data => {
const messages = new Collection();
@@ -94,23 +94,22 @@ class MessageManager extends BaseManager {
*/
/**
* Resolves a MessageResolvable to a Message object.
* @method resolve
* @memberof MessageManager
* @instance
* @param {MessageResolvable} message The message resolvable to resolve
* @returns {?Message}
*/
* Resolves a MessageResolvable to a Message object.
* @method resolve
* @memberof MessageManager
* @instance
* @param {MessageResolvable} message The message resolvable to resolve
* @returns {?Message}
*/
/**
* Resolves a MessageResolvable to a Message ID string.
* @method resolveID
* @memberof MessageManager
* @instance
* @param {MessageResolvable} message The message resolvable to resolve
* @returns {?Snowflake}
*/
* Resolves a MessageResolvable to a Message ID string.
* @method resolveID
* @memberof MessageManager
* @instance
* @param {MessageResolvable} message The message resolvable to resolve
* @returns {?Snowflake}
*/
/**
* Deletes a message, even if it's not cached.
@@ -119,7 +118,12 @@ class MessageManager extends BaseManager {
*/
async delete(message, reason) {
message = this.resolveID(message);
if (message) await this.client.api.channels(this.channel.id).messages(message).delete({ reason });
if (message) {
await this.client.api
.channels(this.channel.id)
.messages(message)
.delete({ reason });
}
}
async _fetchId(messageID, cache) {

View File

@@ -1,7 +1,7 @@
'use strict';
const { Presence } = require('../structures/Presence');
const BaseManager = require('./BaseManager');
const { Presence } = require('../structures/Presence');
/**
* Manages API methods for Presences and holds their cache.
@@ -13,10 +13,10 @@ class PresenceManager extends BaseManager {
}
/**
* The cache of Presences
* @type {Collection<Snowflake, Presence>}
* @name PresenceManager#cache
*/
* The cache of Presences
* @type {Collection<Snowflake, Presence>}
* @name PresenceManager#cache
*/
add(data, cache) {
const existing = this.cache.get(data.user.id);
@@ -32,10 +32,10 @@ class PresenceManager extends BaseManager {
*/
/**
* Resolves a PresenceResolvable to a Presence object.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Presence}
*/
* Resolves a PresenceResolvable to a Presence object.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Presence}
*/
resolve(presence) {
const presenceResolvable = super.resolve(presence);
if (presenceResolvable) return presenceResolvable;
@@ -44,10 +44,10 @@ class PresenceManager extends BaseManager {
}
/**
* Resolves a PresenceResolvable to a Presence ID string.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Snowflake}
*/
* Resolves a PresenceResolvable to a Presence ID string.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Snowflake}
*/
resolveID(presence) {
const presenceResolvable = super.resolveID(presence);
if (presenceResolvable) return presenceResolvable;

View File

@@ -1,7 +1,7 @@
'use strict';
const MessageReaction = require('../structures/MessageReaction');
const BaseManager = require('./BaseManager');
const MessageReaction = require('../structures/MessageReaction');
/**
* Manages API methods for reactions and holds their cache.
@@ -36,29 +36,32 @@ class ReactionManager extends BaseManager {
*/
/**
* Resolves a MessageReactionResolvable to a MessageReaction object.
* @method resolve
* @memberof ReactionManager
* @instance
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
* @returns {?MessageReaction}
*/
* Resolves a MessageReactionResolvable to a MessageReaction object.
* @method resolve
* @memberof ReactionManager
* @instance
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
* @returns {?MessageReaction}
*/
/**
* Resolves a MessageReactionResolvable to a MessageReaction ID string.
* @method resolveID
* @memberof ReactionManager
* @instance
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
* @returns {?Snowflake}
*/
* Resolves a MessageReactionResolvable to a MessageReaction ID string.
* @method resolveID
* @memberof ReactionManager
* @instance
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
* @returns {?Snowflake}
*/
/**
* Removes all reactions from a message.
* @returns {Promise<Message>}
*/
removeAll() {
return this.client.api.channels(this.message.channel.id).messages(this.message.id).reactions.delete()
return this.client.api
.channels(this.message.channel.id)
.messages(this.message.id)
.reactions.delete()
.then(() => this.message);
}
@@ -72,7 +75,10 @@ class ReactionManager extends BaseManager {
const id = reactionEmoji.id || reactionEmoji.name;
const existing = this.cache.get(id);
if (!this._partial(reactionEmoji)) return existing;
const data = await this.client.api.channels(this.message.channel.id).messages(this.message.id).get();
const data = await this.client.api
.channels(this.message.channel.id)
.messages(this.message.id)
.get();
if (this.message.partial) this.message._patch(data);
if (!data.reactions || !data.reactions.some(r => (r.emoji.id || r.emoji.name) === id)) {
reactionEmoji.reaction._patch({ count: 0 });

View File

@@ -1,8 +1,8 @@
'use strict';
const Collection = require('../util/Collection');
const BaseManager = require('./BaseManager');
const { Error } = require('../errors');
const Collection = require('../util/Collection');
/**
* Manages API methods for users who reacted to a reaction and stores their cache.
@@ -34,9 +34,9 @@ class ReactionUserManager extends BaseManager {
*/
async fetch({ limit = 100, after, before } = {}) {
const message = this.reaction.message;
const data = await this.client.api.channels[message.channel.id].messages[message.id]
.reactions[this.reaction.emoji.identifier]
.get({ query: { limit, before, after } });
const data = await this.client.api.channels[message.channel.id].messages[message.id].reactions[
this.reaction.emoji.identifier
].get({ query: { limit, before, after } });
const users = new Collection();
for (const rawUser of data) {
const user = this.client.users.add(rawUser);
@@ -55,8 +55,9 @@ class ReactionUserManager extends BaseManager {
const message = this.reaction.message;
const userID = message.client.users.resolveID(user);
if (!userID) return Promise.reject(new Error('REACTION_RESOLVE_USER'));
return message.client.api.channels[message.channel.id].messages[message.id]
.reactions[this.reaction.emoji.identifier][userID === message.client.user.id ? '@me' : userID]
return message.client.api.channels[message.channel.id].messages[message.id].reactions[
this.reaction.emoji.identifier
][userID === message.client.user.id ? '@me' : userID]
.delete()
.then(() => this.reaction);
}

View File

@@ -2,8 +2,8 @@
const BaseManager = require('./BaseManager');
const Role = require('../structures/Role');
const { resolveColor } = require('../util/Util');
const Permissions = require('../util/Permissions');
const { resolveColor } = require('../util/Util');
/**
* Manages API methods for roles and stores their cache.
@@ -110,14 +110,17 @@ class RoleManager extends BaseManager {
if (data.color) data.color = resolveColor(data.color);
if (data.permissions) data.permissions = Permissions.resolve(data.permissions);
return this.guild.client.api.guilds(this.guild.id).roles.post({ data, reason }).then(r => {
const { role } = this.client.actions.GuildRoleCreate.handle({
guild_id: this.guild.id,
role: r,
return this.guild.client.api
.guilds(this.guild.id)
.roles.post({ data, reason })
.then(r => {
const { role } = this.client.actions.GuildRoleCreate.handle({
guild_id: this.guild.id,
role: r,
});
if (data.position) return role.setPosition(data.position, reason);
return role;
});
if (data.position) return role.setPosition(data.position, reason);
return role;
});
}
/**
@@ -135,7 +138,7 @@ class RoleManager extends BaseManager {
* @readonly
*/
get highest() {
return this.cache.reduce((prev, role) => role.comparePositionTo(prev) > 0 ? role : prev, this.cache.first());
return this.cache.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this.cache.first());
}
}

View File

@@ -1,9 +1,9 @@
'use strict';
const BaseManager = require('./BaseManager');
const User = require('../structures/User');
const GuildMember = require('../structures/GuildMember');
const Message = require('../structures/Message');
const User = require('../structures/User');
/**
* Manages API methods for users and stores their cache.