From d0523d17acbef15b01825c8c98578a6649f8c33a Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Wed, 17 May 2017 12:51:18 +0200 Subject: [PATCH] merge master (#1) * Fix Permissions now that member is deprecated (#1491) * removing more deprecation leftovers (#1492) * Fix MessageCollectors * Fix awaitMessages (#1493) * Fix MessageCollector#cleanup * Fix MessageCollector#postCheck * Add max option back for safety * Update Invite.js (#1496) * guild setPosition missing docs (#1498) * missing docs * update return docs --- src/structures/Guild.js | 4 +- src/structures/GuildChannel.js | 4 +- src/structures/GuildMember.js | 4 +- src/structures/Invite.js | 45 ++++++++----------- src/structures/MessageCollector.js | 10 ++--- src/structures/interfaces/TextBasedChannel.js | 2 +- 6 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 028e868cf92d..5f1108292f48 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -706,6 +706,8 @@ class Guild { } /** + * Sets the position of the guild in the guild listing. + * This is only available when using a user account. * @param {number} position Absolute or relative position * @param {boolean} [relative=false] Whether to position relatively or absolutely * @returns {Promise} @@ -720,7 +722,7 @@ class Guild { /** * Marks all messages in this guild as read. * This is only available when using a user account. - * @returns {Promise} This guild + * @returns {Promise} */ acknowledge() { return this.client.api.guilds(this.id).ack diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index b21119ded02f..1d5750a3d8a5 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -66,7 +66,7 @@ class GuildChannel extends Channel { permissionsFor(member) { member = this.client.resolver.resolveGuildMember(this.guild, member); if (!member) return null; - if (member.id === this.guild.ownerID) return new Permissions(member, Permissions.ALL); + if (member.id === this.guild.ownerID) return new Permissions(Permissions.ALL); let permissions = 0; @@ -95,7 +95,7 @@ class GuildChannel extends Channel { const admin = Boolean(permissions & Permissions.FLAGS.ADMINISTRATOR); if (admin) permissions = Permissions.ALL; - return new Permissions(member, permissions); + return new Permissions(permissions); } overwritesFor(member, verified = false, roles = null) { diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 6567a39a7624..201a2b7924b8 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -244,13 +244,13 @@ class GuildMember { * @readonly */ get permissions() { - if (this.user.id === this.guild.ownerID) return new Permissions(this, Permissions.ALL); + if (this.user.id === this.guild.ownerID) return new Permissions(Permissions.ALL); let permissions = 0; const roles = this.roles; for (const role of roles.values()) permissions |= role.permissions; - return new Permissions(this, permissions); + return new Permissions(permissions); } /** diff --git a/src/structures/Invite.js b/src/structures/Invite.js index ec01bb7fe5d4..d8df0fff3308 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -2,27 +2,6 @@ const PartialGuild = require('./PartialGuild'); const PartialGuildChannel = require('./PartialGuildChannel'); const Constants = require('../util/Constants'); -/* -{ max_age: 86400, - code: 'CG9A5', - guild: - { splash: null, - id: '123123123', - icon: '123123123', - name: 'name' }, - created_at: '2016-08-28T19:07:04.763368+00:00', - temporary: false, - uses: 0, - max_uses: 0, - inviter: - { username: '123', - discriminator: '4204', - bot: true, - id: '123123123', - avatar: '123123123' }, - channel: { type: 0, id: '123123', name: 'heavy-testing' } } -*/ - /** * Represents an invitation to a guild channel. * The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing. @@ -60,6 +39,24 @@ class Invite { */ this.presenceCount = data.approximate_presence_count; + /** + * The approximate total number of members of the guild this invite is for + * @type {number} + */ + this.memberCount = data.approximate_member_count; + + /** + * The number of text channels the guild this invite goes to has + * @type {number} + */ + this.textChannelCount = data.guild.text_channel_count; + + /** + * The number of voice channels the guild this invite goes to has + * @type {number} + */ + this.voiceChannelCount = data.guild.voice_channel_count; + /** * Whether or not this invite is temporary * @type {boolean} @@ -72,12 +69,6 @@ class Invite { */ this.maxAge = data.max_age; - /** - * The approximate total number of members of the guild this invite is for - * @type {number} - */ - this.memberCount = data.approximate_member_count; - /** * How many times this invite has been used * @type {number} diff --git a/src/structures/MessageCollector.js b/src/structures/MessageCollector.js index 35a741133d24..5bcf9ede0dd2 100644 --- a/src/structures/MessageCollector.js +++ b/src/structures/MessageCollector.js @@ -3,7 +3,7 @@ const Collector = require('./interfaces/Collector'); /** * @typedef {CollectorOptions} MessageCollectorOptions * @property {number} max The maximum amount of messages to process - * @property {number} maxMatches The maximum amount of messages to collect + * @property {number} maxProcessed The maximum amount of messages to collect */ /** @@ -33,8 +33,6 @@ class MessageCollector extends Collector { this.received = 0; this.client.on('message', this.listener); - - this.on('collect', this._reEmitter); } /** @@ -58,9 +56,8 @@ class MessageCollector extends Collector { * @private */ postCheck() { - // Consider changing the end reasons for v12 - if (this.options.maxMatches && this.collected.size >= this.options.max) return 'matchesLimit'; - if (this.options.max && this.received >= this.options.maxProcessed) return 'limit'; + if (this.options.max && this.collected.size >= this.options.max) return 'limit'; + if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit'; return null; } @@ -69,7 +66,6 @@ class MessageCollector extends Collector { * @private */ cleanup() { - this.removeListener('collect', this._reEmitter); this.client.removeListener('message', this.listener); } } diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index ffa9d6ba8989..7c3b64fda651 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -352,7 +352,7 @@ class TextBasedChannel { */ awaitMessages(filter, options = {}) { return new Promise((resolve, reject) => { - const collector = this.createCollector(filter, options); + const collector = this.createMessageCollector(filter, options); collector.once('end', (collection, reason) => { if (options.errors && options.errors.includes(reason)) { reject(collection);