Several improvements

- Rename Guild#updateChannelPositions -> setChannelPositions
- Allow Guild#setChannelPositions to take ChannelResolvables
- Prioritise ClientDataResolver#resolveChannel's string case
- Minor cleanup
This commit is contained in:
Schuyler Cebulskie
2017-02-25 15:29:32 -05:00
parent 18bcd2f7e2
commit f3a7f59824
7 changed files with 27 additions and 20 deletions

View File

@@ -117,9 +117,9 @@ class ClientDataResolver {
*/
resolveChannel(channel) {
if (channel instanceof Channel) return channel;
if (typeof channel === 'string') return this.client.channels.get(channel) || null;
if (channel instanceof Message) return channel.channel;
if (channel instanceof Guild) return channel.channels.get(channel.id) || null;
if (typeof channel === 'string') return this.client.channels.get(channel) || null;
return null;
}

View File

@@ -8,9 +8,7 @@ class GuildChannelsPositionUpdate extends Action {
if (guild) {
for (const partialChannel of data.channels) {
const channel = guild.roles.get(partialChannel.id);
if (channel) {
channel.position = partialChannel.position;
}
if (channel) channel.position = partialChannel.position;
}
}

View File

@@ -770,7 +770,15 @@ class RESTMethods {
}
updateChannelPositions(guildID, channels) {
return this.rest.makeRequest('patch', Constants.Endpoints.guildChannels(guildID), true, channels).then(() =>
const data = new Array(channels.length);
for (let i = 0; i < channels.length; i++) {
data[i] = {
id: this.client.resolver.resolveChannelID(channels[i].channel),
position: channels[i].position,
};
}
return this.rest.makeRequest('patch', Constants.Endpoints.guildChannels(guildID), true, data).then(() =>
this.client.actions.GuildChannelsPositionUpdate.handle({
guild_id: guildID,
channels,

View File

@@ -55,7 +55,7 @@ class AudioPlayer extends EventEmitter {
* @type {?StreamDispatcher}
*/
get currentDispatcher() {
return (this.streams.last() || {}).dispatcher;
return this.streams.size > 0 ? this.streams.last().dispatcher || null : null;
}
destroy() {