mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
give up graalvm native image.
This commit is contained in:
@@ -3,33 +3,9 @@ package space.mori.chzzk_bot.discord
|
||||
import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData
|
||||
import org.reflections.Reflections
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Command
|
||||
|
||||
interface CommandInterface {
|
||||
val name: String
|
||||
fun run(event: SlashCommandInteractionEvent, bot: JDA): Unit
|
||||
val command: CommandData
|
||||
}
|
||||
|
||||
fun getCommands(): List<CommandInterface> {
|
||||
val commandList = mutableListOf<CommandInterface>()
|
||||
|
||||
val packageName = "space.mori.chzzk_bot.discord.commands"
|
||||
val reflections = Reflections(packageName)
|
||||
val annotatedClasses = reflections.getTypesAnnotatedWith(Command::class.java)
|
||||
|
||||
for(clazz in annotatedClasses) {
|
||||
val obj = clazz.kotlin.objectInstance
|
||||
if(obj is CommandInterface) {
|
||||
commandList.add(obj)
|
||||
} else {
|
||||
throw IllegalStateException("${clazz.name} is not a CommandInterface")
|
||||
}
|
||||
}
|
||||
|
||||
return commandList.toList()
|
||||
}
|
@@ -8,17 +8,26 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||
import space.mori.chzzk_bot.dotenv
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.discord.commands.*
|
||||
|
||||
class Discord: ListenerAdapter() {
|
||||
private lateinit var bot: JDA
|
||||
private var guild: Guild? = null
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
|
||||
private val commands = getCommands()
|
||||
private val commands = listOf(
|
||||
AddCommand,
|
||||
PingCommand,
|
||||
RegisterCommand,
|
||||
RemoveCommand,
|
||||
UpdateCommand,
|
||||
)
|
||||
|
||||
override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) {
|
||||
event.deferReply().queue()
|
||||
commands.find { it.name == event.name }?.run(event, bot)
|
||||
val handler = commands.find { it.name == event.name }
|
||||
logger.debug("Handler: ${handler?.name ?: "undefined"} command")
|
||||
handler?.run(event, bot)
|
||||
}
|
||||
|
||||
internal fun enable() {
|
||||
@@ -33,7 +42,10 @@ class Discord: ListenerAdapter() {
|
||||
|
||||
bot.updateCommands()
|
||||
.addCommands(* commands.map { it.command }.toTypedArray())
|
||||
.onSuccess { logger.info("Command update success!") }
|
||||
.onSuccess {
|
||||
logger.info("Command update success!")
|
||||
logger.debug("Command list: ${commands.joinToString("/ ") { it.name }}")
|
||||
}
|
||||
.queue()
|
||||
|
||||
|
||||
|
@@ -8,12 +8,10 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chzzk.ChzzkHandler
|
||||
import space.mori.chzzk_bot.chzzk.Connector
|
||||
import space.mori.chzzk_bot.discord.Command
|
||||
import space.mori.chzzk_bot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.services.CommandService
|
||||
import space.mori.chzzk_bot.services.UserService
|
||||
|
||||
@Command
|
||||
object AddCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "add"
|
||||
|
@@ -4,11 +4,9 @@ import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.discord.Command
|
||||
import space.mori.chzzk_bot.discord.CommandInterface
|
||||
|
||||
@Command()
|
||||
object Ping: CommandInterface {
|
||||
object PingCommand: CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name = "ping"
|
||||
override val command = Commands.slash(name, "봇이 살아있을까요?")
|
@@ -8,12 +8,10 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chzzk.ChzzkHandler
|
||||
import space.mori.chzzk_bot.chzzk.Connector
|
||||
import space.mori.chzzk_bot.discord.Command
|
||||
import space.mori.chzzk_bot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.services.UserService
|
||||
|
||||
@Command
|
||||
object Register: CommandInterface {
|
||||
object RegisterCommand: CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name = "register"
|
||||
override val command = Commands.slash(name, "치지직 계정을 등록합니다.")
|
@@ -8,12 +8,10 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chzzk.ChzzkHandler
|
||||
import space.mori.chzzk_bot.chzzk.Connector
|
||||
import space.mori.chzzk_bot.discord.Command
|
||||
import space.mori.chzzk_bot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.services.CommandService
|
||||
import space.mori.chzzk_bot.services.UserService
|
||||
|
||||
@Command
|
||||
object RemoveCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "remove"
|
||||
|
@@ -8,13 +8,10 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chzzk.ChzzkHandler
|
||||
import space.mori.chzzk_bot.chzzk.Connector
|
||||
import space.mori.chzzk_bot.discord.Command
|
||||
import space.mori.chzzk_bot.discord.CommandInterface
|
||||
import space.mori.chzzk_bot.services.CommandService
|
||||
import space.mori.chzzk_bot.services.UserService
|
||||
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
|
||||
|
||||
@Command
|
||||
object UpdateCommand : CommandInterface {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
override val name: String = "update"
|
||||
|
Reference in New Issue
Block a user