From 5c1d4d1933f4c59ee0d83b480fe8db3348010bd9 Mon Sep 17 00:00:00 2001 From: LaoLittle Date: Fri, 22 Apr 2022 18:06:08 +0800 Subject: [PATCH] fix --- src/main/kotlin/DrawMeme.kt | 13 +++++++------ src/main/kotlin/General.kt | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/DrawMeme.kt b/src/main/kotlin/DrawMeme.kt index 7f0681d..6f4ee1a 100644 --- a/src/main/kotlin/DrawMeme.kt +++ b/src/main/kotlin/DrawMeme.kt @@ -47,7 +47,7 @@ object DrawMeme : KotlinPlugin( val k5topFont = Fonts["Noto Sans SC-BOLD"] usedBy "5k兆顶部文字" val k5botFont = Fonts["Noto Serif SC-BOLD"] usedBy "5k兆底部文字" val x0font = Fonts["MiSans-Regular"] usedBy "0%生成器" - val patReg = Regex("""^摸+([我爆头])""") + val patReg = Regex("""^摸+([我爆头])?""") globalEventChannel().subscribeGroupMessages( priority = EventPriority.NORMAL @@ -278,7 +278,9 @@ object DrawMeme : KotlinPlugin( // 零溢事件 finding(Regex("""#(\d{1,3})$""")) { r -> - if (r.groupValues[1].toInt() > 100) return@finding + val real = r.groupValues[1].toInt() + + if (real > 100) return@finding val image = getOrWaitImage() ?: return@finding val skikoImage = HttpClient(OkHttp).use { client -> @@ -288,7 +290,7 @@ object DrawMeme : KotlinPlugin( val h21 = (skikoImage.height shr 1).toFloat() val radius = min(w21, h21) * .24f - val text = TextLine.make("${r.groupValues[1]}%", x0font.makeWithSize(radius * .6f)) + val text = TextLine.make("$real%", x0font.makeWithSize(radius * .6f)) Surface.makeRaster(skikoImage.imageInfo).apply { val paint = Paint().apply { color = Color.WHITE @@ -316,7 +318,7 @@ object DrawMeme : KotlinPlugin( finding(patReg) { result -> val foo = result.groupValues[1] - var delay = 0.2 + var delay = 0.05 var image: SkImage? = null when (foo) { @@ -324,7 +326,7 @@ object DrawMeme : KotlinPlugin( image = SkImage.makeFromEncoded(this) } - "爆" -> delay = 0.5 + "爆" -> delay = 0.02 } for (single in message) { @@ -334,7 +336,6 @@ object DrawMeme : KotlinPlugin( image = SkImage.makeFromEncoded(this) } - is At -> subject[single.target]?.let { httpClient.get(it.avatarUrl).apply { image = SkImage.makeFromEncoded(this) diff --git a/src/main/kotlin/General.kt b/src/main/kotlin/General.kt index c33b98e..216ad19 100644 --- a/src/main/kotlin/General.kt +++ b/src/main/kotlin/General.kt @@ -13,7 +13,6 @@ import net.mamoe.mirai.message.data.PlainText import net.mamoe.mirai.message.data.firstIsInstanceOrNull import net.mamoe.mirai.message.nextMessage import net.mamoe.mirai.utils.info -import org.laolittle.plugin.SkikoMirai import java.io.File import kotlin.math.max import kotlin.math.min @@ -95,7 +94,7 @@ private val supportedEmojis by lazy { } } -internal fun SkImage.Companion.makeFromResource(name: String) = makeFromEncoded(SkikoMirai::class.java.getResourceAsStream(name)?.readBytes()) +internal fun SkImage.Companion.makeFromResource(name: String) = makeFromEncoded(DrawMeme::class.java.getResourceAsStream(name)?.readBytes() ?: throw IllegalStateException("无法找到资源文件: $name")) internal suspend fun MessageEvent.getOrWaitImage(): Image? { return (message.takeIf { m -> m.contains(Image) } ?: runCatching {