mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
VoiceChannel user limit support
This commit is contained in:
@@ -533,6 +533,16 @@ Sets the name and topic of a channel
|
|||||||
- **callback** - `function` taking the following:
|
- **callback** - `function` taking the following:
|
||||||
- **error** - error if any occurred
|
- **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`)
|
startTyping(channel, `callback`)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -17,3 +17,17 @@ members
|
|||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
A Cache_ of Users_ that are connected to the voice channel
|
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_
|
||||||
@@ -969,6 +969,14 @@ var Client = (function (_EventEmitter) {
|
|||||||
return this.internal.setChannelPosition(channel, position).then(dataCallback(callback), errorCallback(callback));
|
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
|
// def updateChannel
|
||||||
|
|
||||||
Client.prototype.updateChannel = function updateChannel(channel, data) {
|
Client.prototype.updateChannel = function updateChannel(channel, data) {
|
||||||
|
|||||||
@@ -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
|
//def updateChannel
|
||||||
|
|
||||||
InternalClient.prototype.updateChannel = function updateChannel(chann, data) {
|
InternalClient.prototype.updateChannel = function updateChannel(chann, data) {
|
||||||
@@ -1666,7 +1690,7 @@ var InternalClient = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
InternalClient.prototype.createWS = function createWS(url) {
|
InternalClient.prototype.createWS = function createWS(url) {
|
||||||
var _this41 = this;
|
var _this42 = this;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var client = self.client;
|
var client = self.client;
|
||||||
@@ -1700,14 +1724,14 @@ var InternalClient = (function () {
|
|||||||
this.websocket.onclose = function (code) {
|
this.websocket.onclose = function (code) {
|
||||||
self.websocket = null;
|
self.websocket = null;
|
||||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||||
self.disconnected(_this41.client.options.autoReconnect);
|
self.disconnected(_this42.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onerror = function (e) {
|
this.websocket.onerror = function (e) {
|
||||||
client.emit("error", e);
|
client.emit("error", e);
|
||||||
self.websocket = null;
|
self.websocket = null;
|
||||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||||
self.disconnected(_this41.client.options.autoReconnect);
|
self.disconnected(_this42.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = function (e) {
|
this.websocket.onmessage = function (e) {
|
||||||
@@ -1736,11 +1760,11 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
||||||
|
|
||||||
_this41.forceFetchCount = {};
|
_this42.forceFetchCount = {};
|
||||||
_this41.forceFetchQueue = [];
|
_this42.forceFetchQueue = [];
|
||||||
_this41.forceFetchLength = 1;
|
_this42.forceFetchLength = 1;
|
||||||
_this41.autoReconnectInterval = 1000;
|
_this42.autoReconnectInterval = 1000;
|
||||||
_this41.sessionID = data.session_id;
|
_this42.sessionID = data.session_id;
|
||||||
|
|
||||||
data.guilds.forEach(function (server) {
|
data.guilds.forEach(function (server) {
|
||||||
if (!server.unavailable) {
|
if (!server.unavailable) {
|
||||||
@@ -2182,7 +2206,7 @@ var InternalClient = (function () {
|
|||||||
data.id = data.id || user.id;
|
data.id = data.id || user.id;
|
||||||
data.avatar = data.avatar || user.avatar;
|
data.avatar = data.avatar || user.avatar;
|
||||||
data.discriminator = data.discriminator || user.discriminator;
|
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);
|
var presenceUser = new _StructuresUser2["default"](data, client);
|
||||||
|
|
||||||
@@ -2324,7 +2348,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case _Constants.PacketType.FRIEND_ADD:
|
case _Constants.PacketType.FRIEND_ADD:
|
||||||
if (_this41.user.bot) {
|
if (_this42.user.bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.type === 1) {
|
if (data.type === 1) {
|
||||||
@@ -2355,7 +2379,7 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _Constants.PacketType.FRIEND_REMOVE:
|
case _Constants.PacketType.FRIEND_REMOVE:
|
||||||
if (_this41.user.bot) {
|
if (_this42.user.bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var user = self.friends.get("id", data.id);
|
var user = self.friends.get("id", data.id);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ var VoiceChannel = (function (_ServerChannel) {
|
|||||||
|
|
||||||
_ServerChannel.call(this, data, client, server);
|
_ServerChannel.call(this, data, client, server);
|
||||||
this.members = data.members || new _UtilCache2["default"]();
|
this.members = data.members || new _UtilCache2["default"]();
|
||||||
|
this.userLimit = data.user_limit || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceChannel.prototype.join = function join() {
|
VoiceChannel.prototype.join = function join() {
|
||||||
@@ -34,6 +35,10 @@ var VoiceChannel = (function (_ServerChannel) {
|
|||||||
return this.client.joinVoiceChannel.apply(this.client, [this, callback]);
|
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;
|
return VoiceChannel;
|
||||||
})(_ServerChannel3["default"]);
|
})(_ServerChannel3["default"]);
|
||||||
|
|
||||||
|
|||||||
@@ -983,6 +983,12 @@ export default class Client extends EventEmitter {
|
|||||||
.then(dataCallback(callback), errorCallback(callback));
|
.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
|
// def updateChannel
|
||||||
updateChannel(channel, data, callback = (/*err, {}*/) => { }) {
|
updateChannel(channel, data, callback = (/*err, {}*/) => { }) {
|
||||||
return this.internal.updateChannel(channel, data)
|
return this.internal.updateChannel(channel, data)
|
||||||
|
|||||||
@@ -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
|
//def updateChannel
|
||||||
updateChannel(chann, data) {
|
updateChannel(chann, data) {
|
||||||
return this.setChannelNameAndTopic(chann, data.name, data.topic);
|
return this.setChannelNameAndTopic(chann, data.name, data.topic);
|
||||||
|
|||||||
@@ -8,9 +8,14 @@ export default class VoiceChannel extends ServerChannel{
|
|||||||
constructor(data, client, server){
|
constructor(data, client, server){
|
||||||
super(data, client, server);
|
super(data, client, server);
|
||||||
this.members = data.members || new Cache();
|
this.members = data.members || new Cache();
|
||||||
|
this.userLimit = data.user_limit || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
join(callback = function () { }) {
|
join(callback = function () { }) {
|
||||||
return this.client.joinVoiceChannel.apply(this.client, [this, callback]);
|
return this.client.joinVoiceChannel.apply(this.client, [this, callback]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setUserLimit() {
|
||||||
|
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user