User limit fix (#359)

* User limit fix

* Better request parameters
This commit is contained in:
Programmix
2016-05-22 22:36:08 -07:00
committed by abalabahaha
parent bea1663052
commit fae03042cb
4 changed files with 81 additions and 33 deletions

View File

@@ -1548,7 +1548,11 @@ var InternalClient = (function () {
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
if (channel.type !== "text") {
return Promise.reject(new Error("Channel must be a text channel"));
}
_this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: channel.position,
topic: topic
@@ -1566,10 +1570,12 @@ var InternalClient = (function () {
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this38.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
_this38.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
topic: channel.topic
topic: channel.topic,
user_limit: channel.userLimit,
bitrate: channel.bitrate
}).then(function (res) {
return channel.name = res.name;
});
@@ -1585,7 +1591,11 @@ var InternalClient = (function () {
var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this39.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
if (channel.type !== "text") {
return Promise.reject(new Error("Channel must be a text channel"));
}
_this39.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
topic: topic
@@ -1596,7 +1606,7 @@ var InternalClient = (function () {
});
};
//def setTopic
//def setChannelPosition
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
var _this40 = this;
@@ -1604,22 +1614,28 @@ var InternalClient = (function () {
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this40.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
_this40.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: position,
topic: channel.topic
topic: channel.topic,
user_limit: channel.userLimit,
bitrate: channel._bitrate
}).then(function (res) {
return channel.position = res.position;
});
});
};
// def setChannelUserLimit
//def setChannelUserLimit
InternalClient.prototype.setChannelUserLimit = function setChannelUserLimit(channel, limit) {
var _this41 = this;
limit = limit || 0;
limit = limit || 0; // default 0 = no limit
if (limit < 0) {
return Promise.reject(new Error("User limit cannot be less than 0"));
}
if (limit > 99) {
return Promise.reject(new Error("User limit cannot be greater than 99"));
@@ -1631,7 +1647,10 @@ var InternalClient = (function () {
}
return _this41.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
user_limit: limit
name: channel.name,
position: channel.position,
user_limit: limit,
bitrate: channel._bitrate
}).then(function (res) {
return channel.userLimit = limit;
});
@@ -1645,18 +1664,23 @@ var InternalClient = (function () {
kbitrate = kbitrate || 64; // default 64kbps
if (kbitrate < 8 || kbitrate > 96) return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
if (kbitrate < 8 || kbitrate > 96) {
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
}
return this.resolver.resolveChannel(channel).then(function (channel) {
if (channel.type !== "voice") return Promise.reject(new Error("Channel must be a voice channel"));
if (channel.type !== "voice") {
return Promise.reject(new Error("Channel must be a voice channel"));
}
return _this42.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
user_limit: channel.userLimit,
position: channel.position,
bitrate: kbitrate * 1000 // in bps
}).then(function () {
return channel.bitrate = kbitrate;
}).then(function (res) {
channel.bitrate = kbitrate;
channel._bitrate = kbitrate * 1000;
});
});
};

View File

@@ -38,7 +38,7 @@ var VoiceChannel = (function (_ServerChannel) {
};
VoiceChannel.prototype.setUserLimit = function setUserLimit() {
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
return this.client.setChannelUserLimit.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
};
VoiceChannel.prototype.setBitrate = function setBitrate() {

View File

@@ -1302,33 +1302,43 @@ export default class InternalClient {
//def setChannelTopic
setChannelTopic(chann, topic = "") {
return this.resolver.resolveChannel(chann)
.then(channel =>
.then(channel => {
if (channel.type !== "text") {
return Promise.reject(new Error("Channel must be a text channel"));
}
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: channel.position,
topic: topic
})
.then(res => channel.topic = res.topic)
);
});
}
//def setChannelName
setChannelName(chann, name = "discordjs_is_the_best") {
return this.resolver.resolveChannel(chann)
.then(channel =>
.then(channel => {
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
topic: channel.topic
topic: channel.topic,
user_limit: channel.userLimit,
bitrate: channel.bitrate
})
.then(res => channel.name = res.name)
);
});
}
//def setChannelNameAndTopic
setChannelNameAndTopic(chann, name = "discordjs_is_the_best", topic = "") {
return this.resolver.resolveChannel(chann)
.then(channel =>
.then(channel => {
if (channel.type !== "text") {
return Promise.reject(new Error("Channel must be a text channel"));
}
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
@@ -1338,25 +1348,31 @@ export default class InternalClient {
channel.name = res.name;
channel.topic = res.topic;
})
);
});
}
//def setTopic
//def setChannelPosition
setChannelPosition(chann, position = 0) {
return this.resolver.resolveChannel(chann)
.then(channel =>
.then(channel => {
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: position,
topic: channel.topic
topic: channel.topic,
user_limit: channel.userLimit,
bitrate: channel._bitrate
})
.then(res => channel.position = res.position)
);
});
}
// def setChannelUserLimit
//def setChannelUserLimit
setChannelUserLimit(channel, limit) {
limit = limit || 0;
limit = limit || 0; // default 0 = no limit
if (limit < 0) {
return Promise.reject(new Error("User limit cannot be less than 0"));
}
if (limit > 99) {
return Promise.reject(new Error("User limit cannot be greater than 99"));
@@ -1368,7 +1384,10 @@ export default class InternalClient {
}
return this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
user_limit: limit
name: channel.name,
position: channel.position,
user_limit: limit,
bitrate: channel._bitrate
})
.then(res => channel.userLimit = limit);
});
@@ -1378,12 +1397,14 @@ export default class InternalClient {
setChannelBitrate(channel, kbitrate) {
kbitrate = kbitrate || 64; // default 64kbps
if (kbitrate < 8 || kbitrate > 96)
if (kbitrate < 8 || kbitrate > 96) {
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
}
return this.resolver.resolveChannel(channel).then(channel => {
if (channel.type !== "voice")
if (channel.type !== "voice") {
return Promise.reject(new Error("Channel must be a voice channel"));
}
return this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
@@ -1391,7 +1412,10 @@ export default class InternalClient {
position: channel.position,
bitrate: kbitrate * 1000 // in bps
})
.then(() => channel.bitrate = kbitrate);
.then(res => {
channel.bitrate = kbitrate;
channel._bitrate = kbitrate * 1000;
});
});
}

View File

@@ -18,7 +18,7 @@ export default class VoiceChannel extends ServerChannel{
}
setUserLimit() {
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
return this.client.setChannelUserLimit.apply(this.client, reg(this, arguments));
}
setBitrate() {