ottobot-v3/src/main/kotlin/nl/voidcorp/ottobot/commands/management/RemoveAdminRoleCommand.kt

34 lines
1.2 KiB
Kotlin

package nl.voidcorp.ottobot.commands.management
import nl.voidcorp.ottobot.command.*
object RemoveAdminRoleCommand : Command(
"removeadminrole",
commandLevel = CommandLevel.ADMIN,
location = CommandSource.GUILD,
group = CommandGroup.ADMIN,
aliases = listOf("rar")
) {
val regex = "(?:<@&!?)?(\\d+)>?".toRegex()
override fun handle(event: CommandMessage): CommandResult {
if (event.params.drop(1).isEmpty()) return CommandResult.PARAMETERS
val guild = getStore(event.guild!!.idLong)
val l = mutableListOf<String>()
for (p in event.params.drop(1)) {
val res = regex.matchEntire(p)
if (res != null && res.groupValues.size == 2) {
if (guild.modifyAdminRole(res.groupValues[1].toLong(), true)) {
val role = event.guild.getRoleById(res.groupValues[1])?.name ?: "some role?"
l += role
} else event.reply("There is no role with id `${res.groupValues[1]}`")
}
}
if (l.isNotEmpty())
event.reply(l.joinToString(prefix = "Removed the following roles as admin roles: ") { "`$it`" })
return CommandResult.SUCCESS
}
}