Add a moverole command
This commit is contained in:
parent
ec30827b24
commit
98d300a9ef
|
@ -0,0 +1,45 @@
|
||||||
|
package nl.voidcorp.discord.commands.roles
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class 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 = repo.findByGuildId(event.guild!!.idLong) ?: GuildStore(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.controller.removeSingleRoleFromMember(it, r1).reason("Swap roles").queue()
|
||||||
|
if (r2 != null) {
|
||||||
|
event.guild.controller.addSingleRoleToMember(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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue