From fef9f1c09ede294e92edbc5d14454000c9125513 Mon Sep 17 00:00:00 2001 From: Emily J Date: Wed, 28 Oct 2020 15:42:57 +1100 Subject: [PATCH] added functions to get role objects, display color --- bot/util/functions.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bot/util/functions.js b/bot/util/functions.js index 6869499..a54724d 100644 --- a/bot/util/functions.js +++ b/bot/util/functions.js @@ -33,6 +33,21 @@ class Functions { return '#' + n.slice(0, 6); } + roleObjects (guild, roles) { + const roleMap = roles.map(roleID => guild.roles.get(roleID)); + return roleMap.sort((a, b) => b.position - a.position); + } + + displayHexColour (guild, userID) { + const roles = this.roleObjects(guild, guild.members.get(userID).roles); + for (const object of roles) { + if (object.color !== 0) return '#' + object.color.toString(16); + } + + const colours = Object.keys(this.client.constants.colours); + return this.client.constants.colours[colours[ colours.length * Math.random() << 0]]; + } + highestRole (member) { if (member.roles.length === 0) return member.guild.roles.find(r => r.name === '@everyone');