From 43283eeaec2d30ed2b3e88b82b85b0b269d567da Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:15:51 -0500 Subject: [PATCH 1/7] Clean up search examples slightly --- src/structures/Guild.js | 6 ++---- src/structures/interface/TextBasedChannel.js | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 472166fbc..6ea55b92d 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -713,12 +713,10 @@ class Guild { * guild.search({ * content: 'discord.js', * before: '2016-11-17' - * }) - * .then(res => { + * }).then(res => { * const hit = res[0].find(m => m.hit).content; * console.log(`I found: **${hit}**`); - * }) - * .catch(console.error); + * }).catch(console.error); */ search(options) { return this.client.rest.methods.search(this, options); diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index 1249b57dc..47bc88409 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -223,12 +223,10 @@ class TextBasedChannel { * channel.search({ * content: 'discord.js', * before: '2016-11-17' - * }) - * .then(res => { + * }).then(res => { * const hit = res[0].find(m => m.hit).content; * console.log(`I found: **${hit}**`); - * }) - * .catch(console.error); + * }).catch(console.error); */ search(options) { return this.client.rest.methods.search(this, options); From eaf2091c2f56c91f1c9f2e81095665e6bea467fc Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:17:31 -0500 Subject: [PATCH 2/7] Rearrange some methods and improve search description --- src/structures/Guild.js | 116 +++++++++---------- src/structures/interface/TextBasedChannel.js | 2 +- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 6ea55b92d..b3b3ad1bf 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -362,6 +362,25 @@ class Guild { }); } + /** + * Performs a search within the entire guild. + * @param {MessageSearchOptions} [options={}] Options to pass to the search + * @returns {Promise>} + * An array containing arrays of messages. Each inner array is a search context cluster. + * The message which has triggered the result will have the `hit` property set to `true`. + * @example + * guild.search({ + * content: 'discord.js', + * before: '2016-11-17' + * }).then(res => { + * const hit = res[0].find(m => m.hit).content; + * console.log(`I found: **${hit}**`); + * }).catch(console.error); + */ + search(options) { + return this.client.rest.methods.search(this, options); + } + /** * The data for editing a guild * @typedef {Object} GuildEditData @@ -600,6 +619,45 @@ class Guild { return create.then(role => role.edit(data)); } + /** + * Set the position of a role in this guild + * @param {string|Role} role the role to edit, can be a role object or a role ID. + * @param {number} position the new position of the role + * @returns {Promise} + */ + setRolePosition(role, position) { + if (typeof role === 'string') { + role = this.roles.get(role); + if (!role) return Promise.reject(new Error('Supplied role is not a role or string.')); + } + + position = Number(position); + if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.')); + + const lowestAffected = Math.min(role.position, position); + const highestAffected = Math.max(role.position, position); + + const rolesToUpdate = this.roles.filter(r => r.position >= lowestAffected && r.position <= highestAffected); + + // stop role positions getting stupidly inflated + if (position > role.position) { + position = rolesToUpdate.first().position; + } else { + position = rolesToUpdate.last().position; + } + + const updatedRoles = []; + + for (const uRole of rolesToUpdate.values()) { + updatedRoles.push({ + id: uRole.id, + position: uRole.id === role.id ? position : uRole.position + (position < role.position ? 1 : -1), + }); + } + + return this.client.rest.methods.setRolePositions(this.id, updatedRoles); + } + /** * Creates a new custom emoji in the guild. * @param {BufferResolvable} attachment The image for the emoji. @@ -664,64 +722,6 @@ class Guild { return this.client.rest.methods.deleteGuild(this); } - /** - * Set the position of a role in this guild - * @param {string|Role} role the role to edit, can be a role object or a role ID. - * @param {number} position the new position of the role - * @returns {Promise} - */ - setRolePosition(role, position) { - if (typeof role === 'string') { - role = this.roles.get(role); - if (!role) return Promise.reject(new Error('Supplied role is not a role or string.')); - } - - position = Number(position); - if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.')); - - const lowestAffected = Math.min(role.position, position); - const highestAffected = Math.max(role.position, position); - - const rolesToUpdate = this.roles.filter(r => r.position >= lowestAffected && r.position <= highestAffected); - - // stop role positions getting stupidly inflated - if (position > role.position) { - position = rolesToUpdate.first().position; - } else { - position = rolesToUpdate.last().position; - } - - const updatedRoles = []; - - for (const uRole of rolesToUpdate.values()) { - updatedRoles.push({ - id: uRole.id, - position: uRole.id === role.id ? position : uRole.position + (position < role.position ? 1 : -1), - }); - } - - return this.client.rest.methods.setRolePositions(this.id, updatedRoles); - } - - /** - * Performs a search - * @param {MessageSearchOptions} [options={}] Options to pass to the search - * @returns {Promise>} - * An array containing arrays of messages. Each inner array is a search context cluster. - * The message which has triggered the result will have the `hit` property set to `true`. - * @example - * guild.search({ - * content: 'discord.js', - * before: '2016-11-17' - * }).then(res => { - * const hit = res[0].find(m => m.hit).content; - * console.log(`I found: **${hit}**`); - * }).catch(console.error); - */ - search(options) { - return this.client.rest.methods.search(this, options); - } - /** * Whether this Guild equals another Guild. It compares all properties, so for most operations * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index 47bc88409..dd763d7f0 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -214,7 +214,7 @@ class TextBasedChannel { } /** - * Performs a search + * Performs a search within the channel. * @param {MessageSearchOptions} [options={}] Options to pass to the search * @returns {Promise>} * An array containing arrays of messages. Each inner array is a search context cluster. From 2ea744c9d1c0e32ef144dee752158d194be3c296 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:19:15 -0500 Subject: [PATCH 3/7] Reestablish the natural order and heirarchy of all things --- src/structures/DMChannel.js | 2 +- src/structures/GroupDMChannel.js | 2 +- src/structures/TextChannel.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index cb6ceddbc..6af543dd6 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -45,6 +45,7 @@ class DMChannel extends Channel { fetchMessage() { return; } fetchMessages() { return; } fetchPinnedMessages() { return; } + search() { return; } startTyping() { return; } stopTyping() { return; } get typing() { return; } @@ -53,7 +54,6 @@ class DMChannel extends Channel { awaitMessages() { return; } bulkDelete() { return; } _cacheMessage() { return; } - search() { return; } } TextBasedChannel.applyToClass(DMChannel, true); diff --git a/src/structures/GroupDMChannel.js b/src/structures/GroupDMChannel.js index 4cdee3ccb..d6b5338d4 100644 --- a/src/structures/GroupDMChannel.js +++ b/src/structures/GroupDMChannel.js @@ -129,6 +129,7 @@ class GroupDMChannel extends Channel { fetchMessage() { return; } fetchMessages() { return; } fetchPinnedMessages() { return; } + search() { return; } startTyping() { return; } stopTyping() { return; } get typing() { return; } @@ -137,7 +138,6 @@ class GroupDMChannel extends Channel { awaitMessages() { return; } bulkDelete() { return; } _cacheMessage() { return; } - search() { return; } } TextBasedChannel.applyToClass(GroupDMChannel, true); diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index 395289ae9..0484c9716 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -81,6 +81,7 @@ class TextChannel extends GuildChannel { fetchMessage() { return; } fetchMessages() { return; } fetchPinnedMessages() { return; } + search() { return; } startTyping() { return; } stopTyping() { return; } get typing() { return; } @@ -89,7 +90,6 @@ class TextChannel extends GuildChannel { awaitMessages() { return; } bulkDelete() { return; } _cacheMessage() { return; } - search() { return; } } TextBasedChannel.applyToClass(TextChannel, true); From 4447e367f6ff453d499288b63da2ef913f3bc4d6 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:22:29 -0500 Subject: [PATCH 4/7] Fix other BufferResolvables with base64 --- src/structures/ClientUser.js | 2 +- src/structures/Guild.js | 4 ++-- src/structures/TextChannel.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 6a8532141..67e19f9c2 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -268,7 +268,7 @@ class ClientUser extends User { */ createGuild(name, region, icon = null) { if (!icon) return this.client.rest.methods.createGuild({ name, icon, region }); - if (icon.startsWith('data:')) { + if (typeof icon === 'string' && icon.startsWith('data:')) { return this.client.rest.methods.createGuild({ name, icon, region }); } else { return this.client.resolver.resolveBuffer(icon).then(data => diff --git a/src/structures/Guild.js b/src/structures/Guild.js index b3b3ad1bf..aa0f717ab 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -660,7 +660,7 @@ class Guild { /** * Creates a new custom emoji in the guild. - * @param {BufferResolvable} attachment The image for the emoji. + * @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji. * @param {string} name The name for the emoji. * @returns {Promise} The created emoji. * @example @@ -676,7 +676,7 @@ class Guild { */ createEmoji(attachment, name) { return new Promise(resolve => { - if (attachment.startsWith('data:')) { + if (typeof attachment === 'string' && attachment.startsWith('data:')) { resolve(this.client.rest.methods.createEmoji(this, attachment, name)); } else { this.client.resolver.resolveBuffer(attachment).then(data => diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index 0484c9716..6e98e9e89 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -53,7 +53,7 @@ class TextChannel extends GuildChannel { /** * Create a webhook for the channel. * @param {string} name The name of the webhook. - * @param {BufferResolvable} avatar The avatar for the webhook. + * @param {BufferResolvable|Base64Resolvable} avatar The avatar for the webhook. * @returns {Promise} webhook The created webhook. * @example * channel.createWebhook('Snek', 'http://snek.s3.amazonaws.com/topSnek.png') @@ -62,7 +62,7 @@ class TextChannel extends GuildChannel { */ createWebhook(name, avatar) { return new Promise(resolve => { - if (avatar.startsWith('data:')) { + if (typeof avatar === 'string' && avatar.startsWith('data:')) { resolve(this.client.rest.methods.createWebhook(this, name, avatar)); } else { this.client.resolver.resolveBuffer(avatar).then(data => From f72817fff5192bdf8984e5297b70a55f835e9375 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:39:37 -0500 Subject: [PATCH 5/7] Rewrote v11 upgrade guide --- docs/general/updating.md | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/general/updating.md b/docs/general/updating.md index d1087207e..d06085ec5 100644 --- a/docs/general/updating.md +++ b/docs/general/updating.md @@ -1,21 +1,31 @@ # Version 11 - -**Significant Additions (see the changelog for a full list):** +## Significant Additions +See [the changelog](https://github.com/hydrabolt/discord.js/releases/tag/11.0.0) for a full list. * Message Reactions and Embeds (rich text) * Support for uws and erlpack for better performance * OAuthApplication support +* Web distributions -### 1) Client.login() no longer supports logging in with email + password -Logging in with an email or password has been discouraged previously, mainly because of [this](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862), however we have made the decision to now remove all email and password logins in v11. Instead, you can use authentication tokens. You can find your token for a self-bot by entering `CTRL+SHIFT+I` in the Discord application, entering the console tab and executing `localStorage.token`. As always, you can get your token for real bot accounts [here.](https://discordapp.com/developers/applications/me) +## Client.login() no longer supports logging in with email + password +Logging in with an email and password has always been heavily discouraged since the advent of proper token support, but in v11 we have made the decision to completely remove the functionality, since Hammer & Chisel have [officially stated](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862) it simply shouldn't be done. -### 2) ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts -In order to change email, password or username on user accounts (self-bots), you need to now pass a password parameter to these methods (changes highlighted in documentation for ClientUser). +User accounts can still log in with tokens just like bot accounts. To obtain the token for a user account, you can log in to Discord with that account, and use Ctrl + Shift + I to open the developer tools. In the console tab, evaluating `localStorage.token` will give you the token for that account. -### 3) Removed TextBasedChannel.sendTTSMessage() -This method was redundant and has been removed as the same results can be achieved using sendMessage() +## ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts +Since you can no longer log in with email and password, you must provide the current account password to the `setEmail()`, `setPassword()`, and `setUsername()` methods for user accounts (self-bots). -### 4) Using Collection.find()/exists() with IDs will throw an error -To find something or check its existence using an ID, you should now use `.get()` and `.has()` which are part of a normal [Map.](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) +## Removed TextBasedChannel.sendTTSMessage() +This method was deemed to be an entirely pointless shortcut that virtually nobody even used. +The same results can be achieved by passing options to `send()` or `sendMessage()`. + +Example: +```js +channel.send('Hi there', { tts: true }); +``` + +### Using Collection.find()/exists() with IDs will throw an error +This is simply to help prevent a common mistake that is made frequently. +To find something or check its existence using an ID, you should use `.get()` and `.has()` which are part of the [ES6 Map class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map), which Collection is an extension of. # Version 10 Version 10's non-BC changes focus on cleaning up some inconsistencies that exist in previous versions. From 90f8cbd09ad7549421453ef2aec3e3247cc1bf0b Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:40:24 -0500 Subject: [PATCH 6/7] Add a header --- docs/general/updating.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/general/updating.md b/docs/general/updating.md index d06085ec5..bca2192f2 100644 --- a/docs/general/updating.md +++ b/docs/general/updating.md @@ -6,15 +6,16 @@ See [the changelog](https://github.com/hydrabolt/discord.js/releases/tag/11.0.0) * OAuthApplication support * Web distributions -## Client.login() no longer supports logging in with email + password +## Breaking changes +### Client.login() no longer supports logging in with email + password Logging in with an email and password has always been heavily discouraged since the advent of proper token support, but in v11 we have made the decision to completely remove the functionality, since Hammer & Chisel have [officially stated](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862) it simply shouldn't be done. User accounts can still log in with tokens just like bot accounts. To obtain the token for a user account, you can log in to Discord with that account, and use Ctrl + Shift + I to open the developer tools. In the console tab, evaluating `localStorage.token` will give you the token for that account. -## ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts +### ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts Since you can no longer log in with email and password, you must provide the current account password to the `setEmail()`, `setPassword()`, and `setUsername()` methods for user accounts (self-bots). -## Removed TextBasedChannel.sendTTSMessage() +### Removed TextBasedChannel.sendTTSMessage() This method was deemed to be an entirely pointless shortcut that virtually nobody even used. The same results can be achieved by passing options to `send()` or `sendMessage()`. From 8406e97e13bafedc2b727be4ab13f61462325645 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Fri, 30 Dec 2016 16:42:51 -0500 Subject: [PATCH 7/7] Add a little more info --- docs/general/updating.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/general/updating.md b/docs/general/updating.md index bca2192f2..cfcc27220 100644 --- a/docs/general/updating.md +++ b/docs/general/updating.md @@ -1,6 +1,8 @@ # Version 11 -## Significant Additions -See [the changelog](https://github.com/hydrabolt/discord.js/releases/tag/11.0.0) for a full list. +Version 11 contains loads of new and improved features, optimisations, and bug fixes. +See [the changelog](https://github.com/hydrabolt/discord.js/releases/tag/11.0.0) for a full list of changes. + +## Significant additions * Message Reactions and Embeds (rich text) * Support for uws and erlpack for better performance * OAuthApplication support