mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
follow period message fix done.
This commit is contained in:
parent
8af0c3ac33
commit
c22c70398f
@ -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<String> = emptyList(),
|
||||
val streamingProperty: Map<String, String> = 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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user