mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 14:58:21 +00:00
add JDA activation codes with graalvm native image configures
This commit is contained in:
parent
8d47bc0bd4
commit
d398f4f1a0
2
.gitignore
vendored
2
.gitignore
vendored
@ -241,4 +241,6 @@ gradle-app.setting
|
||||
# Java heap dump
|
||||
*.hprof
|
||||
|
||||
.env
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,linux,kotlin,gradle,intellij
|
1
.idea/modules/chzzk_bot.main.iml
generated
1
.idea/modules/chzzk_bot.main.iml
generated
@ -3,6 +3,7 @@
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$/../../src/main" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
@ -14,11 +14,23 @@ java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("${"${project.group}.${project.name}".lowercase()}.MainKt")
|
||||
}
|
||||
|
||||
graalvmNative {
|
||||
agent {
|
||||
trackReflectionMetadata.set(true)
|
||||
|
||||
metadataCopy {
|
||||
outputDirectories.add("src/main/resources/META-INF/native-image")
|
||||
mergeWithExisting.set(true)
|
||||
}
|
||||
}
|
||||
binaries {
|
||||
binaries.all {
|
||||
resources.autodetect()
|
||||
@ -28,6 +40,9 @@ graalvmNative {
|
||||
sharedLibrary.set(false)
|
||||
}
|
||||
}
|
||||
metadataRepository {
|
||||
enabled.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -41,6 +56,9 @@ dependencies {
|
||||
}
|
||||
// https://mvnrepository.com/artifact/io.github.R2turnTrue/chzzk4j
|
||||
implementation("io.github.R2turnTrue:chzzk4j:0.0.7")
|
||||
implementation("ch.qos.logback:logback-classic:1.4.14")
|
||||
|
||||
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
|
||||
|
||||
kotlin("stdlib-jdk8")
|
||||
}
|
||||
|
6
reflect-config.json
Normal file
6
reflect-config.json
Normal file
@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"name": "net.dv8tion.jda.api.entities.Guild[]",
|
||||
"unsafeAllocated": true
|
||||
}
|
||||
]
|
@ -1,5 +1,15 @@
|
||||
package space.mori.chzzk_bot
|
||||
|
||||
import io.github.cdimascio.dotenv.dotenv
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.discord.Discord
|
||||
|
||||
val dotenv = dotenv()
|
||||
val logger: Logger = LoggerFactory.getLogger("main")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(args.joinToString("/"))
|
||||
val discord = Discord()
|
||||
|
||||
discord.enable()
|
||||
}
|
48
src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt
Normal file
48
src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt
Normal file
@ -0,0 +1,48 @@
|
||||
package space.mori.chzzk_bot.discord
|
||||
|
||||
import net.dv8tion.jda.api.JDA
|
||||
import net.dv8tion.jda.api.JDABuilder
|
||||
import net.dv8tion.jda.api.entities.Activity
|
||||
import net.dv8tion.jda.api.entities.Guild
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands
|
||||
import space.mori.chzzk_bot.dotenv
|
||||
import space.mori.chzzk_bot.logger
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class Discord {
|
||||
lateinit var bot: JDA
|
||||
var guild: Guild? = null
|
||||
|
||||
internal fun enable() {
|
||||
try {
|
||||
val thread = thread {
|
||||
bot = JDABuilder.createDefault(dotenv["DISCORD_TOKEN"])
|
||||
.setActivity(Activity.playing("치지직 보는중"))
|
||||
.build().awaitReady()
|
||||
|
||||
guild = bot.getGuildById(dotenv["GUILD_ID"])
|
||||
|
||||
bot.updateCommands().addCommands(
|
||||
Commands.slash("ping", "Pong!")
|
||||
).queue()
|
||||
|
||||
if (guild == null) {
|
||||
logger.info("No guild found!")
|
||||
this.disable()
|
||||
}
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
logger.info("Could not enable Discord!")
|
||||
logger.debug(e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
|
||||
internal fun disable() {
|
||||
try {
|
||||
bot.shutdown()
|
||||
} catch(e: Exception) {
|
||||
logger.info("Error while shutting down Discord!")
|
||||
logger.debug(e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user