Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoLittle committed Apr 22, 2022
1 parent 46074e8 commit 5c1d4d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/main/kotlin/DrawMeme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand Down Expand Up @@ -316,15 +318,15 @@ 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) {
"" -> httpClient.get<ByteArray>(sender.avatarUrl).apply {
image = SkImage.makeFromEncoded(this)
}

"" -> delay = 0.5
"" -> delay = 0.02
}

for (single in message) {
Expand All @@ -334,7 +336,6 @@ object DrawMeme : KotlinPlugin(
image = SkImage.makeFromEncoded(this)
}


is At -> subject[single.target]?.let {
httpClient.get<ByteArray>(it.avatarUrl).apply {
image = SkImage.makeFromEncoded(this)
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/General.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5c1d4d1

Please sign in to comment.