follow period message fix done.

This commit is contained in:
dalbodeule 2024-06-16 13:25:05 +09:00
parent 8af0c3ac33
commit c22c70398f
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
2 changed files with 37 additions and 16 deletions

View File

@ -16,14 +16,33 @@ data class IFollowContent(
val nickname: String = "", val nickname: String = "",
val profileImageUrl: String = "", val profileImageUrl: String = "",
val userRoleCode: String = "", val userRoleCode: String = "",
val badge: String? = null, val badge: Badge? = null,
val title: String? = null, val title: Title? = null,
val verifiedMark: Boolean = false, val verifiedMark: Boolean = false,
val activityBadges: List<String> = emptyList(), val activityBadges: List<String> = emptyList(),
val streamingProperty: Map<String, String> = mapOf( val streamingProperty: StreamingProperty = StreamingProperty()
"following" to "",
"nicknameColor" to ""
) )
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() val client = OkHttpClient()
@ -38,7 +57,8 @@ fun getFollowDate(chatID: String, userId: String) : IFollow {
client.newCall(request).execute().use { response -> client.newCall(request).execute().use { response ->
try { try {
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}") 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 return follow
} catch(e: Exception) { } catch(e: Exception) {

View File

@ -8,10 +8,11 @@ import space.mori.chzzk_bot.services.UserService
import xyz.r2turntrue.chzzk4j.chat.ChatMessage import xyz.r2turntrue.chzzk4j.chat.ChatMessage
import xyz.r2turntrue.chzzk4j.chat.ChzzkChat import xyz.r2turntrue.chzzk4j.chat.ChzzkChat
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
import java.text.SimpleDateFormat
import java.time.LocalDate import java.time.LocalDate
import java.time.Period import java.time.Period
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.util.*
class MessageHandler( class MessageHandler(
@ -90,17 +91,17 @@ class MessageHandler(
result = followPattern.replace(result) { result = followPattern.replace(result) {
val following = getFollowDate(listener.chatId, msg.userId) 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() val today = LocalDate.now()
if(dateString == null) {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
// 문자열을 LocalDate 객체로 변환 // 문자열을 LocalDate 객체로 변환
val pastDate = LocalDate.parse(dateString, formatter) val pastDate = LocalDate.parse(dateString, formatter)
val period = Period.between(pastDate, today) val period = Period.between(pastDate, today)
period.days.toString() period.days.toString()
} else ""
} }
if(isFail) { if(isFail) {
return chat.second return chat.second