package nl.voidcorp.ottobot.commands.roles import nl.voidcorp.ottobot.command.* object LeaveRole : Command( "leaverole", aliases = listOf("derole"), location = CommandSource.GUILD, usage = "leaverole rolename", group = CommandGroup.ROLES, commandLevel = CommandLevel.VERIFIED ) { override fun handle(event: CommandMessage): CommandResult { if (event.params.drop(1).isEmpty()) return CommandResult.PARAMETERS val guild = getStore(event.guild!!.idLong) val toRemove = guild.roleMap.filterKeys { it in event.params.drop(1) } // toRemove.forEach { guild.roleMap.remove(it) } // val roleLongs = event.member!!.roles.map { it.idLong }.intersect(toRemove.values) val remove = roleLongs.map { event.guild.getRoleById(it) }.filter { it != null } val remmed = toRemove.filterValues { it in roleLongs }.keys remove.forEach { if (it != null) event.guild.removeRoleFromMember(event.member, it).queue() } event.reply("Removed the roles ${remmed.joinToString { "`$it`" }}") return CommandResult.SUCCESS } }