mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Update channel improvements
Also documented two methods for voice connections. (pause and resume)
This commit is contained in:
@@ -1543,152 +1543,95 @@ var InternalClient = (function () {
|
||||
//def setChannelTopic
|
||||
|
||||
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
|
||||
var _this37 = this;
|
||||
|
||||
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||
|
||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||
if (channel.type !== "text") {
|
||||
return Promise.reject(new Error("Channel must be a text channel"));
|
||||
}
|
||||
topic = topic || "";
|
||||
|
||||
_this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||
name: channel.name,
|
||||
position: channel.position,
|
||||
topic: topic
|
||||
}).then(function (res) {
|
||||
return channel.topic = res.topic;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { topic: topic });
|
||||
};
|
||||
|
||||
//def setChannelName
|
||||
|
||||
InternalClient.prototype.setChannelName = function setChannelName(chann) {
|
||||
var _this38 = this;
|
||||
InternalClient.prototype.setChannelName = function setChannelName(channel, name) {
|
||||
name = name || "unnamed-channel";
|
||||
|
||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { name: name });
|
||||
};
|
||||
|
||||
//def setChannelNameAndTopic
|
||||
|
||||
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) {
|
||||
var _this39 = this;
|
||||
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(channel) {
|
||||
name = name || "unnamed-channel";
|
||||
topic = topic || "";
|
||||
|
||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
||||
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;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { name: name, topic: topic });
|
||||
};
|
||||
|
||||
//def setChannelPosition
|
||||
|
||||
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
|
||||
var _this40 = this;
|
||||
InternalClient.prototype.setChannelPosition = function setChannelPosition(channel, position) {
|
||||
position = position || 0;
|
||||
|
||||
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { position: position });
|
||||
};
|
||||
|
||||
//def setChannelUserLimit
|
||||
|
||||
InternalClient.prototype.setChannelUserLimit = function setChannelUserLimit(channel, limit) {
|
||||
var _this41 = this;
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { userLimit: limit });
|
||||
};
|
||||
|
||||
//def setChannelBitrate
|
||||
|
||||
InternalClient.prototype.setChannelBitrate = function setChannelBitrate(channel, kbitrate) {
|
||||
var _this42 = this;
|
||||
|
||||
kbitrate = kbitrate || 64; // default 64kbps
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
return this.updateChannel(channel, { bitrate: kbitrate });
|
||||
};
|
||||
|
||||
//def updateChannel
|
||||
|
||||
InternalClient.prototype.updateChannel = function updateChannel(chann, data) {
|
||||
return this.setChannelNameAndTopic(chann, data.name, data.topic);
|
||||
InternalClient.prototype.updateChannel = function updateChannel(channel, data) {
|
||||
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
|
||||
@@ -1737,7 +1680,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
InternalClient.prototype.createWS = function createWS(url) {
|
||||
var _this43 = this;
|
||||
var _this38 = this;
|
||||
|
||||
var self = this;
|
||||
var client = self.client;
|
||||
@@ -1771,14 +1714,14 @@ var InternalClient = (function () {
|
||||
this.websocket.onclose = function (code) {
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this43.client.options.autoReconnect);
|
||||
self.disconnected(_this38.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onerror = function (e) {
|
||||
client.emit("error", e);
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this43.client.options.autoReconnect);
|
||||
self.disconnected(_this38.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onmessage = function (e) {
|
||||
@@ -1807,11 +1750,11 @@ var InternalClient = (function () {
|
||||
|
||||
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
||||
|
||||
_this43.forceFetchCount = {};
|
||||
_this43.forceFetchQueue = [];
|
||||
_this43.forceFetchLength = 1;
|
||||
_this43.autoReconnectInterval = 1000;
|
||||
_this43.sessionID = data.session_id;
|
||||
_this38.forceFetchCount = {};
|
||||
_this38.forceFetchQueue = [];
|
||||
_this38.forceFetchLength = 1;
|
||||
_this38.autoReconnectInterval = 1000;
|
||||
_this38.sessionID = data.session_id;
|
||||
|
||||
data.guilds.forEach(function (server) {
|
||||
if (!server.unavailable) {
|
||||
@@ -2254,7 +2197,7 @@ var InternalClient = (function () {
|
||||
data.id = data.id || user.id;
|
||||
data.avatar = data.avatar || user.avatar;
|
||||
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);
|
||||
|
||||
@@ -2396,7 +2339,7 @@ var InternalClient = (function () {
|
||||
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_ADD:
|
||||
if (_this43.user.bot) {
|
||||
if (_this38.user.bot) {
|
||||
return;
|
||||
}
|
||||
if (data.type === 1) {
|
||||
@@ -2427,7 +2370,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_REMOVE:
|
||||
if (_this43.user.bot) {
|
||||
if (_this38.user.bot) {
|
||||
return;
|
||||
}
|
||||
var user = self.friends.get("id", data.id);
|
||||
|
||||
Reference in New Issue
Block a user