Skip to content

Commit

Permalink
fix: fixed remove command feature's exception
Browse files Browse the repository at this point in the history
  • Loading branch information
devproje committed Oct 7, 2024
1 parent 6cad37f commit a48e25b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions px32-bot-core/src/main/kotlin/net/projecttl/p/x32/Px32.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ fun main(args: Array<out String>) {
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class CoreKernel(token: String) {
}

fun kill() {
isActive = false

destroy()
logger.info("shutdown now Px32 kernel v${DefaultConfig.version}")
jda.shutdownNow()
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a48e25b

Please sign in to comment.