From 1dc313425b3496d57ade7eb5d28d41409055eefb Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 02:28:27 +0200 Subject: [PATCH 01/17] 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/17] 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/17] 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 1d403d84ce7a492d65af14740920cab0a80ea39c Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 03:20:33 +0200 Subject: [PATCH 04/17] Revert "Changes to make discord.io compatible with V6 gateway. (2nd try)" This reverts commit c40ba0ef2aa7f93354018e2bbb220e23ca315b6b. --- lib/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7d3609b4..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; @@ -1879,7 +1879,7 @@ 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]); @@ -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.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]); @@ -2538,12 +2538,14 @@ 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); - 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); @@ -2623,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); @@ -2929,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 e1dd7fa21a7e7c6ba5aa02ea4c18a38fb4574081 Mon Sep 17 00:00:00 2001 From: Woor <17484890+Woor@users.noreply.github.com> Date: Mon, 2 Oct 2017 03:29:50 +0200 Subject: [PATCH 05/17] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c76d8f14..4c432489 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 the end of V5 gateway this is a first step at getting it to work on V6** + ### Requirements **Required**: * **Node.js 0.10.x** or greater From f2591b9a3eda9db1ce1a03e288ba87a13055c9b7 Mon Sep 17 00:00:00 2001 From: Gilles May Date: Mon, 2 Oct 2017 03:32:54 +0200 Subject: [PATCH 06/17] Revert "Update README.md" This reverts commit e1dd7fa21a7e7c6ba5aa02ea4c18a38fb4574081. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4c432489..c76d8f14 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ 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 the end of V5 gateway this is a first step at getting it to work on V6** - ### Requirements **Required**: * **Node.js 0.10.x** or greater From 3d72457a1eacec3bc550350da5d7af6d90f0b988 Mon Sep 17 00:00:00 2001 From: Woor Date: Mon, 2 Oct 2017 03:39:30 +0200 Subject: [PATCH 07/17] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4c432489..c76d8f14 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ 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 the end of V5 gateway this is a first step at getting it to work on V6** - ### Requirements **Required**: * **Node.js 0.10.x** or greater From e7e6ee3f9f3b68b7cbe31dd68521db1c8a88054b Mon Sep 17 00:00:00 2001 From: Woor Date: Fri, 27 Oct 2017 10:22:29 +0200 Subject: [PATCH 08/17] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c76d8f14..5843e698 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) +**You are probably here for the gateway_v6 branch. (https://github.com/Woor/discord.io/tree/gateway_v6) ** + ### Requirements **Required**: * **Node.js 0.10.x** or greater From ae17caa04603a7012c44ae9f55c1290389eeb895 Mon Sep 17 00:00:00 2001 From: izy521 Date: Mon, 16 Oct 2017 15:53:23 -0700 Subject: [PATCH 09/17] Merge pull request #214 from HazardDev/master Added embed options --- typings/index.d.ts | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 305edfe6..cef92bc7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -120,10 +120,36 @@ declare interface permissions { */ declare type sendMessageOpts = { to: string, - message: string, + message?: string, tts?: boolean, nonce?: string, - typing?: boolean + typing?: boolean, + embed?: embedMessageOpts +} + +declare type embedMessageOpts = { + author?: { + icon_url?: string, + name: string, + url?: string + }, + color?: number, + description?: string, + fields?: [{ + name: string, + value?: string, + inline?: boolean + }], + thumbnail?: { + url: string + }, + title: string, + timestamp?: Date + url?: string, + footer?: { + icon_url?: string, + text: string + } } declare type uploadFileOpts = { @@ -325,6 +351,12 @@ declare type getMembersOpts = { after: string } +declare type reactionOpts = { + channelID: string, + messageID: string, + reaction: string +} + /** * CLASSES */ @@ -506,7 +538,7 @@ declare namespace Discord { pinMessage(options: pinMessageOpts, callback?: callbackFunc): void deletePinnedMessage(options: deletePinnedMessageOpts, callback?: callbackFunc): void getPinnedMessages(options: getPinnedMessagesOpts, callback?: callbackFunc): void - + addReaction(options: reactionOpts, callback?: callbackFunc): void /** * VOICE CHANNELS */ From 66a285612f771cc986d506ec428c3eb577d0b746 Mon Sep 17 00:00:00 2001 From: izy521 Date: Sat, 28 Oct 2017 22:08:36 -0700 Subject: [PATCH 10/17] Merge pull request #139 from RaidAndFade/patch-2 Added a way to move roles --- lib/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index a712be3e..dcf06fce 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1129,7 +1129,52 @@ 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 + * @arg {Snowflake} input.serverID + * @arg {Snowflake} input.roleID - The ID of the role. + * @arg {Number} input.position - A relative number to move the role up or down. + */ +DCP.moveRole = function(input,callback){ + if(input.position===0)return handleErrCB("Desired role position is same as current", callback); //Don't do anything if they dont want it to move + + try { + var role = new Role(this.servers[input.serverID].roles[input.roleID]); + var curPos = role.position; + var newPos = curPos + input.position; + + 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 + + var currentOrder = []; + for(var roleID in this.servers[input.serverID].roles){ + if(roleID == input.serverID) continue; //the everyone role cannot be changed, so best to not try. + var _role = new Role(this.servers[input.serverID].roles[roleID]); + currentOrder[_role.position] = roleID; + } + var payload = []; + + + for(var pos in currentOrder){ + var roleID = currentOrder[pos]; + if(newPos>curPos && curPos < pos && pos <= newPos) + payload.push({id:roleID, position:pos-1}); + if(curPos>newPos && curPos > pos && pos >= newPos) + payload.push({id:roleID, position:(pos-(-1))}); + } + payload.push({id:input.roleID,position:newPos}); + this._req('patch', Endpoints.ROLES(input.serverID), payload, function(err, res) { + handleResCB("Unable to move role", err, res, callback); + }); + } catch(e) {return handleErrCB(e, callback);} +}; + /** * Delete a role. * @arg {Object} input @@ -1465,7 +1510,7 @@ function APIRequest(method, url) { }); }); }); - if (type(data) === 'object' || method.toLowerCase() === 'get') req.setHeader("Content-Type", "application/json; charset=utf-8"); + if (typeof(data) == 'object' || method.toLowerCase() === 'get') req.setHeader("Content-Type", "application/json; charset=utf-8"); if (data instanceof Multipart) req.setHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary); if (data) req.write( data.result || JSON.stringify(data), data.result ? 'binary' : 'utf-8' ); req.end(); @@ -1486,7 +1531,7 @@ function APIRequest(method, url) { callback(null, req); } }; - if (type(data) === 'object' || method.toLowerCase() === 'get') req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); + if (typeof(data) == 'object' || method.toLowerCase() === 'get') req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); if (data instanceof Multipart) req.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary); if (data) return req.send( data.result ? data.result : JSON.stringify(data) ); req.send(null); From 6245f1fd38674c3b5a287e0a60fcd208346fd94d Mon Sep 17 00:00:00 2001 From: izy521 Date: Sat, 28 Oct 2017 22:09:08 -0700 Subject: [PATCH 11/17] Merge pull request #138 from Adryd/patch-1 Allow users to set typing time in miliseconds when sending message --- lib/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index dcf06fce..2671b0ff 100644 --- a/lib/index.js +++ b/lib/index.js @@ -227,7 +227,7 @@ DCP.sendMessage = function(input, callback) { message.tts = (input.tts === true); message.nonce = input.nonce || message.nonce; - if (input.typing === true) { + if (typof input.typing === "boolean" && input.typing === true) { return simulateTyping( this, input.to, @@ -235,6 +235,14 @@ DCP.sendMessage = function(input, callback) { ( (message.content.length * 0.12) * 1000 ), callback ); + } else if (typof input.typing === "number") { + return simulateTyping( + this, + input.to, + message, + input.typing + callback + ); } sendMessage(this, input.to, message, callback); From cd10791c9caa51692de2edfaf4df6cac6804b77d Mon Sep 17 00:00:00 2001 From: izy521 Date: Sun, 29 Oct 2017 10:25:20 -0700 Subject: [PATCH 12/17] Merge pull request #217 from Seth177/patch-1 Fixed typo --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2671b0ff..cd243c79 100644 --- a/lib/index.js +++ b/lib/index.js @@ -227,7 +227,7 @@ DCP.sendMessage = function(input, callback) { message.tts = (input.tts === true); message.nonce = input.nonce || message.nonce; - if (typof input.typing === "boolean" && input.typing === true) { + if (typeof input.typing === "boolean" && input.typing === true) { return simulateTyping( this, input.to, @@ -235,7 +235,7 @@ DCP.sendMessage = function(input, callback) { ( (message.content.length * 0.12) * 1000 ), callback ); - } else if (typof input.typing === "number") { + } else if (typeof input.typing === "number") { return simulateTyping( this, input.to, From 416c7684a008386d39dc767cdea0c8c1ff0e9ddb Mon Sep 17 00:00:00 2001 From: izy521 Date: Sun, 29 Oct 2017 10:29:29 -0700 Subject: [PATCH 13/17] Merge pull request #218 from Seth177/patch-2 Someone forgot a comma too --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index cd243c79..08e05116 100644 --- a/lib/index.js +++ b/lib/index.js @@ -240,7 +240,7 @@ DCP.sendMessage = function(input, callback) { this, input.to, message, - input.typing + input.typing, callback ); } From af547c0c395c44a71f3167598ff2366a5cbd5243 Mon Sep 17 00:00:00 2001 From: izy521 Date: Sat, 28 Oct 2017 22:06:55 -0700 Subject: [PATCH 14/17] Merge pull request #216 from mastastealth/master Fixes DM Channel Issue --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 08e05116..b692f0df 100644 --- a/lib/index.js +++ b/lib/index.js @@ -928,7 +928,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.recipient_id] = res.body.id; handleResCB("Unable to create DM Channel", err, res, callback); }); }; From 6212c8586903fbd59f5c22b15a89be24492c4020 Mon Sep 17 00:00:00 2001 From: pix674 <38077439+pix674@users.noreply.github.com> Date: Thu, 5 Apr 2018 09:40:17 +0200 Subject: [PATCH 15/17] Allow GENERAL_MANAGE_WEBHOOKS & TEXT_ADD_REACTIONS in editChannelPermissions in function : editChannelPermissions - Add GENERAL_MANAGE_WEBHOOKS & TEXT_ADD_REACTIONS in allowed_values --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index b692f0df..7f4752d3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1008,8 +1008,8 @@ DCP.editChannelPermissions = function(input, callback) { //Will shrink this up l channel = this.channels[ input.channelID ]; permissions = channel.permissions[pType][ID] || { allow: 0, deny: 0 }; allowed_values = [0, 4, 28].concat((channel.type === 'text' ? - [10, 11, 12, 13, 14, 15, 16, 17, 18] : - [20, 21, 22, 23, 24, 25] )); + [6, 10, 11, 12, 13, 14, 15, 16, 17, 18] : + [20, 21, 22, 23, 24, 25, 29] )); //Take care of allow first if (type(input.allow) === 'array') { From 5f20a4c4e602787410b268aca2acae6ecc9d359b Mon Sep 17 00:00:00 2001 From: pix674 <38077439+pix674@users.noreply.github.com> Date: Thu, 5 Apr 2018 09:43:58 +0200 Subject: [PATCH 16/17] Add in permissions interface GENERAL_MANAGE_WEBHOOKS and TEXT_ADD_REACTIONS have been added to the permissions interface. --- typings/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index cef92bc7..19311154 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -97,7 +97,9 @@ declare interface permissions { GENERAL_MANAGE_ROLES?: boolean; GENERAL_MANAGE_NICKNAMES?: boolean; GENERAL_CHANGE_NICKNAME?: boolean; + GENERAL_MANAGE_WEBHOOKS?: boolean; + TEXT_ADD_REACTIONS?: boolean; TEXT_READ_MESSAGES?: boolean; TEXT_SEND_MESSAGES?: boolean; TEXT_SEND_TTS_MESSAGE?: boolean; From 68564d12e79acc24a105b70be76b4442e80c239f Mon Sep 17 00:00:00 2001 From: Brad Nakken <3517352+bradnak@users.noreply.github.com> Date: Thu, 11 Oct 2018 16:48:14 +1100 Subject: [PATCH 17/17] Add DMRecipient class type to describe DMChannel.recipient --- typings/index.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 19311154..e1860d9b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -407,11 +407,18 @@ declare namespace Discord { } export class DMChannel extends Resource { - recipient: Object; + recipient: DMRecipient; last_message_id: string; id: string; } + export class DMRecipient extends Resource { + username: string; + id: string; + discriminator: string; + avatar: string; + } + export class User extends Resource { username: string; id: string;