Add admin and moderator role commands
This commit is contained in:
parent
003f27c5e3
commit
371e3e4d78
|
@ -6,7 +6,7 @@ import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class DebugCommand(@Lazy private val list: List<Command>) :
|
class DebugCommand(@Lazy private val list: List<Command>) :
|
||||||
Command("debug", commandLevel = CommandLevel.MAINTAINER, group = CommandGroup.`VERY HIDDEN CATEGORY lol`) {
|
Command("debug", commandLevel = CommandLevel.MAINTAINER, group = CommandGroup.VeRY_hIdden_CaTegoRY_LoL) {
|
||||||
override fun handle(event: CommandMessage): CommandResult {
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
event.reply("DebugInfo")
|
event.reply("DebugInfo")
|
||||||
event.reply("Commands found: ${list.size + 1}")
|
event.reply("Commands found: ${list.size + 1}")
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package nl.voidcorp.discord.commands.management
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class AdminRoleCommand : Command(
|
||||||
|
"addadminrole",
|
||||||
|
commandLevel = CommandLevel.ADMIN,
|
||||||
|
location = CommandSource.GUILD,
|
||||||
|
group = CommandGroup.ADMIN,
|
||||||
|
aliases = listOf("aar")
|
||||||
|
) {
|
||||||
|
|
||||||
|
val regex = "(?:<@&!?)?(\\d+)>?".toRegex()
|
||||||
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
|
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
||||||
|
if (event.params.drop(1).isEmpty()) {
|
||||||
|
val roles = guild.adminRoles.map { event.guild.getRoleById(it)?.name ?: "Missing role $it" }
|
||||||
|
.joinToString(prefix = "Admin roles: ") { "`$it`" }
|
||||||
|
event.reply(roles)
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
val l = mutableListOf<String>()
|
||||||
|
for (p in event.params.drop(1)) {
|
||||||
|
val res = regex.matchEntire(p)
|
||||||
|
if (res != null && res.groupValues.size == 2) {
|
||||||
|
if (event.guild.getRoleById(res.groupValues[1]) != null) {
|
||||||
|
guild.adminRoles.plusAssign(res.groupValues[1].toLong())
|
||||||
|
val role = event.guild.getRoleById(res.groupValues[1])!!
|
||||||
|
l += role.name
|
||||||
|
} else event.reply("There is no role with id `${res.groupValues[1]}`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo.save(guild)
|
||||||
|
if (l.isNotEmpty())
|
||||||
|
event.reply(l.joinToString(prefix = "Added the following roles as admin roles: ") { "`$it`" })
|
||||||
|
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package nl.voidcorp.discord.commands.management
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class ModeratorRoleCommand : Command(
|
||||||
|
"addmoderatorrole",
|
||||||
|
commandLevel = CommandLevel.ADMIN,
|
||||||
|
location = CommandSource.GUILD,
|
||||||
|
group = CommandGroup.ADMIN,
|
||||||
|
aliases = listOf("addmodrole", "amr")
|
||||||
|
|
||||||
|
) {
|
||||||
|
|
||||||
|
val regex = "(?:<@&!?)?(\\d+)>?".toRegex()
|
||||||
|
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 l = mutableListOf<String>()
|
||||||
|
for (p in event.params.drop(1)) {
|
||||||
|
val res = regex.matchEntire(p)
|
||||||
|
if (res != null && res.groupValues.size == 2) {
|
||||||
|
if (event.guild.getRoleById(res.groupValues[1]) != null) {
|
||||||
|
guild.moderatorRoles.plusAssign(res.groupValues[1].toLong())
|
||||||
|
val role = event.guild.getRoleById(res.groupValues[1])!!
|
||||||
|
l += role.name
|
||||||
|
} else event.reply("There is no role with id `${res.groupValues[1]}`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo.save(guild)
|
||||||
|
if (l.isNotEmpty())
|
||||||
|
event.reply(l.joinToString(prefix = "Added the following roles as moderator roles: ") { "`$it`" })
|
||||||
|
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package nl.voidcorp.discord.commands.management
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class RemoveAdminRoleCommand : Command(
|
||||||
|
"removeadminrole",
|
||||||
|
commandLevel = CommandLevel.ADMIN,
|
||||||
|
location = CommandSource.GUILD,
|
||||||
|
group = CommandGroup.ADMIN,
|
||||||
|
aliases = listOf( "rar")
|
||||||
|
|
||||||
|
) {
|
||||||
|
|
||||||
|
val regex = "(?:<@&!?)?(\\d+)>?".toRegex()
|
||||||
|
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 l = mutableListOf<String>()
|
||||||
|
for (p in event.params.drop(1)) {
|
||||||
|
val res = regex.matchEntire(p)
|
||||||
|
if (res != null && res.groupValues.size == 2) {
|
||||||
|
if (guild.adminRoles.contains(res.groupValues[1].toLong())) {
|
||||||
|
guild.adminRoles.minusAssign(res.groupValues[1].toLong())
|
||||||
|
val role = event.guild.getRoleById(res.groupValues[1])?.name ?: "some role?"
|
||||||
|
l += role
|
||||||
|
} else event.reply("There is no role with id `${res.groupValues[1]}`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo.save(guild)
|
||||||
|
if (l.isNotEmpty())
|
||||||
|
event.reply(l.joinToString(prefix = "Removed the following roles as admin roles: ") { "`$it`" })
|
||||||
|
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package nl.voidcorp.discord.commands.management
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class RemoveModeratorRoleCommand : Command(
|
||||||
|
"removemoderatorrole",
|
||||||
|
commandLevel = CommandLevel.ADMIN,
|
||||||
|
location = CommandSource.GUILD,
|
||||||
|
group = CommandGroup.ADMIN,
|
||||||
|
aliases = listOf("removemodrole", "rmr")
|
||||||
|
) {
|
||||||
|
|
||||||
|
val regex = "(?:<@&!?)?(\\d+)>?".toRegex()
|
||||||
|
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 l = mutableListOf<String>()
|
||||||
|
for (p in event.params.drop(1)) {
|
||||||
|
val res = regex.matchEntire(p)
|
||||||
|
if (res != null && res.groupValues.size == 2) {
|
||||||
|
if (guild.adminRoles.contains(res.groupValues[1].toLong())) {
|
||||||
|
guild.adminRoles.minusAssign(res.groupValues[1].toLong())
|
||||||
|
val role = event.guild.getRoleById(res.groupValues[1])?.name ?: "some role?"
|
||||||
|
l += role
|
||||||
|
} else event.reply("There is no role with id `${res.groupValues[1]}`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo.save(guild)
|
||||||
|
if (l.isNotEmpty())
|
||||||
|
event.reply(l.joinToString(prefix = "Removed the following roles as admin roles: ") { "`$it`" })
|
||||||
|
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,8 +14,8 @@ class AddRoleCommand : Command(
|
||||||
) {
|
) {
|
||||||
val regex = "([\\w\\d-_+]+):(?:<@&!?)?(\\d+)>?".toRegex()
|
val regex = "([\\w\\d-_+]+):(?:<@&!?)?(\\d+)>?".toRegex()
|
||||||
override fun handle(event: CommandMessage): CommandResult {
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
|
||||||
if (event.params.drop(1).isEmpty()) return CommandResult.PARAMETERS
|
if (event.params.drop(1).isEmpty()) return CommandResult.PARAMETERS
|
||||||
|
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
||||||
val l = mutableListOf<String>()
|
val l = mutableListOf<String>()
|
||||||
for (p in event.params.drop(1)) {
|
for (p in event.params.drop(1)) {
|
||||||
val res = regex.matchEntire(p)
|
val res = regex.matchEntire(p)
|
||||||
|
|
Loading…
Reference in a new issue