chzzk followdate fix

This commit is contained in:
dalbodeule 2024-07-14 19:47:12 +09:00
parent 7522ec6f9e
commit fe63a4af15
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
3 changed files with 39 additions and 19 deletions

14
.idea/dataSources.xml generated
View File

@ -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>

View File

@ -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
}
}

View File

@ -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 dateString: String = following.content.streamingProperty.following?.followDate ?: SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
Date()
)
val today = LocalDate.now()
val followingDate = getFollowDate(listener.chatId, msg.userId)
.content.streamingProperty.following?.followDate
return@replace when (followingDate) {
null -> "0"
else -> {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
// 문자열을 LocalDate 객체로 변환
val pastDate = LocalDate.parse(dateString, formatter)
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.info(e.message)
return@replace "0"
logger.error(e.message)
"0"
}
}