44 lines
1.7 KiB
Kotlin
44 lines
1.7 KiB
Kotlin
package nl.voidcorp.ottobot.commands.roles
|
|
|
|
import nl.voidcorp.ottobot.command.*
|
|
|
|
|
|
|
|
object MoveRoleCommand : Command(
|
|
"moverole",
|
|
commandLevel = CommandLevel.MODERATOR,
|
|
usage = "moverole [from] [to]",
|
|
location = CommandSource.GUILD,
|
|
group = CommandGroup.ROLES
|
|
) {
|
|
override fun handle(event: CommandMessage): CommandResult {
|
|
if (event.params.drop(2).isEmpty() || event.params.toSet().size != event.params.size) return CommandResult.PARAMETERS
|
|
val guild = getStore(event.guild!!.idLong)
|
|
val from = guild.roleMap[event.params[1]]
|
|
val to = guild.roleMap[event.params[2]]
|
|
if (from == null || to == null) {
|
|
event.reply("One of those roles does not exist...")
|
|
return CommandResult.PARAMETERS
|
|
}
|
|
val r1 = event.guild.getRoleById(from)
|
|
val r2 = event.guild.getRoleById(to)
|
|
val who = event.guild.members.filter { it.roles.contains(r1) }
|
|
who.forEach {
|
|
if (r1 != null)
|
|
event.guild.removeRoleFromMember(it, r1).reason("Swap roles").queue()
|
|
if (r2 != null) {
|
|
event.guild.addRoleToMember(it, r2).reason("Swap roles").queue()
|
|
}
|
|
}
|
|
|
|
// val toRemove = guild.roleMap.filterKeys { it in event.params.drop(1) }
|
|
//
|
|
// 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
|
|
// event.guild.controller.removeRolesFromMember(event.member, remove).queue()
|
|
// event.reply("Removed the roles ${remmed.joinToString { "`$it`" }}")
|
|
return CommandResult.SUCCESS
|
|
}
|
|
} |