Skip to content

Commit

Permalink
fix: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Colter23 committed Nov 25, 2021
1 parent c4bae40 commit e6e0d47
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 48 deletions.
25 changes: 3 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
plugins {
val kotlinVersion = "1.5.10"
val kotlinVersion = "1.5.31"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion

id("net.mamoe.mirai-console") version "2.8.1"
id("net.mamoe.mirai-console") version "2.8.2"
}

group = "top.colter"
version = "2.0.2"
version = "2.0.3"

repositories {
mavenLocal()
maven("https://maven.aliyun.com/repository/public") // 阿里云国内代理仓库
mavenCentral()
}

kotlin {
sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
languageSettings.useExperimentalAnnotation("io.ktor.util.KtorExperimentalAPI")
languageSettings.useExperimentalAnnotation("kotlinx.serialization.InternalSerializationApi")
languageSettings.useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.console.util.ConsoleExperimentalApi")
}
test {
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.console.ConsoleFrontEndImplementation")
}
}
}
dependencies {

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ object DynamicTasker : CoroutineScope by PluginMain.childScope("DynamicTasker")
seleniumMutex.withLock {
list.sendMessage { di.build(it, color) }
history.add(describe.dynamicId)
lastDynamic = di.timestamp
// lastDynamic = di.timestamp
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/top.colter.mirai.plugin.bilibili/Dynamic.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package top.colter.mirai.plugin.bilibili

//import top.colter.mirai.plugin.bilibili.utils.getScreenshot
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.message.data.Message
Expand All @@ -19,6 +19,7 @@ import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter

@OptIn(ExperimentalSerializationApi::class)
inline fun <reified T> String.decode(): T = json.decodeFromString(this)

val DynamicInfo.did get() = describe.dynamicId
Expand Down Expand Up @@ -165,6 +166,8 @@ fun String.buildContent(type: Int, dynamicInfo: DynamicInfo): List<BufferedImage
DynamicType.EPISODE -> decode<DynamicEpisode>().bufferedImages(dynamicInfo)
DynamicType.DELETE -> listOf(ImgUtils.infoContent("源动态已被作者删除"))
DynamicType.SKETCH -> decode<DynamicSketch>().bufferedImages(dynamicInfo)
DynamicType.LIVE, DynamicType.LIVE_ING -> listOf(ImgUtils.infoContent("直播"))
DynamicType.LIVE_END -> listOf(ImgUtils.infoContent("直播结束了"))
else -> {
if (dynamicInfo.link == "") {
dynamicInfo.link = "https://t.bilibili.com/${dynamicInfo.did}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.colter.mirai.plugin.bilibili

import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
Expand All @@ -14,7 +15,7 @@ object PluginMain : KotlinPlugin(
JvmPluginDescription(
id = "top.colter.bilibili-dynamic-mirai-plugin",
name = "BilibiliDynamic",
version = "2.0.2"
version = "2.0.3"
) {
author("Colter")
info(
Expand Down
37 changes: 16 additions & 21 deletions src/main/kotlin/top.colter.mirai.plugin.bilibili/utils/HttpUtils.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package top.colter.mirai.plugin.bilibili.utils

import kotlinx.serialization.json.JsonElement
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import top.colter.mirai.plugin.bilibili.PluginMain
import top.colter.mirai.plugin.bilibili.data.ResultData
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.time.Duration

class HttpUtils {

private val cookie: String = PluginMain.sessData

private var client: HttpClient = HttpClient.newBuilder().connectTimeout(Duration.ofMillis(10000)).build()
private var client: OkHttpClient = OkHttpClient().newBuilder().connectTimeout(Duration.ofMillis(20000)).build()

private val ua = listOf(
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);",
Expand All @@ -25,32 +25,27 @@ class HttpUtils {
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"
)

private fun sendRequest(request: HttpRequest): JsonElement {
val bodyHandler: HttpResponse.BodyHandler<String> = HttpResponse.BodyHandlers.ofString()
val response: HttpResponse<String> = client.send(request, bodyHandler)
val body: String = response.body()
private fun sendRequest(request: Request): JsonElement {
val body: String = client.newCall(request).execute().body!!.string()
return json.parseToJsonElement(body)
}

fun get(url: String): JsonElement {
val request: HttpRequest =
HttpRequest.newBuilder(URI.create(url))
.header("cookie", cookie)
.header("Content-Type", "application/json; charset=utf-8")
.header("user-agent", ua.random())
.GET().build()

val request = Request.Builder().url(url)
.header("cookie", cookie)
.header("Content-Type", "application/json; charset=utf-8")
.header("user-agent", ua.random())
.get().build()
return sendRequest(request)
}

fun post(url: String, postBody: String): JsonElement {
val request: HttpRequest =
HttpRequest.newBuilder(URI.create(url))
val media = "application/x-www-form-urlencoded; charset=utf-8"
val request = Request.Builder().url(url)
.header("cookie", cookie)
.header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
.header("Content-Type", media)
.header("user-agent", ua.random())
.POST(HttpRequest.BodyPublishers.ofString(postBody)).build()

.post(postBody.toRequestBody(media.toMediaTypeOrNull())).build()
return sendRequest(request)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ object ImgUtils {
val margin = 10
val rw = imgWidth - margin * 2
val rh = height - margin * 2
bgG2.color = Color.WHITE
bgG2.color = Color(255,255,255, 200)
bgG2.fillRoundRect(margin, margin, rw, rh, 20, 20)
bgG2.color = Color(238, 238, 238)
bgG2.drawRoundRect(margin - 1, margin - 1, rw + 1, rh + 1, 20, 20)
Expand Down Expand Up @@ -465,7 +465,7 @@ object ImgUtils {
}

fun infoContent(text: String): BufferedImage {
val infoBi = BufferedImage(imgWidth, 30, BufferedImage.TYPE_INT_ARGB)
val infoBi = BufferedImage(imgWidth, 50, BufferedImage.TYPE_INT_ARGB)
val infoG2 = infoBi.createGraphics()
infoG2.setRenderingHints(renderingHints)
infoG2.font = font.deriveFont(25f)
Expand Down

0 comments on commit e6e0d47

Please sign in to comment.