From b4dcd657cfb5bd97fa41b61c7b8ffa7c9de3bb03 Mon Sep 17 00:00:00 2001 From: Manuel Kraus Date: Sun, 29 May 2016 05:46:16 +0200 Subject: [PATCH] Add role mentioning (#385) * Add role mentioning * Add to docs * Forgot to save again --- docs/docs_role.rst | 7 ++++++- lib/Structures/Role.js | 9 +++++++++ src/Structures/Role.js | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/docs_role.rst b/docs/docs_role.rst index 1c2ca097b..4b1a7c552 100644 --- a/docs/docs_role.rst +++ b/docs/docs_role.rst @@ -70,4 +70,9 @@ Sees whether the role has the permission given. colorAsHex() ~~~~~~~~~~~~ -Returns the role's colour as hex, e.g. ``#FF0000``. \ No newline at end of file +Returns the role's colour as hex, e.g. ``#FF0000``. + +mention() +~~~~~~~~~ + +Returns a valid string that can be sent in a message to mention the role. By default, ``role.toString()`` does this so by adding a role object to a string, e.g. ``role + ""``, their mention code will be retrieved. If the role isn't mentionable, its name gets returned. \ No newline at end of file diff --git a/lib/Structures/Role.js b/lib/Structures/Role.js index 7264b5fa8..07d6539ad 100644 --- a/lib/Structures/Role.js +++ b/lib/Structures/Role.js @@ -166,6 +166,15 @@ var Role = (function () { return this.client.removeUserFromRole.apply(this.client, [member, this, callback]); }; + Role.prototype.mention = function mention() { + if (this.mentionable) return "<@&" + this.id + ">"; + return this.name; + }; + + Role.prototype.toString = function toString() { + return this.mention(); + }; + return Role; })(); diff --git a/src/Structures/Role.js b/src/Structures/Role.js index 8c13b6883..12b783ff3 100644 --- a/src/Structures/Role.js +++ b/src/Structures/Role.js @@ -160,4 +160,14 @@ export default class Role { removeUser(member, callback) { return this.client.removeUserFromRole.apply(this.client, [member, this, callback]); } + + mention(){ + if(this.mentionable) + return `<@&${this.id}>`; + return this.name; + } + + toString(){ + return this.mention(); + } }