Skip to content

Commit

Permalink
feat: load cookie close #94
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Sep 25, 2022
1 parent 078eb63 commit c5672b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ object BiliHelperPlugin : KotlinPlugin(
}

launch(SupervisorJob()) {
loadCookie()
loadEmoteData()
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/xyz/cssxsh/mirai/bilibili/BiliUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xyz.cssxsh.mirai.bilibili

import io.ktor.client.network.sockets.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.http.Cookie
import kotlinx.coroutines.*
Expand Down Expand Up @@ -254,6 +255,21 @@ private val FULLWIDTH_CHARS = mapOf(

internal fun String.fullwidth(): String = fold("") { acc, char -> acc + (FULLWIDTH_CHARS[char] ?: char) }

internal suspend fun loadCookie() {
// home
try {
client.useHttpClient { http, _ -> http.get(INDEX_PAGE).bodyAsText() }
} catch (_: Exception) {
//
}
// space
try {
client.useHttpClient { http, _ -> http.get(SPACE).bodyAsText() }
} catch (_: Exception) {
//
}
}

internal suspend fun loadEmoteData() {
// dynamic
val dynamic = try {
Expand Down

0 comments on commit c5672b3

Please sign in to comment.