mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 12:51:13 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fe63a4af15 | ||
|
7522ec6f9e | ||
|
c35b3082cc | ||
|
19d3f23cd7 | ||
|
80d777dad5 | ||
|
d2071b323e | ||
|
f2b30c8b00 |
14
.idea/dataSources.xml
generated
14
.idea/dataSources.xml
generated
@@ -9,6 +9,20 @@
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="@prod" uuid="ea495604-156c-4d96-9100-9074495ce007">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306/chzzk</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
|
@@ -21,12 +21,17 @@ data class IFollowContent(
|
||||
val badge: Badge? = null,
|
||||
val title: Title? = null,
|
||||
val verifiedMark: Boolean = false,
|
||||
val activityBadges: List<String> = emptyList(),
|
||||
val activityBadges: List<Badge> = emptyList(),
|
||||
val streamingProperty: StreamingProperty = StreamingProperty()
|
||||
)
|
||||
|
||||
data class Badge(
|
||||
val imageUrl: String = ""
|
||||
val badgeNo: Int?,
|
||||
val badgeId: String?,
|
||||
val imageUrl: String?,
|
||||
val title: String?,
|
||||
val description: String?,
|
||||
val activated: Boolean?
|
||||
)
|
||||
|
||||
data class Title(
|
||||
@@ -113,10 +118,12 @@ fun getFollowDate(chatID: String, userId: String) : IData<IFollowContent> {
|
||||
try {
|
||||
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
|
||||
val body = response.body?.string()
|
||||
println(body)
|
||||
val follow = gson.fromJson(body, object: TypeToken<IData<IFollowContent>>() {})
|
||||
|
||||
return follow
|
||||
} catch(e: Exception) {
|
||||
println(e.stackTrace)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
@@ -116,11 +116,6 @@ class UserHandler(
|
||||
})
|
||||
.build()
|
||||
|
||||
init {
|
||||
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
|
||||
listener.connectAsync()
|
||||
}
|
||||
|
||||
internal fun disable() {
|
||||
listener.closeAsync()
|
||||
}
|
||||
@@ -140,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.")
|
||||
|
||||
@@ -164,8 +163,7 @@ class UserHandler(
|
||||
}
|
||||
} else {
|
||||
logger.info("${user.username} is offline.")
|
||||
|
||||
listener.sendChat("${user.username} 님! 방송 수고하셨습니다.")
|
||||
listener.closeAsync()
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
package space.mori.chzzk_bot.chzzk
|
||||
|
||||
import org.slf4j.Logger
|
||||
import space.mori.chzzk_bot.models.Command
|
||||
import space.mori.chzzk_bot.models.User
|
||||
import space.mori.chzzk_bot.services.CommandService
|
||||
import space.mori.chzzk_bot.services.CounterService
|
||||
@@ -9,11 +8,9 @@ import space.mori.chzzk_bot.services.UserService
|
||||
import xyz.r2turntrue.chzzk4j.chat.ChatMessage
|
||||
import xyz.r2turntrue.chzzk4j.chat.ChzzkChat
|
||||
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.LocalDate
|
||||
import java.time.Period
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
|
||||
class MessageHandler(
|
||||
@@ -64,7 +61,7 @@ class MessageHandler(
|
||||
listener.sendChat("명령어 추가 형식은 '!명령어추가 명령어 내용'입니다.")
|
||||
return
|
||||
}
|
||||
if (commands.containsKey(parts[0])) {
|
||||
if (commands.containsKey(parts[1])) {
|
||||
listener.sendChat("${parts[1]} 명령어는 이미 있는 명령어입니다.")
|
||||
return
|
||||
}
|
||||
@@ -85,7 +82,7 @@ class MessageHandler(
|
||||
listener.sendChat("명령어 수정 형식은 '!명령어수정 명령어 내용'입니다.")
|
||||
return
|
||||
}
|
||||
if (!commands.containsKey(parts[0])) {
|
||||
if (!commands.containsKey(parts[1])) {
|
||||
listener.sendChat("${parts[1]} 명령어는 없는 명령어입니다.")
|
||||
return
|
||||
}
|
||||
@@ -121,16 +118,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)
|
||||
@@ -154,21 +141,35 @@ class MessageHandler(
|
||||
}
|
||||
|
||||
result = followPattern.replace(result) {
|
||||
val following = getFollowDate(listener.chatId, msg.userId)
|
||||
val dateString: String = following.content.streamingProperty.following?.followDate ?: SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
|
||||
Date()
|
||||
)
|
||||
val today = LocalDate.now()
|
||||
try {
|
||||
val followingDate = getFollowDate(listener.chatId, msg.userId)
|
||||
.content.streamingProperty.following?.followDate
|
||||
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
// 문자열을 LocalDate 객체로 변환
|
||||
val pastDate = LocalDate.parse(dateString, formatter)
|
||||
return@replace when (followingDate) {
|
||||
null -> "0"
|
||||
else -> {
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
val pastDate = LocalDateTime.parse(followingDate, formatter)
|
||||
val today = LocalDateTime.now()
|
||||
val period = ChronoUnit.DAYS.between(pastDate, today)
|
||||
|
||||
val period = Period.between(pastDate, today)
|
||||
period.days.toString()
|
||||
"$period"
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.error(e.message)
|
||||
"0"
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user