43 lines
1.7 KiB
Kotlin
43 lines
1.7 KiB
Kotlin
package nl.voidcorp.ottobot.commands.roles
|
|
|
|
import nl.voidcorp.ottobot.command.*
|
|
|
|
|
|
|
|
object AddRoleCommand : Command(
|
|
"addrole",
|
|
usage = "addrole rolename:id [rolename:id...]",
|
|
commandLevel = CommandLevel.MODERATOR,
|
|
location = CommandSource.GUILD,
|
|
group = CommandGroup.ADMIN
|
|
) {
|
|
val regex = "([\\w\\d-_+]+):(?:<@&!?)?(\\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 == 3) {
|
|
when {
|
|
res.groupValues[1].length > 200 -> event.reply("Please use a shorter role name in the future (200 char max)")
|
|
guild.roleMap.containsKey(res.groupValues[1]) ->
|
|
event.reply(
|
|
"A role with the key `${res.groupValues[1]
|
|
}` is already mapped, if you want to remap it use `${guild.prefix}removerole ${res.groupValues[1]}` first..."
|
|
)
|
|
event.guild.getRoleById(res.groupValues[2]) != null -> {
|
|
guild.roleMap[res.groupValues[1]] = res.groupValues[2].toLong()
|
|
l += res.groupValues[1]
|
|
}
|
|
else -> event.reply("There is no role with id `${res.groupValues[2]}`")
|
|
}
|
|
}
|
|
}
|
|
|
|
if (l.isNotEmpty())
|
|
event.reply(l.joinToString(prefix = "Added the following groups: ") { "`$it`" })
|
|
|
|
return CommandResult.SUCCESS
|
|
}
|
|
} |