From 1dc313425b3496d57ade7eb5d28d41409055eefb Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 02:28:27 +0200 Subject: [PATCH 01/27] Changes to make discord.io compatible with V6 --- lib/index.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index a712be3e..bf6992ae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,7 @@ (function discordio(Discord){ var isNode = typeof(window) === "undefined" && typeof(navigator) === "undefined"; var CURRENT_VERSION = "2.x.x", - GATEWAY_VERSION = 5, + GATEWAY_VERSION = 6, LARGE_THRESHOLD = 250, CONNECT_WHEN = null, Endpoints, Payloads; @@ -906,7 +906,6 @@ DCP.createChannel = function(input, callback) { try { var serverID = res.body.guild_id; var channelID = res.body.id; - client.channels[channelID] = new Channel( client, client.servers[serverID], res.body ); } catch(e) {} handleResCB('Unable to create channel', err, res, callback); @@ -1775,11 +1774,11 @@ function handleWSMessage(data, flags) { client.emit('any', message); //TODO: Remove in v3 client.emit('debug', message); + switch (message.t) { case "READY": copyKeys(_data.user, client); client.internals.sessionID = _data.session_id; - getServerInfo(client, _data.guilds); getDirectMessages(client, _data.private_channels); @@ -1879,12 +1878,11 @@ function handleWSMessage(data, flags) { case "CHANNEL_CREATE": channelID = _data.id; - if (_data.is_private) { + if (_data.type == 1) { if (client.directMessages[channelID]) return; client.directMessages[channelID] = new DMChannel(client._uIDToDM, _data); return emit(client, message, client.directMessages[channelID]); } - if (client.channels[channelID]) return; client.channels[channelID] = new Channel(client, client.servers[_data.guild_id], _data); return emit(client, message, client.channels[channelID]); @@ -1893,7 +1891,7 @@ function handleWSMessage(data, flags) { Channel.update(client, _data); return emit(client, message, old, client.channels[_data.id]); case "CHANNEL_DELETE": - if (_data.is_private === true) { + if (_data.type == 1) { emit(client, message, client.directMessages[_data.id]); delete(client.directMessages[_data.id]); return delete(client._uIDToDM[_data.recipient.id]); @@ -2526,26 +2524,28 @@ function Channel(client, server, data) { var channel = this; this.members = {}; this.permissions = { user: {}, role: {} }; + this.guild_id = server.id; + copyKeys(data, this, ['permission_overwrites', 'emojis']); + Object.defineProperty(server.channels, channel.id, { get: function() { return client.channels[channel.id]; }, set: function(v) { client.channels[channel.id] = v; }, enumerable: true, configurable: true }); + data.permission_overwrites.forEach(function(p) { var type = (p.type === 'member' ? 'user' : 'role'); this.permissions[type][p.id] = {allow: p.allow, deny: p.deny}; }, this); - - - delete(this.is_private); } function DMChannel(translator, data) { copyKeys(data, this); - translator[data.recipient.id] = data.id; - delete(this.is_private); + data.recipients.forEach(function(recipient) { + translator[recipient.id] = data.id; + }); } function User(data) { copyKeys(data, this); @@ -2625,7 +2625,6 @@ Channel.update = function(client, data) { } client.channels[data.id][key] = data[key]; } - delete(client.channels[data.id].is_private); }; Member.update = function(client, server, data) { if (!server.members[data.user.id]) return server.members[data.user.id] = new Member(client, server, data); @@ -2932,9 +2931,9 @@ function Websocket(url, opts) { return { op: 3, d: { - status: type(input.idle_since) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, + status: type(input.idle) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, afk: !!input.afk, - since: type(input.idle_since) === 'number' || input.status === 'idle' ? Date.now() : null, + since: type(input.idle) === 'number' || input.status === 'idle' ? Date.now() : null, game: type(input.game) === 'object' ? { name: input.game.name ? String(input.game.name) : null, From cb8eb10de9ea507e058eda693831779c976daf33 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 02:55:42 +0200 Subject: [PATCH 02/27] Revert "Changes to make discord.io compatible with V6" This reverts commit 1dc313425b3496d57ade7eb5d28d41409055eefb. --- lib/index.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index bf6992ae..a712be3e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,7 @@ (function discordio(Discord){ var isNode = typeof(window) === "undefined" && typeof(navigator) === "undefined"; var CURRENT_VERSION = "2.x.x", - GATEWAY_VERSION = 6, + GATEWAY_VERSION = 5, LARGE_THRESHOLD = 250, CONNECT_WHEN = null, Endpoints, Payloads; @@ -906,6 +906,7 @@ DCP.createChannel = function(input, callback) { try { var serverID = res.body.guild_id; var channelID = res.body.id; + client.channels[channelID] = new Channel( client, client.servers[serverID], res.body ); } catch(e) {} handleResCB('Unable to create channel', err, res, callback); @@ -1774,11 +1775,11 @@ function handleWSMessage(data, flags) { client.emit('any', message); //TODO: Remove in v3 client.emit('debug', message); - switch (message.t) { case "READY": copyKeys(_data.user, client); client.internals.sessionID = _data.session_id; + getServerInfo(client, _data.guilds); getDirectMessages(client, _data.private_channels); @@ -1878,11 +1879,12 @@ function handleWSMessage(data, flags) { case "CHANNEL_CREATE": channelID = _data.id; - if (_data.type == 1) { + if (_data.is_private) { if (client.directMessages[channelID]) return; client.directMessages[channelID] = new DMChannel(client._uIDToDM, _data); return emit(client, message, client.directMessages[channelID]); } + if (client.channels[channelID]) return; client.channels[channelID] = new Channel(client, client.servers[_data.guild_id], _data); return emit(client, message, client.channels[channelID]); @@ -1891,7 +1893,7 @@ function handleWSMessage(data, flags) { Channel.update(client, _data); return emit(client, message, old, client.channels[_data.id]); case "CHANNEL_DELETE": - if (_data.type == 1) { + if (_data.is_private === true) { emit(client, message, client.directMessages[_data.id]); delete(client.directMessages[_data.id]); return delete(client._uIDToDM[_data.recipient.id]); @@ -2524,28 +2526,26 @@ function Channel(client, server, data) { var channel = this; this.members = {}; this.permissions = { user: {}, role: {} }; - this.guild_id = server.id; - copyKeys(data, this, ['permission_overwrites', 'emojis']); - Object.defineProperty(server.channels, channel.id, { get: function() { return client.channels[channel.id]; }, set: function(v) { client.channels[channel.id] = v; }, enumerable: true, configurable: true }); - data.permission_overwrites.forEach(function(p) { var type = (p.type === 'member' ? 'user' : 'role'); this.permissions[type][p.id] = {allow: p.allow, deny: p.deny}; }, this); + + + delete(this.is_private); } function DMChannel(translator, data) { copyKeys(data, this); - data.recipients.forEach(function(recipient) { - translator[recipient.id] = data.id; - }); + translator[data.recipient.id] = data.id; + delete(this.is_private); } function User(data) { copyKeys(data, this); @@ -2625,6 +2625,7 @@ Channel.update = function(client, data) { } client.channels[data.id][key] = data[key]; } + delete(client.channels[data.id].is_private); }; Member.update = function(client, server, data) { if (!server.members[data.user.id]) return server.members[data.user.id] = new Member(client, server, data); @@ -2931,9 +2932,9 @@ function Websocket(url, opts) { return { op: 3, d: { - status: type(input.idle) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, + status: type(input.idle_since) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, afk: !!input.afk, - since: type(input.idle) === 'number' || input.status === 'idle' ? Date.now() : null, + since: type(input.idle_since) === 'number' || input.status === 'idle' ? Date.now() : null, game: type(input.game) === 'object' ? { name: input.game.name ? String(input.game.name) : null, From c40ba0ef2aa7f93354018e2bbb220e23ca315b6b Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 03:10:47 +0200 Subject: [PATCH 03/27] Changes to make discord.io compatible with V6 gateway. (2nd try) --- lib/index.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/index.js b/lib/index.js index a712be3e..7d3609b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,7 @@ (function discordio(Discord){ var isNode = typeof(window) === "undefined" && typeof(navigator) === "undefined"; var CURRENT_VERSION = "2.x.x", - GATEWAY_VERSION = 5, + GATEWAY_VERSION = 6, LARGE_THRESHOLD = 250, CONNECT_WHEN = null, Endpoints, Payloads; @@ -1879,7 +1879,7 @@ function handleWSMessage(data, flags) { case "CHANNEL_CREATE": channelID = _data.id; - if (_data.is_private) { + if (_data.type == 1) { if (client.directMessages[channelID]) return; client.directMessages[channelID] = new DMChannel(client._uIDToDM, _data); return emit(client, message, client.directMessages[channelID]); @@ -1893,7 +1893,7 @@ function handleWSMessage(data, flags) { Channel.update(client, _data); return emit(client, message, old, client.channels[_data.id]); case "CHANNEL_DELETE": - if (_data.is_private === true) { + if (_data.type == 1) { emit(client, message, client.directMessages[_data.id]); delete(client.directMessages[_data.id]); return delete(client._uIDToDM[_data.recipient.id]); @@ -2538,14 +2538,12 @@ function Channel(client, server, data) { var type = (p.type === 'member' ? 'user' : 'role'); this.permissions[type][p.id] = {allow: p.allow, deny: p.deny}; }, this); - - - delete(this.is_private); } function DMChannel(translator, data) { copyKeys(data, this); - translator[data.recipient.id] = data.id; - delete(this.is_private); + data.recipients.forEach(function(recipient) { + translator[recipient.id] = data.id; + }); } function User(data) { copyKeys(data, this); @@ -2625,7 +2623,6 @@ Channel.update = function(client, data) { } client.channels[data.id][key] = data[key]; } - delete(client.channels[data.id].is_private); }; Member.update = function(client, server, data) { if (!server.members[data.user.id]) return server.members[data.user.id] = new Member(client, server, data); @@ -2932,9 +2929,9 @@ function Websocket(url, opts) { return { op: 3, d: { - status: type(input.idle_since) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, + status: type(input.idle) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, afk: !!input.afk, - since: type(input.idle_since) === 'number' || input.status === 'idle' ? Date.now() : null, + since: type(input.idle) === 'number' || input.status === 'idle' ? Date.now() : null, game: type(input.game) === 'object' ? { name: input.game.name ? String(input.game.name) : null, From 6c0199bbef2b247241c01ff4802c282b2e5840d0 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 03:35:11 +0200 Subject: [PATCH 04/27] Update gateway_v6 README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c76d8f14..e88dce52 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ A small, single-file, fully featured [Discordapp](https://discordapp.com) librar [![Discord](https://discordapp.com/api/guilds/66192955777486848/widget.png)](https://discord.gg/0MvHMfHcTKVVmIGP) [![NPM](https://img.shields.io/npm/v/discord.io.svg)](https://img.shields.io/npm/v/gh-badges.svg) +**With V5 gateway getting deprecated on Oct. 16, this is a first step at getting V6 to work.** + ### Requirements **Required**: * **Node.js 0.10.x** or greater From b7993cc68977b35353202359aebf70c7c6388191 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 06:19:18 +0200 Subject: [PATCH 05/27] Missted a reference to idle_since. Thanks Luarst! --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7d3609b4..8b0b22db 100644 --- a/lib/index.js +++ b/lib/index.js @@ -135,7 +135,7 @@ DCP.editUserInfo = function(input, callback) { * Change the client's presence. * @arg {Object} input * @arg {String|null} input.status - Used to set the status. online, idle, dnd, invisible, and offline are the possible states. - * @arg {Number|null} input.idle_since - Optional, use a Number before the current point in time. + * @arg {Number|null} input.idle - Optional, use a Number before the current point in time. * @arg {Boolean|null} input.afk - Optional, changes how Discord handles push notifications. * @arg {Object|null} input.game - Used to set game information. * @arg {String|null} input.game.name - The name of the game. @@ -146,7 +146,7 @@ DCP.setPresence = function(input) { var payload = Payloads.STATUS(input); send(this._ws, payload); - if (payload.d.idle_since === null) return void(this.presenceStatus = payload.d.status); + if (payload.d.idle === null) return void(this.presenceStatus = payload.d.status); this.presenceStatus = payload.d.status; }; From 52e028429f047dd03a22ad965e095c42925a763d Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 07:07:02 +0200 Subject: [PATCH 06/27] Added Message.type to generated Messages with default :0 --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 8b0b22db..d4996832 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1408,6 +1408,7 @@ function cacheMessage(cache, limit, channelID, message) { } function generateMessage(message, embed) { return { + type: 0, content: String(message), nonce: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER), embed: embed || {} From 76d4e277ed6012bcb106f69ae0960f4b9540c077 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 07:27:54 +0200 Subject: [PATCH 07/27] Properly fix idle_since to 'since' instead of 'idle' --- lib/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index d4996832..5ee7d456 100644 --- a/lib/index.js +++ b/lib/index.js @@ -135,7 +135,7 @@ DCP.editUserInfo = function(input, callback) { * Change the client's presence. * @arg {Object} input * @arg {String|null} input.status - Used to set the status. online, idle, dnd, invisible, and offline are the possible states. - * @arg {Number|null} input.idle - Optional, use a Number before the current point in time. + * @arg {Number|null} input.since - Optional, use a Number before the current point in time. * @arg {Boolean|null} input.afk - Optional, changes how Discord handles push notifications. * @arg {Object|null} input.game - Used to set game information. * @arg {String|null} input.game.name - The name of the game. @@ -146,7 +146,7 @@ DCP.setPresence = function(input) { var payload = Payloads.STATUS(input); send(this._ws, payload); - if (payload.d.idle === null) return void(this.presenceStatus = payload.d.status); + if (payload.d.since === null) return void(this.presenceStatus = payload.d.status); this.presenceStatus = payload.d.status; }; @@ -2930,9 +2930,9 @@ function Websocket(url, opts) { return { op: 3, d: { - status: type(input.idle) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, + status: type(input.since) === 'number' ? 'idle' : input.status !== undefined ? input.status : null, afk: !!input.afk, - since: type(input.idle) === 'number' || input.status === 'idle' ? Date.now() : null, + since: type(input.since) === 'number' || input.status === 'idle' ? Date.now() : null, game: type(input.game) === 'object' ? { name: input.game.name ? String(input.game.name) : null, From 9e34863f91d408b56a31715e05fce375e07df81e Mon Sep 17 00:00:00 2001 From: Gilles May Date: Tue, 3 Oct 2017 01:42:46 +0200 Subject: [PATCH 08/27] Add .recipient to DMChannel to keep backwards compatibilty with existing bots. --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 5ee7d456..de70def2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2542,6 +2542,7 @@ function Channel(client, server, data) { } function DMChannel(translator, data) { copyKeys(data, this); + this.recipient = data.recipients[0]; data.recipients.forEach(function(recipient) { translator[recipient.id] = data.id; }); From cd9c9cd5a96ed2a5cc1c8bc0a7ca9595674caadd Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 16 Oct 2017 10:49:57 +0200 Subject: [PATCH 09/27] Fix voice channel detection. --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index de70def2..b62d7aa0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1303,7 +1303,7 @@ DCP.joinVoiceChannel = function(channelID, callback) { channel = server.channels[channelID]; } catch(e) {} if (!serverID) return handleErrCB(("Cannot find the server related to the channel provided: " + channelID), callback); - if (channel.type !== 'voice') return handleErrCB(("Selected channel is not a voice channel: " + channelID), callback); + if (channel.type !== 'voice' && channel.type !== 2) return handleErrCB(("Selected channel is not a voice channel: " + channelID), callback); if (this._vChannels[channelID]) return handleErrCB(("Voice channel already active: " + channelID), callback); voiceSession = getVoiceSession(this, channelID, server); @@ -2542,7 +2542,7 @@ function Channel(client, server, data) { } function DMChannel(translator, data) { copyKeys(data, this); - this.recipient = data.recipients[0]; + this.recipient = data.recipients[0]; data.recipients.forEach(function(recipient) { translator[recipient.id] = data.id; }); From 6fc95614298d6980d35af683b2217ada15d31445 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Fri, 27 Oct 2017 05:47:08 +0200 Subject: [PATCH 10/27] Fix another occurence of recipient. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index b62d7aa0..fcee511f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -920,7 +920,7 @@ DCP.createChannel = function(input, callback) { DCP.createDMChannel = function(userID, callback) { var client = this; this._req('post', Endpoints.USER(client.id) + "/channels", {recipient_id: userID}, function(err, res) { - if (!err && goodResponse(res)) client._uIDToDM[res.body.recipient.id] = res.body.id; + if (!err && goodResponse(res)) client._uIDToDM[res.body.recipients[0].id] = res.body.id; handleResCB("Unable to create DM Channel", err, res, callback); }); }; From 41ecf2edbbaf265fb612569f20fbbdbc53862e7c Mon Sep 17 00:00:00 2001 From: Woor Date: Fri, 27 Oct 2017 21:59:42 +0200 Subject: [PATCH 11/27] Update README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e88dce52..f8a9f0af 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,8 @@ A small, single-file, fully featured [Discordapp](https://discordapp.com) librar ### Getting Started: #### Installing -**[Stable](https://www.npmjs.com/package/discord.io)** -`npm install discord.io` - -**[Latest](https://github.com/izy521/discord.io)** -`npm install izy521/discord.io` +**[Latest](https://github.com/Woor/discord.io/tree/gateway_v6)** +`npm install Woor/discord.io#gateway_v6` #### Example ```javascript From 1496dd56f1ec2a0ea9a54c4811e97e8f4fc9f9be Mon Sep 17 00:00:00 2001 From: Gilles May Date: Sat, 28 Oct 2017 12:04:18 +0200 Subject: [PATCH 12/27] Yet another occurence of recipient fixed. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index fcee511f..a3a2cf76 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1897,7 +1897,7 @@ function handleWSMessage(data, flags) { if (_data.type == 1) { emit(client, message, client.directMessages[_data.id]); delete(client.directMessages[_data.id]); - return delete(client._uIDToDM[_data.recipient.id]); + return delete(client._uIDToDM[_data.recipients[0].id]); } emit(client, message, client.servers[_data.guild_id].channels[_data.id]); delete(client.servers[_data.guild_id].channels[_data.id]); From 13fd4312f61eed397f215b3986de00e1bba544da Mon Sep 17 00:00:00 2001 From: Edward Fish Date: Sun, 29 Oct 2017 14:26:05 +1300 Subject: [PATCH 13/27] Allow creating channels within a category Use .createChannel with either parentID or parent_id to create a channel in a category; unspecify both of those to create outside of a category. --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index a3a2cf76..a0bc1062 100644 --- a/lib/index.js +++ b/lib/index.js @@ -899,7 +899,8 @@ DCP.getChannelInvites = function(channelID, callback) { DCP.createChannel = function(input, callback) { var client = this, payload = { name: input.name, - type: (['text', 'voice'].indexOf(input.type) < 0) ? 'text' : input.type + type: (['text', 'voice'].indexOf(input.type) < 0) ? 'text' : input.type, + parent_id: input.parentID || input.parent_id }; this._req('post', Endpoints.SERVERS(input.serverID) + "/channels", payload, function(err, res) { From c7a2c9be97d057dc621d48263ace1ff13cc26723 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 30 Oct 2017 22:53:59 +0100 Subject: [PATCH 14/27] Fixes channel.type in DCP.editChannelPermissions() --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index a3a2cf76..ddb8849a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -999,7 +999,7 @@ DCP.editChannelPermissions = function(input, callback) { //Will shrink this up l ID = input[pType + "ID"]; channel = this.channels[ input.channelID ]; permissions = channel.permissions[pType][ID] || { allow: 0, deny: 0 }; - allowed_values = [0, 4, 28].concat((channel.type === 'text' ? + allowed_values = [0, 4, 28].concat(((channel.type === 'text' || channel.type === 0) ? [10, 11, 12, 13, 14, 15, 16, 17, 18] : [20, 21, 22, 23, 24, 25] )); From 162bfba2a60f51950b57c4753b734598a29afc70 Mon Sep 17 00:00:00 2001 From: Edward Fish Date: Tue, 31 Oct 2017 11:17:37 +1300 Subject: [PATCH 15/27] Only use camelCase --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index a0bc1062..eafafc79 100644 --- a/lib/index.js +++ b/lib/index.js @@ -900,7 +900,7 @@ DCP.createChannel = function(input, callback) { var client = this, payload = { name: input.name, type: (['text', 'voice'].indexOf(input.type) < 0) ? 'text' : input.type, - parent_id: input.parentID || input.parent_id + parent_id: input.parentID }; this._req('post', Endpoints.SERVERS(input.serverID) + "/channels", payload, function(err, res) { From 9f01a5f693b3fcaf9c8de921d1a5b660819c44be Mon Sep 17 00:00:00 2001 From: Edward Fish Date: Tue, 31 Oct 2017 12:03:59 +1300 Subject: [PATCH 16/27] Updated function description --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index eafafc79..fa416a33 100644 --- a/lib/index.js +++ b/lib/index.js @@ -895,6 +895,7 @@ DCP.getChannelInvites = function(channelID, callback) { * @arg {Snowflake} input.serverID * @arg {String} input.name * @arg {String} [input.type] - 'text' or 'voice', defaults to 'text. + * @arg {Snowflake} input.parentID */ DCP.createChannel = function(input, callback) { var client = this, payload = { From e33ed71636325c172e9878f42b6f94eb027b5cf7 Mon Sep 17 00:00:00 2001 From: Edward Fish Date: Tue, 31 Oct 2017 12:41:25 +1300 Subject: [PATCH 17/27] Square brackets indicate an optional parameter We good now? --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index fa416a33..315980d4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -895,7 +895,7 @@ DCP.getChannelInvites = function(channelID, callback) { * @arg {Snowflake} input.serverID * @arg {String} input.name * @arg {String} [input.type] - 'text' or 'voice', defaults to 'text. - * @arg {Snowflake} input.parentID + * @arg {Snowflake} [input.parentID] */ DCP.createChannel = function(input, callback) { var client = this, payload = { From bcac982ebaa9975f4204909031a6c446654b9d1a Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Thu, 9 Nov 2017 14:49:34 +1300 Subject: [PATCH 18/27] resolve userID to channelID for addReaction --- lib/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index a8771399..41986942 100644 --- a/lib/index.js +++ b/lib/index.js @@ -401,9 +401,12 @@ DCP.fixMessage = function(message) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.addReaction = function(input, callback) { - this._req('put', Endpoints.USER_REACTIONS(input.channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { - handleResCB("Unable to add reaction", err, res, callback); - }); + let client=this + resolveID(client, input.channelID, function(channelID) { + client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { + handleResCB("Unable to add reaction", err, res, callback); + }); + }); }; /** From dcaa15296f52efc98d00d8469b37bb30922f9bb7 Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Thu, 9 Nov 2017 15:12:57 +1300 Subject: [PATCH 19/27] let to var --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 41986942..96acb27b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -401,7 +401,7 @@ DCP.fixMessage = function(message) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.addReaction = function(input, callback) { - let client=this + var client=this resolveID(client, input.channelID, function(channelID) { client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { handleResCB("Unable to add reaction", err, res, callback); From 3554d8aaaebe84d0ae49dbaad72c303e8dde0f85 Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Thu, 9 Nov 2017 15:14:27 +1300 Subject: [PATCH 20/27] put a space around = sign --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 96acb27b..cd1fcdbe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -401,7 +401,7 @@ DCP.fixMessage = function(message) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.addReaction = function(input, callback) { - var client=this + var client = this resolveID(client, input.channelID, function(channelID) { client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { handleResCB("Unable to add reaction", err, res, callback); From 9bec1d4892d2c97f6e96d0495e7dd0d542aa438b Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Thu, 9 Nov 2017 15:16:44 +1300 Subject: [PATCH 21/27] my bad syntax habit (added ; ) --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index cd1fcdbe..d9780a24 100644 --- a/lib/index.js +++ b/lib/index.js @@ -401,7 +401,7 @@ DCP.fixMessage = function(message) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.addReaction = function(input, callback) { - var client = this + var client = this; resolveID(client, input.channelID, function(channelID) { client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { handleResCB("Unable to add reaction", err, res, callback); From d812e9ac6c48b8ca546e166d9ad734e5a1f7bf82 Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Sat, 11 Nov 2017 12:26:00 +1300 Subject: [PATCH 22/27] added more userID revolvers for reactions --- lib/index.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index d9780a24..e891fe2d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -418,10 +418,13 @@ DCP.addReaction = function(input, callback) { * @arg {String} [input.limit] */ DCP.getReaction = function(input, callback) { - var qs = { limit: (typeof(input.limit) !== 'number' ? 100 : input.limit) }; - this._req('get', Endpoints.MESSAGE_REACTIONS(input.channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { - handleResCB("Unable to get reaction", err, res, callback); - }); + var qs = { limit: (typeof(input.limit) !== 'number' ? 100 : input.limit) }; + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('get', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { + handleResCB("Unable to get reaction", err, res, callback); + }); + }; }; /** @@ -433,9 +436,12 @@ DCP.getReaction = function(input, callback) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.removeReaction = function(input, callback) { - this._req('delete', Endpoints.USER_REACTIONS(input.channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { - handleResCB("Unable to remove reaction", err, res, callback); - }); + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('delete', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { + handleResCB("Unable to remove reaction", err, res, callback); + }); + }; }; /** @@ -445,9 +451,12 @@ DCP.removeReaction = function(input, callback) { * @arg {Snowflake} input.messageID */ DCP.removeAllReactions = function(input, callback) { - this._req('delete', Endpoints.MESSAGE_REACTIONS(input.channelID, input.messageID), function(err, res) { - handleResCB("Unable to remove reactions", err, res, callback); - }); + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('delete', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID), function(err, res) { + handleResCB("Unable to remove reactions", err, res, callback); + }); + }; }; /* - DiscordClient - Methods - Server Management - */ From cbcf3bc93cecdb6821dac97e8056e3098f80bb60 Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Sat, 11 Nov 2017 14:21:18 +1300 Subject: [PATCH 23/27] syntax fix and indentation --- lib/index.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/index.js b/lib/index.js index e891fe2d..da3f7448 100644 --- a/lib/index.js +++ b/lib/index.js @@ -418,13 +418,13 @@ DCP.addReaction = function(input, callback) { * @arg {String} [input.limit] */ DCP.getReaction = function(input, callback) { - var qs = { limit: (typeof(input.limit) !== 'number' ? 100 : input.limit) }; - var client = this; - resolveID(client, input.channelID, function(channelID) { - this._req('get', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { - handleResCB("Unable to get reaction", err, res, callback); - }); - }; + var qs = { limit: (typeof(input.limit) !== 'number' ? 100 : input.limit) }; + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('get', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { + handleResCB("Unable to get reaction", err, res, callback); + }); + }); }; /** @@ -436,12 +436,12 @@ DCP.getReaction = function(input, callback) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.removeReaction = function(input, callback) { - var client = this; - resolveID(client, input.channelID, function(channelID) { - this._req('delete', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { - handleResCB("Unable to remove reaction", err, res, callback); - }); - }; + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('delete', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { + handleResCB("Unable to remove reaction", err, res, callback); + }); + }); }; /** @@ -451,12 +451,12 @@ DCP.removeReaction = function(input, callback) { * @arg {Snowflake} input.messageID */ DCP.removeAllReactions = function(input, callback) { - var client = this; - resolveID(client, input.channelID, function(channelID) { - this._req('delete', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID), function(err, res) { - handleResCB("Unable to remove reactions", err, res, callback); - }); - }; + var client = this; + resolveID(client, input.channelID, function(channelID) { + this._req('delete', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID), function(err, res) { + handleResCB("Unable to remove reactions", err, res, callback); + }); + }); }; /* - DiscordClient - Methods - Server Management - */ From 90388820dec41ffccdaebcd9ecaabab5e6007ae1 Mon Sep 17 00:00:00 2001 From: CheweyZ Date: Tue, 14 Nov 2017 16:55:07 +1300 Subject: [PATCH 24/27] audit log in permissions --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index da3f7448..c763fa96 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2720,6 +2720,7 @@ Discord.Permissions = { GENERAL_ADMINISTRATOR: 3, GENERAL_MANAGE_CHANNELS: 4, GENERAL_MANAGE_GUILD: 5, + GENERAL_AUDIT_LOG: 7, GENERAL_MANAGE_ROLES: 28, GENERAL_MANAGE_NICKNAMES: 27, GENERAL_CHANGE_NICKNAME: 26, From 73e90b24a3fc3ef4fe7aa0894c8a3db4197f8534 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 20 Nov 2017 19:59:56 -0500 Subject: [PATCH 25/27] Added an optimal parameter to define playback volume when you call `getAudioContext` This is using an [FFmpeg Audio filter](https://trac.ffmpeg.org/wiki/AudioVolume) ```javascript client.getAudioContext(channel, 0.5, function(error, stream) { if(error) console.log(error) return stream //This will play any audio at half volume, if no value is defined audio plays at full volume. }) --- lib/index.js | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/index.js b/lib/index.js index b692f0df..57731960 100644 --- a/lib/index.js +++ b/lib/index.js @@ -576,11 +576,11 @@ DCP.undeafen = function(input, callback) { DCP.muteSelf = function(serverID, callback) { var server = this.servers[serverID], channelID, voiceSession; if (!server) return handleErrCB(("Cannot find the server provided: " + serverID), callback); - + server.self_mute = true; - + if (!server.voiceSession) return call(callback, [null]); - + voiceSession = server.voiceSession; voiceSession.self_mute = true; channelID = voiceSession.channelID; @@ -595,11 +595,11 @@ DCP.muteSelf = function(serverID, callback) { DCP.unmuteSelf = function(serverID, callback) { var server = this.servers[serverID], channelID, voiceSession; if (!server) return handleErrCB(("Cannot find the server provided: " + serverID), callback); - + server.self_mute = false; - + if (!server.voiceSession) return call(callback, [null]); - + voiceSession = server.voiceSession; voiceSession.self_mute = false; channelID = voiceSession.channelID; @@ -614,11 +614,11 @@ DCP.unmuteSelf = function(serverID, callback) { DCP.deafenSelf = function(serverID, callback) { var server = this.servers[serverID], channelID, voiceSession; if (!server) return handleErrCB(("Cannot find the server provided: " + serverID), callback); - + server.self_deaf = true; - + if (!server.voiceSession) return call(callback, [null]); - + voiceSession = server.voiceSession; voiceSession.self_deaf = true; channelID = voiceSession.channelID; @@ -633,11 +633,11 @@ DCP.deafenSelf = function(serverID, callback) { DCP.undeafenSelf = function(serverID, callback) { var server = this.servers[serverID], channelID, voiceSession; if (!server) return handleErrCB(("Cannot find the server provided: " + serverID), callback); - + server.self_deaf = false; - + if (!server.voiceSession) return call(callback, [null]); - + voiceSession = server.voiceSession; voiceSession.self_deaf = false; channelID = voiceSession.channelID; @@ -1137,7 +1137,7 @@ DCP.editRole = function(input, callback) { }); } catch(e) {return handleErrCB(('[editRole] ' + e), callback);} }; - + /** * Move a role up or down relative to it's current position. * @arg {Object} input @@ -1155,7 +1155,7 @@ DCP.moveRole = function(input,callback){ if(newPos < 1) newPos = 1; //make sure it doesn't go under the possible positions - + if(newPos > Object.keys(this.servers[input.serverID].roles).length-1) newPos = Object.keys(this.servers[input.serverID].roles).length-1; //make sure it doesn't go above the possible positions @@ -1182,7 +1182,7 @@ DCP.moveRole = function(input,callback){ }); } catch(e) {return handleErrCB(e, callback);} }; - + /** * Delete a role. * @arg {Object} input @@ -1381,19 +1381,22 @@ DCP.leaveVoiceChannel = function(channelID, callback) { * @arg {Number} [channelObj.maxStreamSize] - The size in KB that you wish to receive before pushing out earlier data. Required if you want to store or receive incoming audio. * @arg {Boolean} [channelObj.stereo] - Sets the audio to be either stereo or mono. Defaults to true. */ -DCP.getAudioContext = function(channelObj, callback) { +DCP.getAudioContext = function(channelObj, volume, callback) { // #q/qeled gave a proper timing solution. Credit where it's due. if (!isNode) return handleErrCB("Using audio in the browser is currently not supported.", callback); + var callback = (typeof(arguments[1]) === 'function') ? arguments[1] : arguments[2]; var channelID = channelObj.channelID || channelObj, voiceSession = this._vChannels[channelID], encoder = chooseAudioEncoder(['ffmpeg', 'avconv']); + if (typeof(volume) !== 'number') volume = 1.0 if (!voiceSession) return handleErrCB(("You have not joined the voice channel: " + channelID), callback); if (voiceSession.ready !== true) return handleErrCB(("The connection to the voice channel " + channelID + " has not been initialized yet."), callback); if (!encoder) return handleErrCB("You need either 'ffmpeg' or 'avconv' and they need to be added to PATH", callback); - voiceSession.audio = voiceSession.audio || new AudioCB( + voiceSession.audio = voiceSession.audio && voiceSession.audio.volume === volume || new AudioCB( voiceSession, channelObj.stereo === false ? 1 : 2, encoder, + volume, Math.abs(Number(channelObj.maxStreamSize))); return call(callback, [null, voiceSession.audio]); @@ -2218,7 +2221,7 @@ function handleUDPMessage(voiceSession, msg, rinfo) { } /* - Functions - Voice - AudioCallback - */ -function AudioCB(voiceSession, audioChannels, encoder, maxStreamSize) { +function AudioCB(voiceSession, audioChannels, encoder, volume, maxStreamSize) { //With the addition of the new Stream API, `playAudioFile`, `stopAudioFile` and `send` //will be removed. However they're deprecated for now, hence the code repetition. if (maxStreamSize && !Opus) Opus = require('cjopus'); @@ -2227,6 +2230,7 @@ function AudioCB(voiceSession, audioChannels, encoder, maxStreamSize) { this.audioChannels = audioChannels; this.members = voiceSession.members; + this.volume = volume applyProperties(this, [ ["_sequence", 0], @@ -2480,6 +2484,7 @@ function createAudioEncoder(ACBI, encoder) { '-f', 'data', '-sample_fmt', 's16', '-vbr', 'off', + '-filter:a', 'volume=' + ACBI.volume, '-compression_level', '10', '-ar', '48000', '-ac', ACBI.audioChannels, From c15cd06573d7b1c7bd36335ed5c28025ce7ee1df Mon Sep 17 00:00:00 2001 From: Edward Fish Date: Sun, 26 Nov 2017 18:12:21 +1300 Subject: [PATCH 26/27] Fix deleting old messages automatically when user is banned --- lib/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index c763fa96..92acd211 100644 --- a/lib/index.js +++ b/lib/index.js @@ -486,9 +486,10 @@ DCP.ban = function(input, callback) { var opts = {}; if (input.lastDays) { - opts.lastDays = Number(input.lastDays); - opts.lastDays = Math.min(opts.lastDays, 7); - opts.lastDays = Math.max(opts.lastDays, 1); + input.lastDays = Number(input.lastDays); + input.lastDays = Math.min(input.lastDays, 7); + input.lastDays = Math.max(input.lastDays, 1); + opts["delete-message-days"] = input.lastDays; } if (input.reason) opts.reason = input.reason; From 8d3bfd521f57c070ae996694178b1287b19f9283 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Thu, 30 Nov 2017 04:32:03 +0100 Subject: [PATCH 27/27] Fix identation and fixed resolvers for reactions. --- lib/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index 92acd211..919d0409 100644 --- a/lib/index.js +++ b/lib/index.js @@ -401,12 +401,12 @@ DCP.fixMessage = function(message) { * @arg {String} input.reaction - Either the emoji unicode or the emoji name:id/object. */ DCP.addReaction = function(input, callback) { - var client = this; - resolveID(client, input.channelID, function(channelID) { - client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { - handleResCB("Unable to add reaction", err, res, callback); - }); - }); + var client = this; + resolveID(client, input.channelID, function(channelID) { + client._req('put', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)), function(err, res) { + handleResCB("Unable to add reaction", err, res, callback); + }); + }); }; /** @@ -421,10 +421,10 @@ DCP.getReaction = function(input, callback) { var qs = { limit: (typeof(input.limit) !== 'number' ? 100 : input.limit) }; var client = this; resolveID(client, input.channelID, function(channelID) { - this._req('get', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { + client._req('get', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction)) + qstringify(qs), function(err, res) { handleResCB("Unable to get reaction", err, res, callback); }); - }); + }); }; /** @@ -438,10 +438,10 @@ DCP.getReaction = function(input, callback) { DCP.removeReaction = function(input, callback) { var client = this; resolveID(client, input.channelID, function(channelID) { - this._req('delete', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { + client._req('delete', Endpoints.USER_REACTIONS(channelID, input.messageID, stringifyEmoji(input.reaction), input.userID), function(err, res) { handleResCB("Unable to remove reaction", err, res, callback); }); - }); + }); }; /** @@ -451,12 +451,12 @@ DCP.removeReaction = function(input, callback) { * @arg {Snowflake} input.messageID */ DCP.removeAllReactions = function(input, callback) { - var client = this; - resolveID(client, input.channelID, function(channelID) { - this._req('delete', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID), function(err, res) { + var client = this; + resolveID(client, input.channelID, function(channelID) { + client._req('delete', Endpoints.MESSAGE_REACTIONS(channelID, input.messageID), function(err, res) { handleResCB("Unable to remove reactions", err, res, callback); }); - }); + }); }; /* - DiscordClient - Methods - Server Management - */