diff --git a/README.md b/README.md index 679378d..e325a5b 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,27 @@ - [x] /register chzzk_id: \[치지직 고유ID] - [x] /alert channel: \[디스코드 Channel ID] content: \[알림 내용] - [x] /add label: \[명령어] content: \[내용] +- [ ] /list - [x] /update label: \[명령어] content: \[내용] - [x] /delete label: \[명령어] +### 매니저 명령어 (on Discord) +- [x] /addmanager user: \[Discord user] +- [x] /listmanager +- [x] /removemanager user: \[Discord user] ### 관리 명령어 (on Chzzk chat) - [x] !명령어추가 \[명령어] \[내용] - [x] !명령어수정 \[명령어] \[내용] - [x] !명령어삭제 \[명령어] +### Envs +- DISCORD_TOKEN +- DB_URL +- DB_USER +- DB_PASS +- RUN_AGENT = `false` +- NID_AUT +- NID_SES + ### 사용 예시 - 팔로우 - `/add label: !팔로우 content: 님은 오늘로 일째 팔로우네요!` diff --git a/gradle.properties b/gradle.properties index ccac0f4..61201d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ kotlin.code.style=official group = space.mori -version = 1.0.0 +version = 1.0.1 org.gradle.jvmargs=-Dfile.encoding=UTF-8 org.gradle.console=plain diff --git a/src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt b/src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt index 4667f05..8ce5878 100644 --- a/src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt +++ b/src/main/kotlin/space/mori/chzzk_bot/discord/Discord.kt @@ -4,6 +4,7 @@ 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.events.guild.GuildJoinEvent import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.hooks.ListenerAdapter @@ -40,6 +41,26 @@ class Discord: ListenerAdapter() { event.member?.let { ManagerService.deleteManager(event.guild.idLong, it.idLong) } } + override fun onGuildJoin(event: GuildJoinEvent) { + commandUpdate(event.guild) + } + + private fun commandUpdate(guild: Guild) { + guild.updateCommands().addCommands(* commands.map { it.command}.toTypedArray()) + .onSuccess { + logger.info("Command update on guild success!") + } + .queue() + } + + private fun commandUpdate(bot: JDA) { + bot.updateCommands().addCommands(* commands.map { it.command}.toTypedArray()) + .onSuccess { + logger.info("Command update bot boot success!") + } + .queue() + } + internal fun enable() { val thread = Thread { try { @@ -50,18 +71,9 @@ class Discord: ListenerAdapter() { guild = bot.getGuildById(dotenv["GUILD_ID"]) - bot.updateCommands() - .addCommands(* commands.map { it.command }.toTypedArray()) - .onSuccess { - logger.info("Command update success!") - logger.debug("Command list: ${commands.joinToString("/ ") { it.name }}") - } - .queue() - - - if (guild == null) { - logger.info("No guild found!") - this.disable() + commandUpdate(bot) + bot.guilds.forEach { + commandUpdate(it) } } catch (e: Exception) { logger.info("Could not enable Discord!")