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> <jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" /> <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.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" /> <property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties> </jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir> <working-dir>$ProjectFileDir$</working-dir>

View File

@ -21,12 +21,17 @@ data class IFollowContent(
val badge: Badge? = null, val badge: Badge? = null,
val title: Title? = null, val title: Title? = null,
val verifiedMark: Boolean = false, val verifiedMark: Boolean = false,
val activityBadges: List<String> = emptyList(), val activityBadges: List<Badge> = emptyList(),
val streamingProperty: StreamingProperty = StreamingProperty() val streamingProperty: StreamingProperty = StreamingProperty()
) )
data class Badge( 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( data class Title(
@ -113,10 +118,12 @@ fun getFollowDate(chatID: String, userId: String) : IData<IFollowContent> {
try { try {
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}") if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
val body = response.body?.string() val body = response.body?.string()
println(body)
val follow = gson.fromJson(body, object: TypeToken<IData<IFollowContent>>() {}) val follow = gson.fromJson(body, object: TypeToken<IData<IFollowContent>>() {})
return follow return follow
} catch(e: Exception) { } catch(e: Exception) {
println(e.stackTrace)
throw e 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.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.LocalDateTime
import java.time.LocalDate
import java.time.Period
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.util.* import java.time.temporal.ChronoUnit
class MessageHandler( class MessageHandler(
@ -144,22 +142,23 @@ class MessageHandler(
result = followPattern.replace(result) { result = followPattern.replace(result) {
try { 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( return@replace when (followingDate) {
Date() null -> "0"
) else -> {
val today = LocalDate.now() 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") "$period"
// 문자열을 LocalDate 객체로 변환 }
val pastDate = LocalDate.parse(dateString, formatter) }
val period = Period.between(pastDate, today)
period.days.toString()
} catch (e: Exception) { } catch (e: Exception) {
logger.info(e.message) logger.error(e.message)
return@replace "0" "0"
} }
} }