Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove verified role on mute #117

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/commands/mutemenu.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
}
raiyni marked this conversation as resolved.
Show resolved Hide resolved

return interaction.followUp(`${buildUserDetail(user)} was muted.`)
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)) {
raiyni marked this conversation as resolved.
Show resolved Hide resolved
return `Cannot assign role ${roleToGive} to user ${member.toString()}, user already has the role.`
}

Expand Down Expand Up @@ -433,6 +436,7 @@ export {
assignRole,
removeRole,
ensureRoles,
hasRole,
buildUserDetail,
buildMessageDetail,
isOurDeletion,
Expand Down
Loading