10 Commits
0.1.0 ... 0.3.0

Author SHA1 Message Date
dalbodeule
c35b3082cc log debug to info. level changed 2024-07-05 14:06:31 +09:00
dalbodeule
19d3f23cd7 chzzk livestream status handler fix 2024-07-03 22:33:25 +09:00
dalbodeule
80d777dad5 chzzkChat only connected on live 2024-07-02 10:04:23 +09:00
dalbodeule
d2071b323e register command in chat some fix (4x) 2024-06-29 21:58:50 +09:00
dalbodeule
f2b30c8b00 register command in chat some fix (3x) 2024-06-29 21:44:18 +09:00
dalbodeule
947e6d4bb3 register command in chat some fix (2x) 2024-06-29 21:38:19 +09:00
dalbodeule
43b6869100 register command in chat some fix 2024-06-29 21:11:19 +09:00
dalbodeule
ba12fd655b register discord command bug fix 2024-06-24 19:41:48 +09:00
dalbodeule
b1d69e90ef add command manage commands. 2024-06-24 19:06:24 +09:00
dalbodeule
a9aa5188f9 if stream end, send message and can't use commands.(live image url fix) 2024-06-17 19:43:19 +09:00
4 changed files with 83 additions and 20 deletions

View File

@@ -62,7 +62,7 @@ object ChzzkHandler {
try {
val streamInfo = getStreamInfo(it.channel.channelId)
if (streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, streamInfo)
if (streamInfo.content.status == "CLOSED" && it.isActive) it.isActive(false, streamInfo)
if (streamInfo.content.status == "CLOSE" && it.isActive) it.isActive(false, streamInfo)
} catch(e: SocketTimeoutException) {
logger.info("Timeout: ${it.channel.channelName} / ${e.stackTraceToString()}")
} catch (e: Exception) {
@@ -105,6 +105,7 @@ class UserHandler(
}
override fun onChat(msg: ChatMessage) {
if(!_isActive) return
messageHandler.handle(msg, user)
}
@@ -115,11 +116,6 @@ class UserHandler(
})
.build()
init {
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
listener.connectAsync()
}
internal fun disable() {
listener.closeAsync()
}
@@ -139,6 +135,10 @@ class UserHandler(
_isActive = value
if(value) {
logger.info("${user.username} is live.")
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
listener.connectAsync()
if(user.liveAlertMessage != "" && user.liveAlertGuild != null && user.liveAlertChannel != null) {
val channel = discord.getChannel(user.liveAlertGuild!!, user.liveAlertChannel!!) ?: throw RuntimeException("${user.liveAlertChannel} is not valid.")
@@ -158,9 +158,12 @@ class UserHandler(
.setEmbeds(embed.build())
.build()
).queue()
listener.sendChat("${user.username} 님의 방송이 감지되었습니다.")
}
} else {
logger.info("${user.username} is offline.")
listener.closeAsync()
}
}
}

View File

@@ -36,6 +36,11 @@ class MessageHandler(
val user = UserService.getUser(channel.channelId)
?: throw RuntimeException("User not found. it's bug? ${channel.channelName} - ${channel.channelId}")
val commands = CommandService.getCommands(user)
val manageCommands = mapOf("!명령어추가" to this::manageAddCommand, "!명령어삭제" to this::manageRemoveCommand, "!명령어수정" to this::manageUpdateCommand)
manageCommands.forEach { (commandName, command) ->
this.commands[commandName] = command
}
commands.map {
this.commands.put(it.command.lowercase()) { msg, user ->
@@ -47,6 +52,64 @@ class MessageHandler(
}
}
private fun manageAddCommand(msg: ChatMessage, user: User) {
if (msg.profile?.userRoleCode == "common_user") {
listener.sendChat("매니저만 명령어를 추가할 수 있습니다.")
return
}
val parts = msg.content.split(" ", limit = 3)
if (parts.size < 3) {
listener.sendChat("명령어 추가 형식은 '!명령어추가 명령어 내용'입니다.")
return
}
if (commands.containsKey(parts[1])) {
listener.sendChat("${parts[1]} 명령어는 이미 있는 명령어입니다.")
return
}
val command = parts[1]
val content = parts[2]
CommandService.saveCommand(user, command, content, "")
listener.sendChat("명령어 '$command' 추가되었습니다.")
}
private fun manageUpdateCommand(msg: ChatMessage, user: User) {
if (msg.profile?.userRoleCode == "common_user") {
listener.sendChat("매니저만 명령어를 추가할 수 있습니다.")
return
}
val parts = msg.content.split(" ", limit = 3)
if (parts.size < 3) {
listener.sendChat("명령어 수정 형식은 '!명령어수정 명령어 내용'입니다.")
return
}
if (!commands.containsKey(parts[1])) {
listener.sendChat("${parts[1]} 명령어는 없는 명령어입니다.")
return
}
val command = parts[1]
val content = parts[2]
CommandService.updateCommand(user, command, content, "")
listener.sendChat("명령어 '$command' 수정되었습니다.")
}
private fun manageRemoveCommand(msg: ChatMessage, user: User) {
if (msg.profile?.userRoleCode == "common_user") {
listener.sendChat("매니저만 명령어를 삭제할 수 있습니다.")
return
}
val parts = msg.content.split(" ", limit = 2)
if (parts.size < 2) {
listener.sendChat("명령어 삭제 형식은 '!명령어삭제 명령어'입니다.")
return
}
val command = parts[1]
CommandService.removeCommand(user, command)
listener.sendChat("명령어 '$command' 삭제되었습니다.")
}
internal fun handle(msg: ChatMessage, user: User) {
val commandKey = msg.content.split(' ')[0]
@@ -57,16 +120,6 @@ class MessageHandler(
var result = chat.first
var isFail = false
result = counterPattern.replace(result) {
val name = it.groupValues[1]
CounterService.updateCounterValue(name, 1, user).toString()
}
result = personalCounterPattern.replace(result) {
val name = it.groupValues[1]
CounterService.updatePersonalCounterValue(name, msg.userId, 1, user).toString()
}
result = dailyCounterPattern.replace(result) {
val name = it.groupValues[1]
val dailyCounter = CounterService.getDailyCounterValue(name, msg.userId, user)
@@ -103,8 +156,15 @@ class MessageHandler(
val period = Period.between(pastDate, today)
period.days.toString()
}
if(isFail) {
return chat.second
result = counterPattern.replace(result) {
val name = it.groupValues[1]
CounterService.updateCounterValue(name, 1, user).toString()
}
result = personalCounterPattern.replace(result) {
val name = it.groupValues[1]
CounterService.updatePersonalCounterValue(name, msg.userId, 1, user).toString()
}
result = namePattern.replace(result, userName)

View File

@@ -39,8 +39,8 @@ object RegisterCommand: CommandInterface {
try {
val user = UserService.saveUser(chzzkChannel.channelName, chzzkChannel.channelId, event.user.idLong)
ChzzkHandler.addUser(chzzkChannel, user)
event.hook.sendMessage("등록이 완료되었습니다. `${chzzkChannel.channelId}` - `${chzzkChannel.channelName}`")
ChzzkHandler.addUser(chzzkChannel, user)
} catch(e: Exception) {
event.hook.sendMessage("에러가 발생했습니다.").queue()
logger.debug(e.stackTraceToString())

View File

@@ -3,7 +3,7 @@
<!-- 콘솔에 출력하는 기본 로그 설정 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
<level>INFO</level>
</filter>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>