diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/debug/DebugCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/debug/DebugCommand.kt index 253cd26..94ffac2 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/debug/DebugCommand.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/debug/DebugCommand.kt @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service @Service class DebugCommand(@Lazy private val list: List) : - 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 { event.reply("DebugInfo") event.reply("Commands found: ${list.size + 1}") diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/management/AdminRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/management/AdminRoleCommand.kt new file mode 100644 index 0000000..db9bb7b --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/management/AdminRoleCommand.kt @@ -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() + 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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/management/ModeratorRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/management/ModeratorRoleCommand.kt new file mode 100644 index 0000000..69f5a86 --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/management/ModeratorRoleCommand.kt @@ -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() + 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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveAdminRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveAdminRoleCommand.kt new file mode 100644 index 0000000..4832539 --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveAdminRoleCommand.kt @@ -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() + 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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveModeratorRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveModeratorRoleCommand.kt new file mode 100644 index 0000000..79f8bab --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/management/RemoveModeratorRoleCommand.kt @@ -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() + 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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/roles/AddRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/roles/AddRoleCommand.kt index be176ba..57d32c7 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/roles/AddRoleCommand.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/roles/AddRoleCommand.kt @@ -14,8 +14,8 @@ class AddRoleCommand : Command( ) { val regex = "([\\w\\d-_+]+):(?:<@&!?)?(\\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()) return CommandResult.PARAMETERS + val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong) val l = mutableListOf() for (p in event.params.drop(1)) { val res = regex.matchEntire(p)