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 bdc4959..479b89e 100644 --- a/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt +++ b/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt @@ -16,14 +16,33 @@ data class IFollowContent( val nickname: String = "", val profileImageUrl: String = "", val userRoleCode: String = "", - val badge: String? = null, - val title: String? = null, + val badge: Badge? = null, + val title: Title? = null, val verifiedMark: Boolean = false, val activityBadges: List = emptyList(), - val streamingProperty: Map = mapOf( - "following" to "", - "nicknameColor" to "" - ) + val streamingProperty: StreamingProperty = StreamingProperty() +) + +data class Badge( + val imageUrl: String = "" +) + +data class Title( + val name: String = "", + val color: String = "" +) + +data class StreamingProperty( + val following: Following? = Following(), + val nicknameColor: NicknameColor = NicknameColor() +) + +data class Following( + val followDate: String? = null +) + +data class NicknameColor( + val colorCode: String = "" ) val client = OkHttpClient() @@ -38,7 +57,8 @@ fun getFollowDate(chatID: String, userId: String) : IFollow { client.newCall(request).execute().use { response -> try { if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}") - val follow = gson.fromJson(response.body?.string(), IFollow::class.java) + val body = response.body?.string() + val follow = gson.fromJson(body, IFollow::class.java) return follow } catch(e: Exception) { 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 fce04cb..1a2acfa 100644 --- a/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt +++ b/src/main/kotlin/space/mori/chzzk_bot/chzzk/MessageHandler.kt @@ -8,10 +8,11 @@ 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.format.DateTimeFormatter - +import java.util.* class MessageHandler( @@ -90,17 +91,17 @@ class MessageHandler( result = followPattern.replace(result) { val following = getFollowDate(listener.chatId, msg.userId) - val dateString: String? = following.content.streamingProperty["followDate"] + val dateString: String = following.content.streamingProperty.following?.followDate ?: SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( + Date() + ) val today = LocalDate.now() - if(dateString == null) { - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") - // 문자열을 LocalDate 객체로 변환 - val pastDate = LocalDate.parse(dateString, formatter) + 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() - } else "" + val period = Period.between(pastDate, today) + period.days.toString() } if(isFail) { return chat.second