Skip to content

Commit

Permalink
build: 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Sep 25, 2022
1 parent caf978a commit 23d8b4b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
16 changes: 9 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "xyz.cssxsh"
version = "1.1.3"
version = "1.1.4"

repositories {
mavenLocal()
Expand All @@ -20,17 +20,17 @@ mavenCentralPublish {
singleDevGithubProject("cssxsh", "meme-helper")
licenseFromGitHubProject("AGPL-3.0")
workingDir = System.getenv("PUBLICATION_TEMP")?.let { file(it).resolve(projectName) }
?: project.buildDir.resolve("publishing-tmp")
?: buildDir.resolve("publishing-tmp")
publication {
artifact(tasks.getByName("buildPlugin"))
artifact(tasks["buildPlugin"])
}
}

dependencies {
compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.3")
compileOnly("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.7")
compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.4")
compileOnly("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.9")
compileOnly("xyz.cssxsh:weibo-helper:1.5.5")
compileOnly("xyz.cssxsh:bilibili-helper:1.6.3")
compileOnly("xyz.cssxsh:bilibili-helper:1.6.5")
compileOnly("net.mamoe:mirai-core-utils:2.13.0-M1")
compileOnly("net.mamoe:mirai-core:2.13.0-M1")
implementation("io.ktor:ktor-client-okhttp:2.1.1") {
Expand All @@ -50,7 +50,9 @@ dependencies {
}
// Test
testImplementation(kotlin("test"))
testImplementation("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.7")
testImplementation("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.9")
testImplementation("org.slf4j:slf4j-simple:2.0.0")
testImplementation("net.mamoe:mirai-logging-slf4j:2.13.0-M1")
testImplementation("net.mamoe:mirai-core-utils:2.13.0-M1")
}

Expand Down
38 changes: 16 additions & 22 deletions src/main/kotlin/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import org.jetbrains.skia.Image as SkiaImage
import xyz.cssxsh.mirai.meme.service.*
import java.io.File
import java.time.*
import java.util.*

internal val logger by lazy {
try {
MemeHelperPlugin.logger
} catch (_: Throwable) {
} catch (_: ExceptionInInitializerError) {
MiraiLogger.Factory.create(MemeHelper::class)
}
}
Expand Down Expand Up @@ -71,14 +70,14 @@ public suspend fun cache(image: Image): SkiaImage {
val md5 = image.md5.toUHexString(separator = "")
val cache = imageFolder.listFiles { file -> file.name.startsWith(prefix = md5) }?.firstOrNull()
?: http.prepareGet(image.queryUrl()).execute { response ->
val file = imageFolder.resolve("${md5}.${response.contentType()?.contentSubtype}")
file.outputStream().use { output ->
val channel = response.bodyAsChannel()
val file = imageFolder.resolve("${md5}.${response.contentType()?.contentSubtype}")
file.outputStream().use { output ->
val channel = response.bodyAsChannel()

while (!channel.isClosedForRead) channel.copyTo(output)
while (!channel.isClosedForRead) channel.copyTo(output)
}
file
}
file
}

return SkiaImage.makeFromEncoded(bytes = cache.readBytes())
}
Expand Down Expand Up @@ -108,29 +107,24 @@ internal suspend fun download(urlString: String, folder: File): File = superviso

internal fun JvmPlugin.loadMemeService() {
MemeService.coroutineContext = coroutineContext + CoroutineName("MemeServiceLoader") + Dispatchers.IO
val services = sequence<MemeService> {
val oc = Thread.currentThread().contextClassLoader

@OptIn(MiraiInternalApi::class)
@OptIn(MiraiInternalApi::class)
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
val services: Sequence<MemeService> = sequence {
for (classLoader in MemeHelperPlugin.loader.classLoaders) {
Thread.currentThread().contextClassLoader = classLoader
try {
for (provider in ServiceLoader.load(MemeService::class.java, classLoader).stream()) {
try {
val service = provider.type().kotlin.objectInstance ?: provider.get()
with(net.mamoe.mirai.console.internal.util.PluginServiceHelper) {
val services = classLoader.findServices<MemeService>().loadAllServices()
for (service in services) {
if (MemeService[service.id] != null) {
logger.verbose { "${service.id} 加载重复" }
logger.warning { "${service.id} 加载重复" }
continue
}

yield(service)
} catch (cause: Throwable) {
logger.warning({ "${provider.type().name} 加载失败" }, cause)
continue
}
}
} finally {
Thread.currentThread().contextClassLoader = oc
} catch (cause: Exception) {
logger.warning({ "MemeService 加载失败" }, cause)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/MemeHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public object MemeHelper : SimpleListenerHost() {

@EventHandler
public suspend fun MessageEvent.handle() {
if (this is MessageSyncEvent) return
for (service in MemeService) {
if (!service.loaded) continue
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/MemeHelperPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public object MemeHelperPlugin : KotlinPlugin(
JvmPluginDescription(
id = "xyz.cssxsh.mirai.plugin.meme-helper",
name = "meme-helper",
version = "1.1.3",
version = "1.1.4",
) {
author("cssxsh")
dependsOn("xyz.cssxsh.mirai.plugin.mirai-skia-plugin", ">= 1.1.0", false)
Expand Down

0 comments on commit 23d8b4b

Please sign in to comment.