diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 67402dbc3..9960513d4 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -533,6 +533,16 @@ Sets the name and topic of a channel - **callback** - `function` taking the following: - **error** - error if any occurred +setChannelUserLimit(channel, limit, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets the user limit of a voice channel + +- **channel** - A `Channel Resolvable`_ +- **limit** - A `Number`, user limit (0 - 99) +- **callback** - `function` taking the following: + - **error** - error if any occurred + startTyping(channel, `callback`) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/docs_voicechannel.rst b/docs/docs_voicechannel.rst index 3bd478550..0c4c389ae 100644 --- a/docs/docs_voicechannel.rst +++ b/docs/docs_voicechannel.rst @@ -16,4 +16,18 @@ Attributes members ~~~~~~~~ -A Cache_ of Users_ that are connected to the voice channel \ No newline at end of file +A Cache_ of Users_ that are connected to the voice channel + +userLimit +~~~~~~~~ + +The maximum amount of users that can connect to the voice channel. If it's 0, there is no limit + +Functions +--------- + +setUserLimit(limit, `callback`) +~~~~~~~~~~~~~~~~~~~ + +| **Shortcut of** ``client.setChannelUserLimit(channel, limit, callback)`` +| **See** client.setChannelUserLimit_ \ No newline at end of file diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 7ef639f56..803703b40 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -969,6 +969,14 @@ var Client = (function (_EventEmitter) { return this.internal.setChannelPosition(channel, position).then(dataCallback(callback), errorCallback(callback)); }; + // def setChannelUserLimit + + Client.prototype.setChannelUserLimit = function setChannelUserLimit(channel, limit) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function () /*err, {}*/{} : arguments[2]; + + return this.internal.setChannelUserLimit(channel, limit).then(dataCallback(callback), errorCallback(callback)); + }; + // def updateChannel Client.prototype.updateChannel = function updateChannel(channel, data) { diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index adea81e02..490032b4b 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -1614,6 +1614,30 @@ var InternalClient = (function () { }); }; + // def setChannelUserLimit + + InternalClient.prototype.setChannelUserLimit = function setChannelUserLimit(channel, limit) { + var _this41 = this; + + limit = limit || 0; + + if (limit > 99) { + return Promise.reject(new Error("User limit cannot be greater than 99")); + } + + return this.resolver.resolveChannel(channel).then(function (channel) { + if (channel.type !== "voice") { + return Promise.reject(new Error("Channel must be a voice channel")); + } + + return _this41.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { + user_limit: limit + }).then(function (res) { + return channel.userLimit = limit; + }); + }); + }; + //def updateChannel InternalClient.prototype.updateChannel = function updateChannel(chann, data) { @@ -1666,7 +1690,7 @@ var InternalClient = (function () { }; InternalClient.prototype.createWS = function createWS(url) { - var _this41 = this; + var _this42 = this; var self = this; var client = self.client; @@ -1700,14 +1724,14 @@ var InternalClient = (function () { this.websocket.onclose = function (code) { self.websocket = null; self.state = _ConnectionState2["default"].DISCONNECTED; - self.disconnected(_this41.client.options.autoReconnect); + self.disconnected(_this42.client.options.autoReconnect); }; this.websocket.onerror = function (e) { client.emit("error", e); self.websocket = null; self.state = _ConnectionState2["default"].DISCONNECTED; - self.disconnected(_this41.client.options.autoReconnect); + self.disconnected(_this42.client.options.autoReconnect); }; this.websocket.onmessage = function (e) { @@ -1736,11 +1760,11 @@ var InternalClient = (function () { self.user = self.users.add(new _StructuresUser2["default"](data.user, client)); - _this41.forceFetchCount = {}; - _this41.forceFetchQueue = []; - _this41.forceFetchLength = 1; - _this41.autoReconnectInterval = 1000; - _this41.sessionID = data.session_id; + _this42.forceFetchCount = {}; + _this42.forceFetchQueue = []; + _this42.forceFetchLength = 1; + _this42.autoReconnectInterval = 1000; + _this42.sessionID = data.session_id; data.guilds.forEach(function (server) { if (!server.unavailable) { @@ -2182,7 +2206,7 @@ var InternalClient = (function () { data.id = data.id || user.id; data.avatar = data.avatar || user.avatar; data.discriminator = data.discriminator || user.discriminator; - _this41.email = data.email || _this41.email; + _this42.email = data.email || _this42.email; var presenceUser = new _StructuresUser2["default"](data, client); @@ -2324,7 +2348,7 @@ var InternalClient = (function () { break; case _Constants.PacketType.FRIEND_ADD: - if (_this41.user.bot) { + if (_this42.user.bot) { return; } if (data.type === 1) { @@ -2355,7 +2379,7 @@ var InternalClient = (function () { } break; case _Constants.PacketType.FRIEND_REMOVE: - if (_this41.user.bot) { + if (_this42.user.bot) { return; } var user = self.friends.get("id", data.id); diff --git a/lib/Structures/VoiceChannel.js b/lib/Structures/VoiceChannel.js index cbc8ee4f6..23bed8632 100644 --- a/lib/Structures/VoiceChannel.js +++ b/lib/Structures/VoiceChannel.js @@ -26,6 +26,7 @@ var VoiceChannel = (function (_ServerChannel) { _ServerChannel.call(this, data, client, server); this.members = data.members || new _UtilCache2["default"](); + this.userLimit = data.user_limit || 0; } VoiceChannel.prototype.join = function join() { @@ -34,6 +35,10 @@ var VoiceChannel = (function (_ServerChannel) { return this.client.joinVoiceChannel.apply(this.client, [this, callback]); }; + VoiceChannel.prototype.setUserLimit = function setUserLimit() { + return this.client.setChannelUserLimit.apply(this.client, [this, arguments]); + }; + return VoiceChannel; })(_ServerChannel3["default"]); diff --git a/src/Client/Client.js b/src/Client/Client.js index dec9d0a4c..7a763e335 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -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) diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 51af61c98..8efdccbcc 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -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); diff --git a/src/Structures/VoiceChannel.js b/src/Structures/VoiceChannel.js index 09f4bc9fc..2416f164e 100644 --- a/src/Structures/VoiceChannel.js +++ b/src/Structures/VoiceChannel.js @@ -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]); + } }