From 6318b432b6d7e4a207d2b2b6269ee9e8cb7df5f9 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sun, 4 Apr 2021 00:00:14 -0500 Subject: [PATCH] Improve update logging and fix logging colors --- index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 51bf217..30d7dd7 100644 --- a/index.js +++ b/index.js @@ -833,7 +833,7 @@ client.on('roleCreate', role => { const roleCreateEmbed = new Discord.MessageEmbed() .setTitle("Role Added") .addField("Name", role.name) - .addField("Permissions", role.permissions.bitfield) + .addField("Permissions", role.permissions.toArray().map(p => `\`${p}\``.toLowerCase()).join(' • ')) .addField("Mentionable", role.mentionable) .setFooter("Role ID: " + role.id) .setTimestamp() @@ -855,7 +855,7 @@ client.on('roleDelete', role => { const roleDeleteEmbed = new Discord.MessageEmbed() .setTitle("Role Removed") .addField("Name", role.name) - .addField("Permissions", role.permissions.bitfield) + .addField("Permissions", role.permissions.toArray().map(p => `\`${p}\``.toLowerCase()).join(' • ')) .addField("Mentionable", role.mentionable) .setFooter("Role ID: " + role.id) .setTimestamp() @@ -874,6 +874,8 @@ client.on('roleDelete', role => { }); client.on('roleUpdate', (oldRole, newRole) => { + const removedPerms = oldRole.permissions.filter(perm => !newRole.hasPermission(perm)); + const addedPerms = newRole.permissions.filter(perm => !oldRole.hasPermission(perm)); const roleUpdateEmbed = new Discord.MessageEmbed() .setTitle("Role Updated") .addField("Name", `${oldRole.name} >> ${newRole.name}`) @@ -882,6 +884,12 @@ client.on('roleUpdate', (oldRole, newRole) => { .setFooter("Role ID: " + newRole.id) .setTimestamp() .setColor('c9ff00'); + if (removedPerms.array().length > 0) { + roleUpdateEmbed.addField("Permissions Removed", removedPerms.map(p => `${p}`).join(' • ')); + } + if (addedPerms.array().length > 0) { + roleUpdateEmbed.addField("Permissions Added", addedPerms.map(p => `${p}`).join(' • ')); + } collection.findOne({ guild_id: newRole.guild.id }, (error, result) => { if (error) { console.error; @@ -954,7 +962,7 @@ client.on('guildMemberUpdate', (oldMember, newMember) => { .setFooter("Member ID: " + newMember.id) .setThumbnail(newMember.user.avatarURL()) .setTimestamp() - .setColor('e7778b'); + .setColor('c9ff00'); if (removedRoles) { memberUpdateEmbed.addField("Roles Removed", removedRoles.map(r => `${r}`).join(' • ')); }