Skip to content

Commit 69aa661

Browse files
committed
build: mirai-skia-plugin 1.0.2
1 parent e33bf79 commit 69aa661

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "xyz.cssxsh.mirai"
10-
version = "1.0.1"
10+
version = "1.0.2"
1111

1212
repositories {
1313
mavenLocal()

src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiSkiaPlugin.kt

+6-21
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import xyz.cssxsh.skia.*
1313

1414
public object MiraiSkiaPlugin : KotlinPlugin(
1515
JvmPluginDescription(
16-
id = "xyz.cssxsh.mirai.mirai-skia-plugin",
16+
id = "xyz.cssxsh.mirai.plugin.mirai-skia-plugin",
1717
name = "mirai-skia-plugin",
18-
version = "1.0.1",
18+
version = "1.0.2",
1919
) {
2020
author("cssxsh")
2121
}
2222
) {
2323

2424
override fun onEnable() {
2525
logger.info { "platform: ${hostId}, skia: ${Version.skia}, skiko: ${Version.skiko}" }
26-
loadTypeface(folder = dataFolder.resolve("fonts"))
27-
logger.info { "fonts: ${FontUtils.provider.makeFamilies().keys}" }
26+
launch {
27+
loadTypeface(folder = dataFolder.resolve("fonts"))
28+
logger.info { "fonts: ${FontUtils.provider.makeFamilies().keys}" }
29+
}
2830

2931
val test = System.getProperty("xyz.cssxsh.skia.test", "false").toBoolean()
3032
if (test) {
@@ -48,29 +50,12 @@ public object MiraiSkiaPlugin : KotlinPlugin(
4850

4951
subject.uploadImage(resource = SkiaExternalResource(origin = petpet(face, delay), formatName = "gif"))
5052
}
51-
"""^#shout(.+)""".toRegex() findingReply { result ->
52-
logger.info { "shout ${result.value}" }
53-
val lines = message.firstIsInstance<PlainText>().content
54-
.removePrefix("#shout")
55-
.split(' ').filterNot { it.isBlank() }
56-
.toTypedArray()
57-
subject.uploadImage(resource = shout(lines = lines).makeSnapshotResource())
58-
}
5953
"""^#choyen\s+(\S+)\s+(\S+)""".toRegex() findingReply { result ->
6054
logger.info { "choyen ${result.value}" }
6155
val (top, bottom) = result.destructured
6256

6357
subject.uploadImage(resource = choyen(top, bottom).makeSnapshotResource())
6458
}
65-
"""^#lick""".toRegex() findingReply { result ->
66-
logger.info { "lick ${result.value}" }
67-
val user = message.findIsInstance<At>()?.target?.let { (subject as? Group)?.get(it) } ?: sender
68-
val file = dataFolder.resolve("${user.id}.jpg")
69-
if (file.exists().not()) download(urlString = user.avatarUrl, folder = dataFolder).renameTo(file)
70-
val face = SkiaImage.makeFromEncoded(file.readBytes())
71-
72-
subject.uploadImage(resource = SkiaExternalResource(origin = lick(face), formatName = "gif"))
73-
}
7459
}
7560
}
7661
}

src/main/kotlin/xyz/cssxsh/skia/Mosaic.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.jetbrains.skia.*
44
import kotlin.math.pow
55
import kotlin.reflect.full.*
66

7-
87
public sealed class MosaicOption {
98
internal abstract fun convert(bitmap: Bitmap)
109

@@ -79,6 +78,9 @@ public sealed class MosaicOption {
7978
}
8079
}
8180

81+
/**
82+
* 绘制马赛克
83+
*/
8284
public fun Surface.drawMosaic(area: IRect, options: MosaicOption) {
8385
val bitmap = Bitmap()
8486

@@ -89,6 +91,9 @@ public fun Surface.drawMosaic(area: IRect, options: MosaicOption) {
8991
writePixels(bitmap, area.left, area.top)
9092
}
9193

94+
/**
95+
* 绘制马赛克
96+
*/
9297
public inline fun <reified O : MosaicOption> Surface.drawMosaic(area: IRect, block: O.() -> Unit = {}) {
9398
drawMosaic(area = area, options = O::class.createInstance().apply(block))
9499
}

0 commit comments

Comments
 (0)