From a48e25b33ea954e03ef3c24022627d546f0a5e47 Mon Sep 17 00:00:00 2001 From: Project_IO Date: Mon, 7 Oct 2024 15:38:49 +0900 Subject: [PATCH] fix: fixed remove command feature's exception --- gradle.properties | 2 +- .../src/main/kotlin/net/projecttl/p/x32/Px32.kt | 16 +++++++--------- .../net/projecttl/p/x32/kernel/CoreKernel.kt | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 829598d..f74aeb2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 group=net.projecttl -version=1.0.0-beta.1 +version=1.0.0-beta.2 ktor_version=2.3.12 log4j_version=2.23.1 diff --git a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/Px32.kt b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/Px32.kt index 72a3e60..d990cb2 100644 --- a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/Px32.kt +++ b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/Px32.kt @@ -33,21 +33,19 @@ fun main(args: Array) { if (args.contains("--remove-cmd")) { jda = kernel.build() try { - jda.retrieveCommands().queue { - if (it == null) { - return@queue - } + val list = jda.retrieveCommands().complete() + if (list.isEmpty()) { + return + } - it.forEach { command -> - logger.info("unregister command: /${command.name}") - command.jda.deleteCommandById(command.id).queue() - } + list.forEach { command -> + logger.info("unregister command: /${command.name}") + command.jda.deleteCommandById(command.id).complete() } } catch (ex: Exception) { ex.printStackTrace() } - kernel.kill() return } diff --git a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt index 2e60ee1..eed8d46 100644 --- a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt +++ b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt @@ -99,7 +99,10 @@ class CoreKernel(token: String) { } fun kill() { + isActive = false + destroy() + logger.info("shutdown now Px32 kernel v${DefaultConfig.version}") jda.shutdownNow() } @@ -210,10 +213,7 @@ class CoreKernel(token: String) { isActive = true Runtime.getRuntime().addShutdownHook(Thread { - isActive = false - - logger.info("shutdown now Px32 kernel v${DefaultConfig.version}") - jda.shutdownNow() + kill() }) return jda