Add the remaining role commands and disable listroles. Fix an issue with command permissions in private channels. Add help and make it print a list of commands.
This commit is contained in:
parent
8c39f6882f
commit
94970a3e6a
|
@ -49,25 +49,28 @@ abstract class Command(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun guildStuff(event: MessageReceivedEvent, str: String) =
|
private fun guildStuff(event: MessageReceivedEvent, str: String) =
|
||||||
if (isPermOK(commandLevel, getLevel(event.member!!))) try {
|
if (isPermOK(commandLevel, getLevel(event.member))) try {
|
||||||
handle(CommandMessage(event, translateCommandline(str)))
|
handle(CommandMessage(event, translateCommandline(str)))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
CommandResult.ERROR
|
CommandResult.ERROR
|
||||||
} else CommandResult.PERMISSIONS
|
} else CommandResult.PERMISSIONS
|
||||||
|
|
||||||
private fun privateStuff(event: MessageReceivedEvent, str: String) = try {
|
private fun privateStuff(event: MessageReceivedEvent, str: String) =
|
||||||
handle(CommandMessage(event, translateCommandline(str)))
|
if (isPermOK(commandLevel, getLevel(event.member))) try {
|
||||||
} catch (e: Exception) {
|
handle(CommandMessage(event, translateCommandline(str)))
|
||||||
e.printStackTrace()
|
} catch (e: Exception) {
|
||||||
CommandResult.ERROR
|
e.printStackTrace()
|
||||||
}
|
CommandResult.ERROR
|
||||||
|
} else {
|
||||||
|
CommandResult.PERMISSIONS
|
||||||
|
}
|
||||||
|
|
||||||
abstract fun handle(event: CommandMessage): CommandResult
|
abstract fun handle(event: CommandMessage): CommandResult
|
||||||
|
|
||||||
fun getLevel(member: Member): CommandLevel {
|
fun getLevel(member: Member?): CommandLevel {
|
||||||
|
if (member == null) return CommandGroup.ADMIN
|
||||||
val guildStore = repo.findByGuildId(member.guild.idLong) ?: GuildStore(-1)
|
val guildStore = repo.findByGuildId(member.guild.idLong) ?: GuildStore(-1)
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
member.user.idLong == creator.idLong -> CommandGroup.MAINTAINER
|
member.user.idLong == creator.idLong -> CommandGroup.MAINTAINER
|
||||||
member.hasPermission(Permission.ADMINISTRATOR)
|
member.hasPermission(Permission.ADMINISTRATOR)
|
||||||
|
@ -76,7 +79,7 @@ abstract class Command(
|
||||||
guildStore.moderatorRoles.intersect(member.roles.map { it.idLong }).isNotEmpty()
|
guildStore.moderatorRoles.intersect(member.roles.map { it.idLong }).isNotEmpty()
|
||||||
-> CommandGroup.MODERATOR
|
-> CommandGroup.MODERATOR
|
||||||
member.roles.isNotEmpty() or guildStore.defaultVerified -> CommandGroup.VERIFIED
|
member.roles.isNotEmpty() or guildStore.defaultVerified -> CommandGroup.VERIFIED
|
||||||
else -> CommandGroup.UNVERIFIED
|
else -> CommandGroup.ALL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ object CommandGroup {
|
||||||
val ADMIN = CommandLevel("Administrator", MAINTAINER)
|
val ADMIN = CommandLevel("Administrator", MAINTAINER)
|
||||||
val MODERATOR = CommandLevel("Moderator", ADMIN)
|
val MODERATOR = CommandLevel("Moderator", ADMIN)
|
||||||
val VERIFIED = CommandLevel("Verified", MODERATOR)
|
val VERIFIED = CommandLevel("Verified", MODERATOR)
|
||||||
val UNVERIFIED = CommandLevel("Unverified", VERIFIED)
|
val ALL = CommandLevel("Unverified", VERIFIED)
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import net.dv8tion.jda.api.MessageBuilder
|
||||||
import net.dv8tion.jda.api.entities.*
|
import net.dv8tion.jda.api.entities.*
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
|
|
||||||
|
|
||||||
data class CommandMessage(
|
data class CommandMessage(
|
||||||
private val event: MessageReceivedEvent,
|
private val event: MessageReceivedEvent,
|
||||||
val params: List<String>,
|
val params: List<String>,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
|
||||||
class DebugCommand(@Lazy private val list: List<Command>) : Command("debug", commandLevel = CommandGroup.MAINTAINER) {
|
class DebugCommand(@Lazy private val list: List<Command>) : Command("debug", commandLevel = CommandGroup.MAINTAINER) {
|
||||||
override fun handle(event: CommandMessage): CommandResult {
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
event.reply("DebugInfo")
|
event.reply("DebugInfo")
|
||||||
event.reply("Commands found: ${list.size}")
|
event.reply("Commands found: ${list.size + 1}")
|
||||||
event.reply(list.joinToString(prefix = "`debug`, ") { "`${it.name}`" })
|
event.reply(list.joinToString(prefix = "`debug`, ") { "`${it.name}`" })
|
||||||
event.reply("EndDebugInfo")
|
event.reply("EndDebugInfo")
|
||||||
return CommandResult.SUCCESS
|
return CommandResult.SUCCESS
|
||||||
|
|
17
src/main/kotlin/nl/voidcorp/discord/commands/HelpCommand.kt
Normal file
17
src/main/kotlin/nl/voidcorp/discord/commands/HelpCommand.kt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package nl.voidcorp.discord.commands
|
||||||
|
|
||||||
|
import nl.voidcorp.discord.command.Command
|
||||||
|
import nl.voidcorp.discord.command.CommandMessage
|
||||||
|
import nl.voidcorp.discord.command.CommandResult
|
||||||
|
import org.springframework.context.annotation.Lazy
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class HelpCommand(@Lazy private val list: List<Command>) : Command("help") {
|
||||||
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
|
event.reply("cursed_help")
|
||||||
|
val commands = list.filter { isPermOK(it.commandLevel, getLevel(event.member)) }
|
||||||
|
event.reply(commands.joinToString { "`${it.name}`" })
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package nl.voidcorp.discord.commands
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.Role
|
||||||
|
import nl.voidcorp.discord.command.*
|
||||||
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class JoinRoleCommand :
|
||||||
|
Command(
|
||||||
|
"joinrole",
|
||||||
|
aliases = listOf("role"),
|
||||||
|
commandLevel = CommandGroup.ALL,
|
||||||
|
usage = "joinrole [rolename]",
|
||||||
|
location = CommandSource.GUILD
|
||||||
|
) {
|
||||||
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
|
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
||||||
|
if (event.params.size == 1) {
|
||||||
|
if (guild.roleMap.isNotEmpty())
|
||||||
|
event.reply(guild.roleMap.keys.joinToString(prefix = "The available roles are: ") { "`$it`" })
|
||||||
|
else
|
||||||
|
event.reply("There are no roles to pick here...")
|
||||||
|
} else {
|
||||||
|
val fail = mutableListOf<String>()
|
||||||
|
val success = mutableListOf<String>()
|
||||||
|
val roles = mutableListOf<Role>()
|
||||||
|
for (p in event.params.drop(1)) {
|
||||||
|
val roleID = guild.roleMap[p]
|
||||||
|
if (roleID == null) {
|
||||||
|
fail += p
|
||||||
|
} else {
|
||||||
|
val role = event.guild.getRoleById(roleID)
|
||||||
|
if (role != null) {
|
||||||
|
success += p
|
||||||
|
roles += role
|
||||||
|
} else {
|
||||||
|
fail += p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.guild.controller.addRolesToMember(event.member!!, roles).queue()
|
||||||
|
if (success.isNotEmpty()) event.reply("I have given you the following roles: ${roles.joinToString { "`${it.name}`" }}!")
|
||||||
|
if (fail.isNotEmpty()) event.reply("I failed to find the following roles: ${fail.joinToString { "`$it`" }}")
|
||||||
|
}
|
||||||
|
return CommandResult.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,10 +7,9 @@ import nl.voidcorp.discord.storage.GuildRepo
|
||||||
import nl.voidcorp.discord.storage.GuildStore
|
import nl.voidcorp.discord.storage.GuildStore
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
class ListRolesCommand : Command("listroles", aliases = listOf("roles")) {
|
||||||
class ListRolesCommand(val guildRepo: GuildRepo) : Command("listroles", aliases = listOf("roles")) {
|
|
||||||
override fun handle(event: CommandMessage): CommandResult {
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
val guild = guildRepo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
val guild = repo.findByGuildId(event.guild.idLong) ?: GuildStore(event.guild.idLong)
|
||||||
if (guild.roleMap.isNotEmpty())
|
if (guild.roleMap.isNotEmpty())
|
||||||
event.reply(guild.roleMap.keys.joinToString(prefix = "The available roles are: ") { "`$it`" })
|
event.reply(guild.roleMap.keys.joinToString(prefix = "The available roles are: ") { "`$it`" })
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package nl.voidcorp.discord.commands
|
package nl.voidcorp.discord.commands
|
||||||
|
|
||||||
import nl.voidcorp.discord.command.Command
|
import nl.voidcorp.discord.command.*
|
||||||
import nl.voidcorp.discord.command.CommandMessage
|
|
||||||
import nl.voidcorp.discord.command.CommandResult
|
|
||||||
import nl.voidcorp.discord.command.CommandSource
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class PermissionLevelCommand : Command("permissions", location = CommandSource.GUILD) {
|
class PermissionLevelCommand :
|
||||||
|
Command("permissions", location = CommandSource.GUILD, commandLevel = CommandGroup.ALL) {
|
||||||
override fun handle(event: CommandMessage): CommandResult {
|
override fun handle(event: CommandMessage): CommandResult {
|
||||||
event.reply("Your highest permission level is `${getLevel(event.member!!).levelName}`")
|
event.reply("Your highest permission level is `${getLevel(event.member!!).levelName}`")
|
||||||
return CommandResult.SUCCESS
|
return CommandResult.SUCCESS
|
||||||
|
|
Loading…
Reference in a new issue