diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index b716e72..2664d1c 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -9,6 +9,20 @@
+
+
+
+ $ProjectFileDir$
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://localhost:3306/chzzk
+
+
+
+
$ProjectFileDir$
diff --git a/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt b/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt
index 61cc511..e937c29 100644
--- a/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt
+++ b/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt
@@ -21,12 +21,17 @@ data class IFollowContent(
val badge: Badge? = null,
val title: Title? = null,
val verifiedMark: Boolean = false,
- val activityBadges: List = emptyList(),
+ val activityBadges: List = 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 {
try {
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
val body = response.body?.string()
+ println(body)
val follow = gson.fromJson(body, object: TypeToken>() {})
return follow
} catch(e: Exception) {
+ println(e.stackTrace)
throw e
}
}
diff --git a/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt b/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt
index eeacd9d..df1029c 100644
--- a/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt
+++ b/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt
@@ -8,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(
@@ -144,22 +142,23 @@ class MessageHandler(
result = followPattern.replace(result) {
try {
- val following = getFollowDate(listener.chatId, msg.userId)
+ val followingDate = getFollowDate(listener.chatId, msg.userId)
+ .content.streamingProperty.following?.followDate
- val dateString: String = following.content.streamingProperty.following?.followDate ?: SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
- Date()
- )
- val today = LocalDate.now()
+ 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 formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
- // 문자열을 LocalDate 객체로 변환
- val pastDate = LocalDate.parse(dateString, formatter)
-
- val period = Period.between(pastDate, today)
- period.days.toString()
+ "$period"
+ }
+ }
} catch (e: Exception) {
- logger.info(e.message)
- return@replace "0"
+ logger.error(e.message)
+ "0"
}
}