From 382598fac01513cd5f97e5e5093b5db44ad18d61 Mon Sep 17 00:00:00 2001 From: Ron Young Date: Sat, 3 Aug 2024 13:46:25 -0500 Subject: [PATCH 1/3] remove verified role on mute --- lib/commands/mutemenu.js | 6 +++++- lib/security.js | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/commands/mutemenu.js b/lib/commands/mutemenu.js index abec1a281..69514a76f 100644 --- a/lib/commands/mutemenu.js +++ b/lib/commands/mutemenu.js @@ -1,5 +1,5 @@ import { ContextMenuCommandBuilder } from '@discordjs/builders' -import { assignRole, buildUserDetail, removeRole } from '../security.js' +import { assignRole, buildUserDetail, removeRole, hasRole } from '../security.js' import config from '../config.js' import { ApplicationCommandType } from 'discord-api-types/v10' @@ -43,6 +43,10 @@ export default { await logs.send(`:mute: ${buildUserDetail(user)} was muted by **${interaction.user.tag}**.`) } + if (hasRole(member, config.roles.verified)) { + await removeRole(member, guild.roles, config.roles.verified) + } + return interaction.followUp(`${buildUserDetail(user)} was muted.`) } } diff --git a/lib/security.js b/lib/security.js index 4fa8b6e4c..6171fc3da 100644 --- a/lib/security.js +++ b/lib/security.js @@ -352,6 +352,10 @@ function resetMessageCache () { return Promise.resolve() } +function hasRole(member, roleName) { + return member.roles.cache.find(r => r.name.toLowerCase() === roleName) +} + async function ensureRoles (member, allRoles) { const roles = roleDb.get(member.id) @@ -364,9 +368,8 @@ async function ensureRoles (member, allRoles) { async function assignRole (member, allRoles, roleToGive) { const roleName = roleToGive.toLowerCase() - const hasRole = member.roles.cache.find(r => r.name.toLowerCase() === roleName) - if (hasRole) { + if (hasRole(member, roleToGive)) { return `Cannot assign role ${roleToGive} to user ${member.toString()}, user already has the role.` } @@ -433,6 +436,7 @@ export { assignRole, removeRole, ensureRoles, + hasRole, buildUserDetail, buildMessageDetail, isOurDeletion, From 82b41bb5331427d17138da92c9960e9833770627 Mon Sep 17 00:00:00 2001 From: Ron Young Date: Sat, 3 Aug 2024 13:49:43 -0500 Subject: [PATCH 2/3] fix style --- lib/security.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/security.js b/lib/security.js index 6171fc3da..6d8f342df 100644 --- a/lib/security.js +++ b/lib/security.js @@ -352,7 +352,7 @@ function resetMessageCache () { return Promise.resolve() } -function hasRole(member, roleName) { +function hasRole (member, roleName) { return member.roles.cache.find(r => r.name.toLowerCase() === roleName) } From 7965b77edbc2a458e338b7f911cd62829a4200a9 Mon Sep 17 00:00:00 2001 From: Ron Young Date: Sat, 3 Aug 2024 17:55:08 -0500 Subject: [PATCH 3/3] address feedback --- lib/commands/mutemenu.js | 6 ++---- lib/security.js | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/commands/mutemenu.js b/lib/commands/mutemenu.js index 69514a76f..a951f0fcc 100644 --- a/lib/commands/mutemenu.js +++ b/lib/commands/mutemenu.js @@ -1,5 +1,5 @@ import { ContextMenuCommandBuilder } from '@discordjs/builders' -import { assignRole, buildUserDetail, removeRole, hasRole } from '../security.js' +import { assignRole, buildUserDetail, removeRole } from '../security.js' import config from '../config.js' import { ApplicationCommandType } from 'discord-api-types/v10' @@ -43,9 +43,7 @@ export default { await logs.send(`:mute: ${buildUserDetail(user)} was muted by **${interaction.user.tag}**.`) } - if (hasRole(member, config.roles.verified)) { - await removeRole(member, guild.roles, config.roles.verified) - } + await removeRole(member, guild.roles, config.roles.verified) return interaction.followUp(`${buildUserDetail(user)} was muted.`) } diff --git a/lib/security.js b/lib/security.js index 6d8f342df..d487a1d16 100644 --- a/lib/security.js +++ b/lib/security.js @@ -369,7 +369,7 @@ async function ensureRoles (member, allRoles) { async function assignRole (member, allRoles, roleToGive) { const roleName = roleToGive.toLowerCase() - if (hasRole(member, roleToGive)) { + if (hasRole(member, roleName)) { return `Cannot assign role ${roleToGive} to user ${member.toString()}, user already has the role.` } @@ -404,9 +404,8 @@ async function assignRole (member, allRoles, roleToGive) { async function removeRole (member, allRoles, roleToRemove) { const roleName = roleToRemove.toLowerCase() - const foundRole = member.roles.cache.find(r => r.name.toLowerCase() === roleName) - if (!foundRole) { + if (!hasRole(member, roleName)) { return `Cannot remove role ${roleToRemove} from user ${member.toString()}, user already has the role.` } @@ -436,7 +435,6 @@ export { assignRole, removeRole, ensureRoles, - hasRole, buildUserDetail, buildMessageDetail, isOurDeletion,