mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 14:58:21 +00:00
[hotfix] please, this patch is the final patch!
This commit is contained in:
parent
77eecaca34
commit
51232ad593
@ -46,7 +46,7 @@ object ChzzkHandler {
|
||||
UserService.getAllUsers().map {
|
||||
if(!it.isDisabled)
|
||||
try {
|
||||
Connector.getChannel(it.token)?.let { token -> addUser(token, it) }
|
||||
getChannel(it.token)?.let { token -> addUser(token, it) }
|
||||
} catch(e: Exception) {
|
||||
logger.info("Exception: ${it.token}(${it.username}) not found. ${e.stackTraceToString()}")
|
||||
}
|
||||
@ -223,7 +223,9 @@ class UserHandler(
|
||||
throw RuntimeException("AccessToken or RefreshToken is not valid.")
|
||||
}
|
||||
try {
|
||||
val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token) }
|
||||
println(user.refreshToken)
|
||||
|
||||
val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token)}
|
||||
if(tokens == null) {
|
||||
throw RuntimeException("AccessToken is not valid.")
|
||||
}
|
||||
|
@ -1,27 +1,15 @@
|
||||
package space.mori.chzzk_bot.chatbot.utils
|
||||
|
||||
import com.google.gson.Gson
|
||||
import okhttp3.MediaType
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import space.mori.chzzk_bot.chatbot.chzzk.dotenv
|
||||
import space.mori.chzzk_bot.common.utils.IData
|
||||
import space.mori.chzzk_bot.common.utils.client
|
||||
import xyz.r2turntrue.chzzk4j.ChzzkClient
|
||||
import java.io.IOException
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.addNetworkInterceptor { chain ->
|
||||
chain.proceed(
|
||||
chain.request()
|
||||
.newBuilder()
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
|
||||
.build()
|
||||
)
|
||||
}
|
||||
.build()
|
||||
val gson = Gson()
|
||||
|
||||
data class RefreshTokenResponse(
|
||||
val accessToken: String,
|
||||
@ -48,9 +36,9 @@ fun ChzzkClient.refreshAccessToken(refreshToken: String): Pair<String, String> {
|
||||
try {
|
||||
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
|
||||
val body = response.body?.string()
|
||||
val data = gson.fromJson(body, RefreshTokenResponse::class.java)
|
||||
val data = gson.fromJson(body, object: TypeToken<IData<RefreshTokenResponse>>() {})
|
||||
|
||||
return Pair(data.accessToken, data.refreshToken)
|
||||
return Pair(data.content.accessToken, data.content.refreshToken)
|
||||
} catch(e: Exception) {
|
||||
throw e
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user