From 042d7d1dbe7e50bf873dd221500b1f2eaafebf72 Mon Sep 17 00:00:00 2001 From: meew0 Date: Sun, 24 Jan 2016 23:22:24 +0100 Subject: [PATCH 1/6] Add voice channel moving, not quite working yet --- lib/Client/Client.js | 8 ++++++++ lib/Client/InternalClient.js | 19 +++++++++++++++++++ src/Client/Client.js | 6 ++++++ src/Client/InternalClient.js | 19 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 46672b55b..c3c395c8a 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -314,6 +314,14 @@ var Client = (function (_EventEmitter) { return this.internal.kickMember(user, server).then(dataCallback(callback), errorCallback(callback)); }; + // def moveMember + + Client.prototype.moveMember = function moveMember(user, server, channel) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, {}*/{} : arguments[3]; + + return this.internal.moveMember(user, server, channel).then(dataCallback(callback), errorCallback(callback)); + }; + // def createRole Client.prototype.createRole = function createRole(server) { diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 1d82f8066..bf6db93d7 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -694,6 +694,25 @@ var InternalClient = (function () { return this.apiRequest("del", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true); }; + // def moveMember + + InternalClient.prototype.moveMember = function moveMember(user, server, channel) { + user = this.resolver.resolveUser(user); + server = this.resolver.resolveServer(server); + channel = this.resolver.resolveChannel(channel); + + console.log(channel.type); + // Make sure `channel` is a voice channel + if (channel.type !== "voice") { + throw new Error("Can't moveMember into a non-voice channel"); + } else { + return this.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) { + user.voiceChannel = channel; + return res; + }); + } + }; + // def createRole InternalClient.prototype.createRole = function createRole(server, data) { diff --git a/src/Client/Client.js b/src/Client/Client.js index cbc4945dc..82a32d5f9 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -273,6 +273,12 @@ export default class Client extends EventEmitter { .then(dataCallback(callback), errorCallback(callback)); } + // def moveMember + moveMember(user, server, channel, callback = (/*err, {}*/) => { }) { + return this.internal.moveMember(user, server, channel) + .then(dataCallback(callback), errorCallback(callback)); + } + // def createRole createRole(server, data = null, callback = (/*err, role*/) => { }) { if (typeof data === "function") { diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 89f378fe3..350d15004 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -572,6 +572,25 @@ export default class InternalClient { return this.apiRequest("del", `${Endpoints.SERVER_MEMBERS(server.id) }/${user.id}`, true); } + // def moveMember + moveMember(user, server, channel) { + user = this.resolver.resolveUser(user); + server = this.resolver.resolveServer(server); + channel = this.resolver.resolveChannel(channel); + + console.log(channel.type); + // Make sure `channel` is a voice channel + if(channel.type !== "voice") { + throw new Error("Can't moveMember into a non-voice channel"); + } else { + return this.apiRequest("patch", `${Endpoints.SERVER_MEMBERS(server.id)}/${user.id}`, true, { channel_id: channel.id }) + .then(res => { + user.voiceChannel = channel; + return res; + }); + } + } + // def createRole createRole(server, data) { server = this.resolver.resolveServer(server); From 59060b27e6200f9818f7bd687cee9aba39bc3990 Mon Sep 17 00:00:00 2001 From: meew0 Date: Fri, 29 Jan 2016 22:44:29 +0100 Subject: [PATCH 2/6] Handle resolveChannel correctly because it returns a promise --- src/Client/InternalClient.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 350d15004..741fdd251 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -576,19 +576,21 @@ export default class InternalClient { moveMember(user, server, channel) { user = this.resolver.resolveUser(user); server = this.resolver.resolveServer(server); - channel = this.resolver.resolveChannel(channel); - - console.log(channel.type); - // Make sure `channel` is a voice channel - if(channel.type !== "voice") { - throw new Error("Can't moveMember into a non-voice channel"); - } else { - return this.apiRequest("patch", `${Endpoints.SERVER_MEMBERS(server.id)}/${user.id}`, true, { channel_id: channel.id }) - .then(res => { - user.voiceChannel = channel; - return res; - }); - } + return this.resolver.resolveChannel(channel).then(channel => { + console.log(channel.id); + console.log(channel.name); + console.log(channel.type); + // Make sure `channel` is a voice channel + if(channel.type !== "voice") { + throw new Error("Can't moveMember into a non-voice channel"); + } else { + return this.apiRequest("patch", `${Endpoints.SERVER_MEMBERS(server.id)}/${user.id}`, true, { channel_id: channel.id }) + .then(res => { + user.voiceChannel = channel; + return res; + }); + } + }); } // def createRole From 9cfcb3452ba3966117d071c2cde3ae9db0615858 Mon Sep 17 00:00:00 2001 From: meew0 Date: Fri, 29 Jan 2016 22:44:36 +0100 Subject: [PATCH 3/6] Remove debug calls --- src/Client/InternalClient.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 741fdd251..e3e18110a 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -577,9 +577,6 @@ export default class InternalClient { user = this.resolver.resolveUser(user); server = this.resolver.resolveServer(server); return this.resolver.resolveChannel(channel).then(channel => { - console.log(channel.id); - console.log(channel.name); - console.log(channel.type); // Make sure `channel` is a voice channel if(channel.type !== "voice") { throw new Error("Can't moveMember into a non-voice channel"); From c93ed88daf173d91a605fbd18ae931d7441a69e5 Mon Sep 17 00:00:00 2001 From: meew0 Date: Fri, 29 Jan 2016 22:46:42 +0100 Subject: [PATCH 4/6] Rebuild for voice moving --- lib/Client/InternalClient.js | 101 ++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index bf6db93d7..4e0762ff8 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -697,34 +697,35 @@ var InternalClient = (function () { // def moveMember InternalClient.prototype.moveMember = function moveMember(user, server, channel) { + var _this19 = this; + user = this.resolver.resolveUser(user); server = this.resolver.resolveServer(server); - channel = this.resolver.resolveChannel(channel); - - console.log(channel.type); - // Make sure `channel` is a voice channel - if (channel.type !== "voice") { - throw new Error("Can't moveMember into a non-voice channel"); - } else { - return this.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) { - user.voiceChannel = channel; - return res; - }); - } + return this.resolver.resolveChannel(channel).then(function (channel) { + // Make sure `channel` is a voice channel + if (channel.type !== "voice") { + throw new Error("Can't moveMember into a non-voice channel"); + } else { + return _this19.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) { + user.voiceChannel = channel; + return res; + }); + } + }); }; // def createRole InternalClient.prototype.createRole = function createRole(server, data) { - var _this19 = this; + var _this20 = this; server = this.resolver.resolveServer(server); return this.apiRequest("post", _Constants.Endpoints.SERVER_ROLES(server.id), true).then(function (res) { - var role = server.roles.add(new _StructuresRole2["default"](res, server, _this19.client)); + var role = server.roles.add(new _StructuresRole2["default"](res, server, _this20.client)); if (data) { - return _this19.updateRole(role, data); + return _this20.updateRole(role, data); } return role; }); @@ -733,7 +734,7 @@ var InternalClient = (function () { // def updateRole InternalClient.prototype.updateRole = function updateRole(role, data) { - var _this20 = this; + var _this21 = this; var server = this.resolver.resolveServer(role.server); @@ -769,7 +770,7 @@ var InternalClient = (function () { } return this.apiRequest("patch", _Constants.Endpoints.SERVER_ROLES(server.id) + "/" + role.id, true, newData).then(function (res) { - return server.roles.update(role, new _StructuresRole2["default"](res, server, _this20.client)); + return server.roles.update(role, new _StructuresRole2["default"](res, server, _this21.client)); }); }; @@ -914,7 +915,7 @@ var InternalClient = (function () { // def createInvite InternalClient.prototype.createInvite = function createInvite(chanServ, options) { - var _this21 = this; + var _this22 = this; if (chanServ instanceof _StructuresChannel2["default"]) { // do something @@ -947,7 +948,7 @@ var InternalClient = (function () { } return this.apiRequest("post", epoint, true, options).then(function (res) { - return new _StructuresInvite2["default"](res, _this21.channels.get("id", res.channel.id), _this21.client); + return new _StructuresInvite2["default"](res, _this22.channels.get("id", res.channel.id), _this22.client); }); }; @@ -964,7 +965,7 @@ var InternalClient = (function () { //def getInvite InternalClient.prototype.getInvite = function getInvite(invite) { - var _this22 = this; + var _this23 = this; invite = this.resolver.resolveInviteID(invite); if (!invite) { @@ -972,11 +973,11 @@ var InternalClient = (function () { } return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) { - if (!_this22.channels.has("id", res.channel.id)) { - return new _StructuresInvite2["default"](res, null, _this22.client); + if (!_this23.channels.has("id", res.channel.id)) { + return new _StructuresInvite2["default"](res, null, _this23.client); } - return _this22.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) { - return new _StructuresInvite2["default"](res2, _this22.channels.get("id", res.channel.id), _this22.client); + return _this23.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) { + return new _StructuresInvite2["default"](res2, _this23.channels.get("id", res.channel.id), _this23.client); }); }); }; @@ -984,22 +985,22 @@ var InternalClient = (function () { //def getInvites InternalClient.prototype.getInvites = function getInvites(channel) { - var _this23 = this; + var _this24 = this; if (!(channel instanceof _StructuresChannel2["default"])) { var server = this.resolver.resolveServer(channel); if (server) { return this.apiRequest("get", _Constants.Endpoints.SERVER_INVITES(server.id), true).then(function (res) { return res.map(function (data) { - return new _StructuresInvite2["default"](data, _this23.channels.get("id", data.channel.id), _this23.client); + return new _StructuresInvite2["default"](data, _this24.channels.get("id", data.channel.id), _this24.client); }); }); } } return this.resolver.resolveChannel(channel).then(function (channel) { - return _this23.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) { + return _this24.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) { return res.map(function (data) { - return new _StructuresInvite2["default"](data, _this23.channels.get("id", data.channel.id), _this23.client); + return new _StructuresInvite2["default"](data, _this24.channels.get("id", data.channel.id), _this24.client); }); }); }); @@ -1008,7 +1009,7 @@ var InternalClient = (function () { //def overwritePermissions InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) { - var _this24 = this; + var _this25 = this; return this.resolver.resolveChannel(channel).then(function (channel) { var user; @@ -1049,7 +1050,7 @@ var InternalClient = (function () { } } - return _this24.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data); + return _this25.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data); }); }; @@ -1085,49 +1086,49 @@ var InternalClient = (function () { //def sendTyping InternalClient.prototype.sendTyping = function sendTyping(channel) { - var _this25 = this; + var _this26 = this; return this.resolver.resolveChannel(channel).then(function (channel) { - return _this25.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true); + return _this26.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true); }); }; //def startTyping InternalClient.prototype.startTyping = function startTyping(channel) { - var _this26 = this; + var _this27 = this; return this.resolver.resolveChannel(channel).then(function (channel) { - if (_this26.intervals.typing[channel.id]) { + if (_this27.intervals.typing[channel.id]) { // typing interval already exists, leave it alone throw new Error("Already typing in that channel"); } - _this26.intervals.typing[channel.id] = setInterval(function () { - return _this26.sendTyping(channel)["catch"](function (error) { - return _this26.emit("error", error); + _this27.intervals.typing[channel.id] = setInterval(function () { + return _this27.sendTyping(channel)["catch"](function (error) { + return _this27.emit("error", error); }); }, 4000); - return _this26.sendTyping(channel); + return _this27.sendTyping(channel); }); }; //def stopTyping InternalClient.prototype.stopTyping = function stopTyping(channel) { - var _this27 = this; + var _this28 = this; return this.resolver.resolveChannel(channel).then(function (channel) { - if (!_this27.intervals.typing[channel.id]) { + if (!_this28.intervals.typing[channel.id]) { // typing interval doesn"t exist throw new Error("Not typing in that channel"); } - clearInterval(_this27.intervals.typing[channel.id]); - _this27.intervals.typing[channel.id] = false; + clearInterval(_this28.intervals.typing[channel.id]); + _this28.intervals.typing[channel.id] = false; }); }; @@ -1158,12 +1159,12 @@ var InternalClient = (function () { //def setChannelTopic InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) { - var _this28 = this; + var _this29 = this; var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1]; return this.resolver.resolveChannel(chann).then(function (channel) { - return _this28.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { + return _this29.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { name: channel.name, position: channel.position, topic: topic @@ -1176,12 +1177,12 @@ var InternalClient = (function () { //def setChannelName InternalClient.prototype.setChannelName = function setChannelName(chann) { - var _this29 = this; + var _this30 = this; var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1]; return this.resolver.resolveChannel(chann).then(function (channel) { - return _this29.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { + return _this30.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { name: name, position: channel.position, topic: channel.topic @@ -1194,13 +1195,13 @@ var InternalClient = (function () { //def setChannelNameAndTopic InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) { - var _this30 = this; + var _this31 = this; 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) { - return _this30.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { + return _this31.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { name: name, position: channel.position, topic: topic @@ -1214,12 +1215,12 @@ var InternalClient = (function () { //def setTopic InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) { - var _this31 = this; + var _this32 = this; var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; return this.resolver.resolveChannel(chann).then(function (channel) { - return _this31.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { + return _this32.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, { name: channel.name, position: position, topic: channel.topic From 9fab8ed381b2808714a65560830baeb0adcbc08f Mon Sep 17 00:00:00 2001 From: meew0 Date: Fri, 29 Jan 2016 22:48:52 +0100 Subject: [PATCH 5/6] Documentation --- docs/docs_client.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index d4f1fa1d4..46673609a 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -276,6 +276,17 @@ Removes a user from a server - **callback** - `function` taking the following: - **error** - error if any occurred. +moveMember(user, server, channel, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Moves a user from one voice channel into another. + +- **user** - A `User Resolvable`_ that should be moved +- **server** - A `Server Resolvable`_ in which to move the user +- **channel** - The `Channel Resolvable`_ to move the user to +- **callback** - `function` taking the following: + - **error** - error if any occurred. + createInvite(channel, `options`, `callback`) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -669,4 +680,4 @@ Emitted when a user joins a voice channel, supplies a User_ and a VoiceChannel_ voiceLeave ~~~~~~~~~~ -Emitted when a user leaves a voice channel, supplies a User_ and a VoiceChannel_ \ No newline at end of file +Emitted when a user leaves a voice channel, supplies a User_ and a VoiceChannel_ From fe9911acc2ea85c90a6c329a8938062ceb61b40f Mon Sep 17 00:00:00 2001 From: meew0 Date: Fri, 29 Jan 2016 23:03:12 +0100 Subject: [PATCH 6/6] Don't require a server for moveMember --- docs/docs_client.rst | 3 +-- lib/Client/Client.js | 6 +++--- lib/Client/InternalClient.js | 5 +++-- src/Client/Client.js | 4 ++-- src/Client/InternalClient.js | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 46673609a..436cefc54 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -276,13 +276,12 @@ Removes a user from a server - **callback** - `function` taking the following: - **error** - error if any occurred. -moveMember(user, server, channel, `callback`) +moveMember(user, channel, `callback`) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Moves a user from one voice channel into another. - **user** - A `User Resolvable`_ that should be moved -- **server** - A `Server Resolvable`_ in which to move the user - **channel** - The `Channel Resolvable`_ to move the user to - **callback** - `function` taking the following: - **error** - error if any occurred. diff --git a/lib/Client/Client.js b/lib/Client/Client.js index c3c395c8a..16a701197 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -316,10 +316,10 @@ var Client = (function (_EventEmitter) { // def moveMember - Client.prototype.moveMember = function moveMember(user, server, channel) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, {}*/{} : arguments[3]; + Client.prototype.moveMember = function moveMember(user, channel) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function () /*err, {}*/{} : arguments[2]; - return this.internal.moveMember(user, server, channel).then(dataCallback(callback), errorCallback(callback)); + return this.internal.moveMember(user, channel).then(dataCallback(callback), errorCallback(callback)); }; // def createRole diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 4e0762ff8..89ffc099c 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -696,12 +696,13 @@ var InternalClient = (function () { // def moveMember - InternalClient.prototype.moveMember = function moveMember(user, server, channel) { + InternalClient.prototype.moveMember = function moveMember(user, channel) { var _this19 = this; user = this.resolver.resolveUser(user); - server = this.resolver.resolveServer(server); return this.resolver.resolveChannel(channel).then(function (channel) { + var server = channel.server; + // Make sure `channel` is a voice channel if (channel.type !== "voice") { throw new Error("Can't moveMember into a non-voice channel"); diff --git a/src/Client/Client.js b/src/Client/Client.js index 82a32d5f9..c01331b7d 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -274,8 +274,8 @@ export default class Client extends EventEmitter { } // def moveMember - moveMember(user, server, channel, callback = (/*err, {}*/) => { }) { - return this.internal.moveMember(user, server, channel) + moveMember(user, channel, callback = (/*err, {}*/) => { }) { + return this.internal.moveMember(user, channel) .then(dataCallback(callback), errorCallback(callback)); } diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index e3e18110a..e4f39bf7f 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -573,10 +573,11 @@ export default class InternalClient { } // def moveMember - moveMember(user, server, channel) { + moveMember(user, channel) { user = this.resolver.resolveUser(user); - server = this.resolver.resolveServer(server); return this.resolver.resolveChannel(channel).then(channel => { + var server = channel.server; + // Make sure `channel` is a voice channel if(channel.type !== "voice") { throw new Error("Can't moveMember into a non-voice channel");