From 636a095377880e14e792629ab2fd53807f7b8bf3 Mon Sep 17 00:00:00 2001 From: Brussell Date: Wed, 1 Jun 2016 23:35:32 -0500 Subject: [PATCH] Add disableEveryone option (#400) * Added support for new game objects bot.setStreaming(name, url, type, callback); added logic for Internal setStatus updated to check if string or object * Add disableEveryone option * forgot to compile oh well, it can be squash merged --- docs/docs_client.rst | 6 ++++++ lib/Client/Client.js | 1 + lib/Client/InternalClient.js | 7 +++++++ src/Client/Client.js | 1 + src/Client/InternalClient.js | 7 +++++++ 5 files changed, 22 insertions(+) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 26357841d..457904d05 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -49,6 +49,11 @@ rateLimitAsError Have the lib throw a rejection Promise/callback when being ratelimited, instead of auto-retrying. +disableEveryone +~~~~~~~~~~~~~~~~ + +Have the lib insert a zero width space between here and everyone mentions disabling them. + shardCount ~~~~~~~~~~ @@ -195,6 +200,7 @@ Sends a message to the specified channel. - **file** - (Optional) `object`, containing: - **file** - a `File Resolvable`_ - **name** - (Optional) `String`, filename to upload file as + - **disableEveryone** - (Optional) `Boolean`, disable `here` and `everyone` mentions - **callback** - `function` that takes the following parameters: - **error** - error object if any occurred - **message** - the sent Message_ diff --git a/lib/Client/Client.js b/lib/Client/Client.js index c9cbc265a..51150d777 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -79,6 +79,7 @@ var Client = (function (_EventEmitter) { this.options.guildCreateTimeout = options.guildCreateTimeout || 1000; this.options.shardId = options.shardId || 0; this.options.shardCount = options.shardCount || 0; + this.options.disableEveryone = options.disableEveryone || false; if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) { this.options.shard = [options.shardId, options.shardCount]; diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 81d9439d7..055c88585 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -727,6 +727,10 @@ var InternalClient = (function () { return this.resolver.resolveChannel(where).then(function (destination) { var content = _this15.resolver.resolveString(_content); + if (_this15.client.options.disableEveryone || options.disableEveryone) { + content = content.replace(/(@)(everyone|here)/g, "$1​$2"); + } + if (options.file) { return _this15.resolver.resolveFile(options.file.file).then(function (file) { return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, { @@ -770,6 +774,9 @@ var InternalClient = (function () { content = { content: this.resolver.resolveString(content) }; + if (this.client.options.disableEveryone) { + content.content = content.content.replace(/(@)(everyone|here)/g, "$1​$2"); + } } return this.resolver.resolveChannel(where).then(function (channel) { diff --git a/src/Client/Client.js b/src/Client/Client.js index 832210f2d..cc8389d3b 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -53,6 +53,7 @@ export default class Client extends EventEmitter { this.options.guildCreateTimeout = options.guildCreateTimeout || 1000; this.options.shardId = options.shardId || 0; this.options.shardCount = options.shardCount || 0; + this.options.disableEveryone = options.disableEveryone || false; if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) { this.options.shard = [options.shardId, options.shardCount]; diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 5142d8f45..e0f43d755 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -616,6 +616,10 @@ export default class InternalClient { .then(destination => { var content = this.resolver.resolveString(_content); + if (this.client.options.disableEveryone || options.disableEveryone) { + content = content.replace(/(@)(everyone|here)/g, '$1\u200b$2'); + } + if (options.file) { return this.resolver.resolveFile(options.file.file) .then(file => @@ -655,6 +659,9 @@ export default class InternalClient { content = { content: this.resolver.resolveString(content) }; + if (this.client.options.disableEveryone) { + content.content = content.content.replace(/(@)(everyone|here)/g, '$1\u200b$2'); + } } return this.resolver.resolveChannel(where)