mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
Merge pull request #371 from Programmix/indev
Update channel improvements
This commit is contained in:
@@ -534,7 +534,7 @@ Sets the name and topic of a channel
|
|||||||
- **error** - error if any occurred
|
- **error** - error if any occurred
|
||||||
|
|
||||||
setChannelUserLimit(channel, limit, `callback`)
|
setChannelUserLimit(channel, limit, `callback`)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Sets the user limit of a voice channel
|
Sets the user limit of a voice channel
|
||||||
|
|
||||||
@@ -544,7 +544,7 @@ Sets the user limit of a voice channel
|
|||||||
- **error** - error if any occurred
|
- **error** - error if any occurred
|
||||||
|
|
||||||
setChannelBitrate(channel, bitrate, `callback`)
|
setChannelBitrate(channel, bitrate, `callback`)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Sets the bitrate of a voice channel
|
Sets the bitrate of a voice channel
|
||||||
|
|
||||||
@@ -553,6 +553,21 @@ Sets the bitrate of a voice channel
|
|||||||
- **callback** - `function` taking the following:
|
- **callback** - `function` taking the following:
|
||||||
- **error** - error if any occurred
|
- **error** - error if any occurred
|
||||||
|
|
||||||
|
updateChannel(channel, data, `callback`)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Updates the settings of a channel
|
||||||
|
|
||||||
|
- **channel** - A `Channel Resolvable`_
|
||||||
|
- **details** - `object` containing any of the following:
|
||||||
|
- **name** - `String`, the new name of channel
|
||||||
|
- **topic** - `String`, the new topic of the channel (`TextChannel`_ only)
|
||||||
|
- **position** - `Number`, the new position of the channel
|
||||||
|
- **userLimit** - `Number`, the new user limit of the channel (`VoiceChannel`_ only)
|
||||||
|
- **bitrate** - `Number`, the new bitrate (in kb/s) of the channel (`VoiceChannel`_ only)
|
||||||
|
- **callback** - `function` taking the following:
|
||||||
|
- **error** - error if any occurred
|
||||||
|
|
||||||
startTyping(channel, `callback`)
|
startTyping(channel, `callback`)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -51,3 +51,9 @@ mention()
|
|||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
Returns a `string` that can be used in discord messages to mention a channel. `serverChannel.toString()` defaults to this.
|
Returns a `string` that can be used in discord messages to mention a channel. `serverChannel.toString()` defaults to this.
|
||||||
|
|
||||||
|
update(data, `callback`)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
| **Shortcut of** ``client.updateChannel(channel, data, callback)``
|
||||||
|
| **See** client.updateChannel_
|
||||||
|
|||||||
@@ -120,6 +120,16 @@ getVolume()
|
|||||||
|
|
||||||
Returns the current volume. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
|
Returns the current volume. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
|
||||||
|
|
||||||
|
pause()
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
Pauses the current connection's audio.
|
||||||
|
|
||||||
|
resume()
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Resumes the current connection's audio.
|
||||||
|
|
||||||
stopPlaying()
|
stopPlaying()
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -1543,152 +1543,95 @@ var InternalClient = (function () {
|
|||||||
//def setChannelTopic
|
//def setChannelTopic
|
||||||
|
|
||||||
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
|
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
|
||||||
var _this37 = this;
|
|
||||||
|
|
||||||
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
topic = topic || "";
|
||||||
if (channel.type !== "text") {
|
|
||||||
return Promise.reject(new Error("Channel must be a text channel"));
|
|
||||||
}
|
|
||||||
|
|
||||||
_this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
return this.updateChannel(channel, { topic: topic });
|
||||||
name: channel.name,
|
|
||||||
position: channel.position,
|
|
||||||
topic: topic
|
|
||||||
}).then(function (res) {
|
|
||||||
return channel.topic = res.topic;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//def setChannelName
|
//def setChannelName
|
||||||
|
|
||||||
InternalClient.prototype.setChannelName = function setChannelName(chann) {
|
InternalClient.prototype.setChannelName = function setChannelName(channel, name) {
|
||||||
var _this38 = this;
|
name = name || "unnamed-channel";
|
||||||
|
|
||||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
return this.updateChannel(channel, { name: name });
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
|
||||||
_this38.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
|
||||||
name: name,
|
|
||||||
position: channel.position,
|
|
||||||
topic: channel.topic,
|
|
||||||
user_limit: channel.userLimit,
|
|
||||||
bitrate: channel.bitrate
|
|
||||||
}).then(function (res) {
|
|
||||||
return channel.name = res.name;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//def setChannelNameAndTopic
|
//def setChannelNameAndTopic
|
||||||
|
|
||||||
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) {
|
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(channel) {
|
||||||
var _this39 = this;
|
name = name || "unnamed-channel";
|
||||||
|
topic = topic || "";
|
||||||
|
|
||||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
return this.updateChannel(channel, { name: name, topic: topic });
|
||||||
var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
|
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
|
||||||
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
|
|
||||||
}).then(function (res) {
|
|
||||||
channel.name = res.name;
|
|
||||||
channel.topic = res.topic;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//def setChannelPosition
|
//def setChannelPosition
|
||||||
|
|
||||||
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
|
InternalClient.prototype.setChannelPosition = function setChannelPosition(channel, position) {
|
||||||
var _this40 = this;
|
position = position || 0;
|
||||||
|
|
||||||
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
return this.updateChannel(channel, { position: position });
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
|
||||||
_this40.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
|
||||||
name: channel.name,
|
|
||||||
position: position,
|
|
||||||
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) {
|
InternalClient.prototype.setChannelUserLimit = function setChannelUserLimit(channel, limit) {
|
||||||
var _this41 = this;
|
|
||||||
|
|
||||||
limit = limit || 0; // default 0 = no limit
|
limit = limit || 0; // default 0 = no limit
|
||||||
|
|
||||||
if (limit < 0) {
|
return this.updateChannel(channel, { userLimit: limit });
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
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, {
|
|
||||||
name: channel.name,
|
|
||||||
position: channel.position,
|
|
||||||
user_limit: limit,
|
|
||||||
bitrate: channel._bitrate
|
|
||||||
}).then(function (res) {
|
|
||||||
return channel.userLimit = limit;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//def setChannelBitrate
|
//def setChannelBitrate
|
||||||
|
|
||||||
InternalClient.prototype.setChannelBitrate = function setChannelBitrate(channel, kbitrate) {
|
InternalClient.prototype.setChannelBitrate = function setChannelBitrate(channel, kbitrate) {
|
||||||
var _this42 = this;
|
|
||||||
|
|
||||||
kbitrate = kbitrate || 64; // default 64kbps
|
kbitrate = kbitrate || 64; // default 64kbps
|
||||||
|
|
||||||
if (kbitrate < 8 || kbitrate > 96) {
|
return this.updateChannel(channel, { bitrate: kbitrate });
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (res) {
|
|
||||||
channel.bitrate = kbitrate;
|
|
||||||
channel._bitrate = kbitrate * 1000;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//def updateChannel
|
//def updateChannel
|
||||||
|
|
||||||
InternalClient.prototype.updateChannel = function updateChannel(chann, data) {
|
InternalClient.prototype.updateChannel = function updateChannel(channel, data) {
|
||||||
return this.setChannelNameAndTopic(chann, data.name, data.topic);
|
var _this37 = this;
|
||||||
|
|
||||||
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
|
if (!channel) {
|
||||||
|
return Promise.reject(new Error("Failed to resolve channel"));
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
name: data.name || channel.name,
|
||||||
|
topic: data.topic || channel.topic,
|
||||||
|
position: data.position || channel.position,
|
||||||
|
user_limit: data.userLimit || channel.userLimit,
|
||||||
|
bitrate: data.bitrate || channel.bitrate
|
||||||
|
};
|
||||||
|
|
||||||
|
if (data.position < 0) {
|
||||||
|
return Promise.reject(new Error("Position cannot be less than 0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.user_limit < 0 || data.user_limit > 99) {
|
||||||
|
return Promise.reject(new Error("User limit must be between 0-99"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.kbitrate < 8 || data.kbitrate > 96) {
|
||||||
|
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
|
||||||
|
}
|
||||||
|
|
||||||
|
data.bitrate *= 1000; // convert to bits before sending
|
||||||
|
|
||||||
|
return _this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, data).then(function (res) {
|
||||||
|
channel.name = data.name;
|
||||||
|
channel.topic = data.topic;
|
||||||
|
channel.position = data.position;
|
||||||
|
channel.userLimit = data.user_limit;
|
||||||
|
channel.bitrate = Math.ceil(data.bitrate / 1000);
|
||||||
|
channel._bitrate = data.bitrate;
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//def addFriend
|
//def addFriend
|
||||||
@@ -1737,7 +1680,7 @@ var InternalClient = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
InternalClient.prototype.createWS = function createWS(url) {
|
InternalClient.prototype.createWS = function createWS(url) {
|
||||||
var _this43 = this;
|
var _this38 = this;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var client = self.client;
|
var client = self.client;
|
||||||
@@ -1771,14 +1714,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(_this43.client.options.autoReconnect);
|
self.disconnected(_this38.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(_this43.client.options.autoReconnect);
|
self.disconnected(_this38.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = function (e) {
|
this.websocket.onmessage = function (e) {
|
||||||
@@ -1807,11 +1750,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));
|
||||||
|
|
||||||
_this43.forceFetchCount = {};
|
_this38.forceFetchCount = {};
|
||||||
_this43.forceFetchQueue = [];
|
_this38.forceFetchQueue = [];
|
||||||
_this43.forceFetchLength = 1;
|
_this38.forceFetchLength = 1;
|
||||||
_this43.autoReconnectInterval = 1000;
|
_this38.autoReconnectInterval = 1000;
|
||||||
_this43.sessionID = data.session_id;
|
_this38.sessionID = data.session_id;
|
||||||
|
|
||||||
data.guilds.forEach(function (server) {
|
data.guilds.forEach(function (server) {
|
||||||
if (!server.unavailable) {
|
if (!server.unavailable) {
|
||||||
@@ -2254,7 +2197,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;
|
||||||
_this43.email = data.email || _this43.email;
|
_this38.email = data.email || _this38.email;
|
||||||
|
|
||||||
var presenceUser = new _StructuresUser2["default"](data, client);
|
var presenceUser = new _StructuresUser2["default"](data, client);
|
||||||
|
|
||||||
@@ -2396,7 +2339,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case _Constants.PacketType.FRIEND_ADD:
|
case _Constants.PacketType.FRIEND_ADD:
|
||||||
if (_this43.user.bot) {
|
if (_this38.user.bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.type === 1) {
|
if (data.type === 1) {
|
||||||
@@ -2427,7 +2370,7 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _Constants.PacketType.FRIEND_REMOVE:
|
case _Constants.PacketType.FRIEND_REMOVE:
|
||||||
if (_this43.user.bot) {
|
if (_this38.user.bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var user = self.friends.get("id", data.id);
|
var user = self.friends.get("id", data.id);
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ var ServerChannel = (function (_Channel) {
|
|||||||
return this.client.setChannelPosition.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
return this.client.setChannelPosition.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ServerChannel.prototype.update = function update() {
|
||||||
|
return this.client.updateChannel.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
return ServerChannel;
|
return ServerChannel;
|
||||||
})(_Channel3["default"]);
|
})(_Channel3["default"]);
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ var TextChannel = (function (_ServerChannel) {
|
|||||||
return this.client.setChannelNameAndTopic.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
return this.client.setChannelNameAndTopic.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||||
};
|
};
|
||||||
|
|
||||||
TextChannel.prototype.update = function update() {
|
|
||||||
return this.client.updateChannel.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
|
||||||
};
|
|
||||||
|
|
||||||
TextChannel.prototype.sendMessage = function sendMessage() {
|
TextChannel.prototype.sendMessage = function sendMessage() {
|
||||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1301,127 +1301,87 @@ export default class InternalClient {
|
|||||||
|
|
||||||
//def setChannelTopic
|
//def setChannelTopic
|
||||||
setChannelTopic(chann, topic = "") {
|
setChannelTopic(chann, topic = "") {
|
||||||
return this.resolver.resolveChannel(chann)
|
topic = topic || "";
|
||||||
.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, {
|
return this.updateChannel(channel, {topic: topic});
|
||||||
name: channel.name,
|
|
||||||
position: channel.position,
|
|
||||||
topic: topic
|
|
||||||
})
|
|
||||||
.then(res => channel.topic = res.topic)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def setChannelName
|
//def setChannelName
|
||||||
setChannelName(chann, name = "discordjs_is_the_best") {
|
setChannelName(channel, name) {
|
||||||
return this.resolver.resolveChannel(chann)
|
name = name || "unnamed-channel";
|
||||||
.then(channel => {
|
|
||||||
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
|
return this.updateChannel(channel, {name: name});
|
||||||
name: name,
|
|
||||||
position: channel.position,
|
|
||||||
topic: channel.topic,
|
|
||||||
user_limit: channel.userLimit,
|
|
||||||
bitrate: channel.bitrate
|
|
||||||
})
|
|
||||||
.then(res => channel.name = res.name)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def setChannelNameAndTopic
|
//def setChannelNameAndTopic
|
||||||
setChannelNameAndTopic(chann, name = "discordjs_is_the_best", topic = "") {
|
setChannelNameAndTopic(channel) {
|
||||||
return this.resolver.resolveChannel(chann)
|
name = name || "unnamed-channel";
|
||||||
.then(channel => {
|
topic = topic || "";
|
||||||
if (channel.type !== "text") {
|
|
||||||
return Promise.reject(new Error("Channel must be a text channel"));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
|
return this.updateChannel(channel, {name: name, topic: topic});
|
||||||
name: name,
|
|
||||||
position: channel.position,
|
|
||||||
topic: topic
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
channel.name = res.name;
|
|
||||||
channel.topic = res.topic;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def setChannelPosition
|
//def setChannelPosition
|
||||||
setChannelPosition(chann, position = 0) {
|
setChannelPosition(channel, position) {
|
||||||
return this.resolver.resolveChannel(chann)
|
position = position || 0;
|
||||||
.then(channel => {
|
|
||||||
this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
|
return this.updateChannel(channel, {position: position});
|
||||||
name: channel.name,
|
|
||||||
position: position,
|
|
||||||
topic: channel.topic,
|
|
||||||
user_limit: channel.userLimit,
|
|
||||||
bitrate: channel._bitrate
|
|
||||||
})
|
|
||||||
.then(res => channel.position = res.position)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def setChannelUserLimit
|
//def setChannelUserLimit
|
||||||
setChannelUserLimit(channel, limit) {
|
setChannelUserLimit(channel, limit) {
|
||||||
limit = limit || 0; // default 0 = no limit
|
limit = limit || 0; // default 0 = no limit
|
||||||
|
|
||||||
if (limit < 0) {
|
return this.updateChannel(channel, {userLimit: limit})
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
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, {
|
|
||||||
name: channel.name,
|
|
||||||
position: channel.position,
|
|
||||||
user_limit: limit,
|
|
||||||
bitrate: channel._bitrate
|
|
||||||
})
|
|
||||||
.then(res => channel.userLimit = limit);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def setChannelBitrate
|
//def setChannelBitrate
|
||||||
setChannelBitrate(channel, kbitrate) {
|
setChannelBitrate(channel, kbitrate) {
|
||||||
kbitrate = kbitrate || 64; // default 64kbps
|
kbitrate = kbitrate || 64; // default 64kbps
|
||||||
|
|
||||||
if (kbitrate < 8 || kbitrate > 96) {
|
return this.updateChannel(channel, {bitrate: kbitrate});
|
||||||
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
|
|
||||||
}
|
|
||||||
|
|
||||||
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, {
|
|
||||||
name: channel.name,
|
|
||||||
user_limit: channel.userLimit,
|
|
||||||
position: channel.position,
|
|
||||||
bitrate: kbitrate * 1000 // in bps
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
channel.bitrate = kbitrate;
|
|
||||||
channel._bitrate = kbitrate * 1000;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def updateChannel
|
//def updateChannel
|
||||||
updateChannel(chann, data) {
|
updateChannel(channel, data) {
|
||||||
return this.setChannelNameAndTopic(chann, data.name, data.topic);
|
return this.resolver.resolveChannel(channel).then(channel => {
|
||||||
|
if (!channel) {
|
||||||
|
return Promise.reject(new Error("Failed to resolve channel"));
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
name: data.name || channel.name,
|
||||||
|
topic: data.topic || channel.topic,
|
||||||
|
position: (data.position ? data.position : channel.position),
|
||||||
|
user_limit: (data.userLimit ? data.userLimit : channel.userLimit),
|
||||||
|
bitrate: (data.bitrate ? data.bitrate : channel.bitrate)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.position < 0) {
|
||||||
|
return Promise.reject(new Error("Position cannot be less than 0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.user_limit < 0 || data.user_limit > 99) {
|
||||||
|
return Promise.reject(new Error("User limit must be between 0-99"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.kbitrate < 8 || data.kbitrate > 96) {
|
||||||
|
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data.bitrate *= 1000; // convert to bits before sending
|
||||||
|
|
||||||
|
return this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, data)
|
||||||
|
.then(res => {
|
||||||
|
channel.name = data.name;
|
||||||
|
channel.topic = data.topic;
|
||||||
|
channel.position = data.position;
|
||||||
|
channel.userLimit = data.user_limit;
|
||||||
|
channel.bitrate = Math.ceil(data.bitrate / 1000);
|
||||||
|
channel._bitrate = data.bitrate;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//def addFriend
|
//def addFriend
|
||||||
|
|||||||
@@ -82,4 +82,8 @@ export default class ServerChannel extends Channel{
|
|||||||
setPosition(){
|
setPosition(){
|
||||||
return this.client.setChannelPosition.apply(this.client, reg(this, arguments));
|
return this.client.setChannelPosition.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(){
|
||||||
|
return this.client.updateChannel.apply(this.client, reg(this, arguments));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,11 @@ export default class TextChannel extends ServerChannel{
|
|||||||
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
|
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
update(){
|
|
||||||
return this.client.updateChannel.apply(this.client, reg(this, arguments));
|
|
||||||
}
|
|
||||||
|
|
||||||
sendMessage(){
|
sendMessage(){
|
||||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
send() {
|
send(){
|
||||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,23 +38,23 @@ export default class TextChannel extends ServerChannel{
|
|||||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTTS() {
|
sendTTS(){
|
||||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
sendFile() {
|
sendFile(){
|
||||||
return this.client.sendFile.apply(this.client, reg(this, arguments));
|
return this.client.sendFile.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogs() {
|
getLogs(){
|
||||||
return this.client.getChannelLogs.apply(this.client, reg(this, arguments));
|
return this.client.getChannelLogs.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
startTyping() {
|
startTyping(){
|
||||||
return this.client.startTyping.apply(this.client, reg(this, arguments));
|
return this.client.startTyping.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
stopTyping() {
|
stopTyping(){
|
||||||
return this.client.stopTyping.apply(this.client, reg(this, arguments));
|
return this.client.stopTyping.apply(this.client, reg(this, arguments));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user