ottobotv2/src/main/kotlin/nl/voidcorp/discord/commands/roles/RemoveRoleCommand.kt

25 lines
969 B
Kotlin

package nl.voidcorp.discord.commands.roles
import nl.voidcorp.discord.command.*
import nl.voidcorp.discord.storage.GuildStore
import org.springframework.stereotype.Service
@Service
class RemoveRoleCommand : Command(
"removerole",
usage = "removerole rolename",
commandLevel = CommandLevel.MODERATOR,
location = CommandSource.GUILD,
group = CommandGroup.ADMIN
) {
override fun handle(event: CommandMessage): CommandResult {
if (event.params.drop(1).isEmpty()) return CommandResult.PARAMETERS
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
val toRemove = guild.roleMap.keys.intersect(event.params.drop(1))
toRemove.forEach { guild.roleMap.remove(it) }
repo.save(guild)
event.reply("Removed ${toRemove.size} roles from the list. ")
event.reply(toRemove.joinToString(prefix = "(", postfix = ")") { "`$it`" })
return CommandResult.SUCCESS
}
}