VoiceChannel user limit support

This commit is contained in:
Programmix
2016-05-21 00:43:28 -07:00
committed by abalabahaha
parent d42cbd1c14
commit ab2c9d9a8d
8 changed files with 104 additions and 12 deletions

View File

@@ -983,6 +983,12 @@ export default class Client extends EventEmitter {
.then(dataCallback(callback), errorCallback(callback));
}
// def setChannelUserLimit
setChannelUserLimit(channel, limit, callback = (/*err, {}*/) => { }) {
return this.internal.setChannelUserLimit(channel, limit)
.then(dataCallback(callback), errorCallback(callback));
}
// def updateChannel
updateChannel(channel, data, callback = (/*err, {}*/) => { }) {
return this.internal.updateChannel(channel, data)

View File

@@ -1354,6 +1354,26 @@ export default class InternalClient {
);
}
// def setChannelUserLimit
setChannelUserLimit(channel, limit) {
limit = limit || 0;
if (limit > 99) {
return Promise.reject(new Error("User limit cannot be greater than 99"));
}
return this.resolver.resolveChannel(channel).then((channel) => {
if (channel.type !== "voice") {
return Promise.reject(new Error("Channel must be a voice channel"));
}
return this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
user_limit: limit
})
.then(res => channel.userLimit = limit);
});
}
//def updateChannel
updateChannel(chann, data) {
return this.setChannelNameAndTopic(chann, data.name, data.topic);

View File

@@ -8,9 +8,14 @@ export default class VoiceChannel extends ServerChannel{
constructor(data, client, server){
super(data, client, server);
this.members = data.members || new Cache();
this.userLimit = data.user_limit || 0;
}
join(callback = function () { }) {
return this.client.joinVoiceChannel.apply(this.client, [this, callback]);
}
setUserLimit() {
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
}
}