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

36 lines
1.2 KiB
Kotlin

package nl.voidcorp.ottobot.commands.management
import nl.voidcorp.ottobot.command.*
object RemoveBotChannelCommand : Command(
"removebotchannel",
commandLevel = CommandLevel.ADMIN,
location = CommandSource.GUILD,
group = CommandGroup.ADMIN,
aliases = listOf( "rbc")
) {
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.modifyBotChannel(res.groupValues[1].toLong(), true)) {
val role = event.guild.getTextChannelById(res.groupValues[1])?.id ?: "some channel?"
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 channels as bot channels: ") { "<#$it>" })
return CommandResult.SUCCESS
}
}