mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 12:51:13 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1d23ac5121 | ||
|
8f8d2f895a | ||
|
47b4b8252f | ||
|
64880318e8 | ||
|
cec07f9859 | ||
|
18ee27e567 |
14
README.md
14
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: <name>님은 오늘로 <following>일째 팔로우네요!`
|
||||
|
@@ -1,6 +1,6 @@
|
||||
kotlin.code.style=official
|
||||
group = space.mori
|
||||
version = 1.0.0
|
||||
version = 1.0.3
|
||||
|
||||
org.gradle.jvmargs=-Dfile.encoding=UTF-8
|
||||
org.gradle.console=plain
|
||||
|
@@ -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!")
|
||||
|
@@ -38,12 +38,12 @@ object AddCommand : CommandInterface {
|
||||
return
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
user = manager!!.user
|
||||
if (manager != null) {
|
||||
user = manager.user
|
||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
||||
}
|
||||
|
||||
val commands = CommandService.getCommands(user)
|
||||
val commands = CommandService.getCommands(user!!)
|
||||
if (commands.any { it.command == label }) {
|
||||
event.hook.sendMessage("$label 명령어는 이미 있습니다! 업데이트 명령어를 써주세요.").queue()
|
||||
return
|
||||
|
@@ -30,12 +30,12 @@ object AlertCommand : CommandInterface {
|
||||
return
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
user = manager!!.user
|
||||
if (manager != null) {
|
||||
user = manager.user
|
||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
||||
}
|
||||
|
||||
val chzzkChannel = Connector.getChannel(user.token)
|
||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||
|
||||
try {
|
||||
val newUser = UserService.updateLiveAlert(user.id.value, channel?.guild?.idLong ?: 0L, channel?.idLong ?: 0L, content ?: "")
|
||||
|
@@ -34,12 +34,12 @@ object RemoveCommand : CommandInterface {
|
||||
return
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
user = manager!!.user
|
||||
if (manager != null) {
|
||||
user = manager.user
|
||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
||||
}
|
||||
|
||||
val chzzkChannel = Connector.getChannel(user.token)
|
||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||
|
||||
try {
|
||||
CommandService.removeCommand(user, label)
|
||||
|
@@ -38,12 +38,12 @@ object UpdateCommand : CommandInterface {
|
||||
return
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
user = manager!!.user
|
||||
if (manager != null) {
|
||||
user = manager.user
|
||||
ManagerService.updateManager(user, event.user.idLong, event.user.effectiveName)
|
||||
}
|
||||
|
||||
val chzzkChannel = Connector.getChannel(user.token)
|
||||
val chzzkChannel = Connector.getChannel(user!!.token)
|
||||
|
||||
try {
|
||||
CommandService.updateCommand(user, label, content, failContent ?: "")
|
||||
|
@@ -96,6 +96,7 @@ object CounterService {
|
||||
Pair(counter.value, false)
|
||||
else {
|
||||
counter.value += increment
|
||||
counter.updatedAt = today
|
||||
Pair(counter.value, true)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user