Skip to content

Commit

Permalink
merge master (#1)
Browse files Browse the repository at this point in the history
* Fix Permissions now that member is deprecated (discordjs#1491)

* removing more deprecation leftovers (discordjs#1492)

* Fix MessageCollectors

* Fix awaitMessages (discordjs#1493)

* Fix MessageCollector#cleanup

* Fix MessageCollector#postCheck

* Add max option back for safety

* Update Invite.js (discordjs#1496)

* guild setPosition missing docs (discordjs#1498)

* missing docs

* update return docs
  • Loading branch information
SpaceEEC authored and devsnek committed May 17, 2017
1 parent 0fc5534 commit 8be1f52
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 40 deletions.
4 changes: 3 additions & 1 deletion src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ class Guild {
}

/**
* Sets the position of the guild in the guild listing.
* <warn>This is only available when using a user account.</warn>
* @param {number} position Absolute or relative position
* @param {boolean} [relative=false] Whether to position relatively or absolutely
* @returns {Promise<Guild>}
Expand All @@ -720,7 +722,7 @@ class Guild {
/**
* Marks all messages in this guild as read.
* <warn>This is only available when using a user account.</warn>
* @returns {Promise<Guild>} This guild
* @returns {Promise<Guild>}
*/
acknowledge() {
return this.client.api.guilds(this.id).ack
Expand Down
4 changes: 2 additions & 2 deletions src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
45 changes: 18 additions & 27 deletions src/structures/Invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <warn>The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing.</warn>
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down
10 changes: 3 additions & 7 deletions src/structures/MessageCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -33,8 +33,6 @@ class MessageCollector extends Collector {
this.received = 0;

this.client.on('message', this.listener);

this.on('collect', this._reEmitter);
}

/**
Expand All @@ -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;
}

Expand All @@ -69,7 +66,6 @@ class MessageCollector extends Collector {
* @private
*/
cleanup() {
this.removeListener('collect', this._reEmitter);
this.client.removeListener('message', this.listener);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/interfaces/TextBasedChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8be1f52

Please sign in to comment.