mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
add JDA activation codes with graalvm native image configures
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user