diff --git a/commands.md b/commands.md index d0597d1..955a8fc 100644 --- a/commands.md +++ b/commands.md @@ -28,9 +28,9 @@ | nick | LowerMemberArg, Theme, [Nickname] | Set a member's nickname | ## ReactionRole -| Commands | Arguments | Description | -|--------------------|-------------------------|------------------------------| -| createReactionRole | Roles, EmbedDescription | Create a reaction role embed | +| Commands | Arguments | Description | +|--------------------|------------------------------------------|------------------------------| +| createReactionRole | Roles, EmbedDescription, [AllowMultiple] | Create a reaction role embed | ## Utility | Commands | Arguments | Description | diff --git a/src/main/kotlin/me/ddivad/hawk/commands/ReactionRoleCommands.kt b/src/main/kotlin/me/ddivad/hawk/commands/ReactionRoleCommands.kt index b3ea3b8..f50b947 100644 --- a/src/main/kotlin/me/ddivad/hawk/commands/ReactionRoleCommands.kt +++ b/src/main/kotlin/me/ddivad/hawk/commands/ReactionRoleCommands.kt @@ -6,6 +6,7 @@ import me.ddivad.hawk.dataclasses.ReactionRole import me.ddivad.hawk.embeds.createReactionRoleMenu import me.ddivad.hawk.services.LoggingService import me.ddivad.hawk.services.buildGuildLogMessage +import me.jakejmattson.discordkt.arguments.BooleanArg import me.jakejmattson.discordkt.arguments.EveryArg import me.jakejmattson.discordkt.commands.commands import me.jakejmattson.discordkt.dsl.edit @@ -19,18 +20,20 @@ fun reactionRoleCommands(configuration: Configuration, loggingService: LoggingSe slash("createReactionRole", "Create a reaction role embed", Permissions.ADMINISTRATOR) { execute( EveryArg("Roles", "Role IDs to be added. If using multiple roles, separate IDs with a space"), - EveryArg("EmbedDescription", "Text to be added to reaction role embed") + EveryArg("EmbedDescription", "Text to be added to reaction role embed"), + BooleanArg("AllowMultiple", "yes", "no", "Allow more than 1 role to be chosen. Defualts to yes").optional(true) ) { - val (roleIds, descriptionText) = args + val (roleIds, descriptionText, allowMultiple) = args try { - val roles = roleIds.split(" ").map { guild.getRole(it.toSnowflake()) } val guildConfig = configuration[guild.id] ?: return@execute + val roles = roleIds.split(" ").map { guild.getRole(it.toSnowflake()) } val reactionRole = ReactionRole( guildConfig.reactionRoles.size + 1, descriptionText, roles.map { it.id }.toMutableList(), null, - channel.id + channel.id, + allowMultiple ) reactionRole.messageId = respondMenu { createReactionRoleMenu(discord, guild, reactionRole) @@ -40,7 +43,7 @@ fun reactionRoleCommands(configuration: Configuration, loggingService: LoggingSe } respond("Reaction role created") } catch (e: Exception) { - respond("Error parsing roles. Make sure IDs $roleIds are valid roles and separated by ` ` if adding multiple roles.") + respond("Error parsing roles. Make sure role IDs $roleIds are valid roles and separated by ` ` if adding multiple roles.") logger.error(e) { buildGuildLogMessage(guild, "Failed to parse roles") } } } diff --git a/src/main/kotlin/me/ddivad/hawk/dataclasses/Configuration.kt b/src/main/kotlin/me/ddivad/hawk/dataclasses/Configuration.kt index 4a80a90..661d8b1 100644 --- a/src/main/kotlin/me/ddivad/hawk/dataclasses/Configuration.kt +++ b/src/main/kotlin/me/ddivad/hawk/dataclasses/Configuration.kt @@ -75,5 +75,6 @@ data class ReactionRole( val description: String, val roles: MutableList, var messageId: Snowflake?, - val channel: Snowflake + val channel: Snowflake, + val allowMultiple: Boolean = true ) \ No newline at end of file diff --git a/src/main/kotlin/me/ddivad/hawk/embeds/ReactionRole.kt b/src/main/kotlin/me/ddivad/hawk/embeds/ReactionRole.kt index f326403..78e9bd7 100644 --- a/src/main/kotlin/me/ddivad/hawk/embeds/ReactionRole.kt +++ b/src/main/kotlin/me/ddivad/hawk/embeds/ReactionRole.kt @@ -23,12 +23,19 @@ suspend fun MenuBuilder.createReactionRoleMenu(discord: Discord, guild: Guild, r } buttons { runBlocking { - reactionRole.roles.forEach { - val liveRole = guild.getRole(it) + reactionRole.roles.forEach { role -> + val liveRole = guild.getRole(role) actionButton(liveRole.name, null) { val member = guild.getMemberOrNull(this.user.id) ?: return@actionButton - if (!member.roles.toList().contains(liveRole)) { + if (!member.roleIds.contains(role)) { + if (!reactionRole.allowMultiple) { + reactionRole.roles.forEach { role -> + if (member.roleIds.contains(role)) { + member.removeRole(role) + } + } + } member.addRole(liveRole.id, "Reaction button clicked") respondEphemeral { content = "Assigned role ${liveRole.name}" } loggingService.reactionRoleAdded(guild, member, liveRole) diff --git a/src/main/kotlin/me/ddivad/hawk/services/StartupService.kt b/src/main/kotlin/me/ddivad/hawk/services/StartupService.kt index 9b3dd47..9392c9a 100644 --- a/src/main/kotlin/me/ddivad/hawk/services/StartupService.kt +++ b/src/main/kotlin/me/ddivad/hawk/services/StartupService.kt @@ -1,6 +1,7 @@ package me.ddivad.hawk.services import dev.kord.core.behavior.getChannelOfOrNull +import dev.kord.core.entity.channel.GuildMessageChannel import dev.kord.core.entity.channel.TextChannel import me.ddivad.hawk.dataclasses.Configuration import me.ddivad.hawk.embeds.createReactionRoleMenu @@ -29,7 +30,7 @@ class StartupService( } guildConfig.reactionRoles.forEach { - val channel = guild.getChannelOfOrNull(it.channel) ?: return + val channel = guild.getChannelOfOrNull(it.channel) ?: return val message = channel.getMessageOrNull(it.messageId!!) ?: return logger.info { buildGuildLogMessage( diff --git a/src/main/resources/bot.properties b/src/main/resources/bot.properties index 5b80b2c..0495c5a 100644 --- a/src/main/resources/bot.properties +++ b/src/main/resources/bot.properties @@ -1,5 +1,5 @@ -#Sat Apr 01 18:01:31 IST 2023 +#Fri Mar 29 00:53:13 GMT 2024 name=Hawk description=A bot to add and maintain a symbol as a prefix or suffix in staff names.\n -version=3.0.0-RC1 +version=3.1 url=https\://github.com/the-programmers-hangout/Hawk/