mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
[feature] some logic fixed.
This commit is contained in:
@@ -207,6 +207,7 @@ class UserHandler(
|
||||
var messageHandler: MessageHandler
|
||||
var client: ChzzkClient
|
||||
var listener: ChzzkUserSession
|
||||
var chatChannelId: String?
|
||||
|
||||
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||
private var _isActive: Boolean
|
||||
@@ -225,14 +226,11 @@ class UserHandler(
|
||||
val tokens = Connector.client.refreshAccessToken(user.refreshToken!!)
|
||||
client = Connector.getClient(tokens.first, tokens.second)
|
||||
UserService.setRefreshToken(user, tokens.first, tokens.second)
|
||||
chatChannelId = getChzzkChannelId(channel.channelId)
|
||||
|
||||
client.loginAsync().join()
|
||||
client.refreshTokenAsync().join()
|
||||
|
||||
listener = ChzzkSessionBuilder(client).buildUserSession()
|
||||
|
||||
listener.createAndConnectAsync().join()
|
||||
|
||||
messageHandler = MessageHandler(this@UserHandler)
|
||||
|
||||
listener.on(SessionChatMessageEvent::class.java) {
|
||||
|
@@ -353,15 +353,15 @@ class MessageHandler(
|
||||
// Replace followPattern
|
||||
result = followPattern.replace(result) { _ ->
|
||||
try {
|
||||
val followingDate = getFollowDate(channel.channelId, msg.senderChannelId)
|
||||
.content?.streamingProperty?.following?.followDate
|
||||
val followingDate = handler.chatChannelId?.let { getFollowDate(it, msg.senderChannelId) }
|
||||
?.content?.streamingProperty?.following?.followDate ?: LocalDateTime.now().minusDays(1).toString()
|
||||
|
||||
val period = followingDate?.let {
|
||||
val period = followingDate.let {
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
val pastDate = LocalDateTime.parse(it, formatter)
|
||||
val today = LocalDateTime.now()
|
||||
ChronoUnit.DAYS.between(pastDate, today)
|
||||
} ?: 0
|
||||
} + 1
|
||||
|
||||
period.toString()
|
||||
} catch (e: Exception) {
|
||||
|
@@ -29,7 +29,7 @@ data class RefreshTokenResponse(
|
||||
)
|
||||
|
||||
fun ChzzkClient.refreshAccessToken(refreshToken: String): Pair<String, String> {
|
||||
val url = "https://openapi.chzzk.naver.com/auth/v1/token"
|
||||
val url = "https://chzzk.naver.com/auth/v1/token"
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.header("Content-Type", "application/json")
|
||||
|
Reference in New Issue
Block a user