Skip to content

Commit a978f91

Browse files
committed
support more message
1 parent 26497a4 commit a978f91

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ plugins {
2626
}
2727

2828
group = "net.lz1998"
29-
version = "0.0.1-SNAPSHOT"
29+
version = "0.0.3"
3030
java.sourceCompatibility = JavaVersion.VERSION_1_8
3131

3232
configurations {
@@ -46,7 +46,7 @@ repositories {
4646
}
4747

4848
dependencies {
49-
implementation("net.mamoe:mirai-core-qqandroid:1.3.0")
49+
implementation("net.mamoe:mirai-core-qqandroid:1.3.1")
5050
implementation("com.squareup.okhttp3:okhttp:4.8.0")
5151
// implementation("com.google.protobuf:protobuf-javalite:3.8.0")
5252

src/main/kotlin/net/lz1998/mirai/utils/MsgConverter.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ suspend fun OnebotBase.Message.toMiraiMessage(bot: Bot, contact: Contact): Messa
1717
return when (this.type) {
1818
"text" -> PlainText(dataMap["text"] ?: "")
1919
"face" -> dataMap["id"]?.toInt()?.let { Face(it) } ?: MSG_EMPTY
20-
"image" -> {
21-
return try {
22-
withContext(Dispatchers.IO) {
23-
URL(dataMap["file"] ?: "").openConnection().getInputStream().uploadAsImage(contact)
24-
}
25-
} catch (e: Exception) {
26-
MSG_EMPTY
20+
"image" -> try {
21+
withContext(Dispatchers.IO) {
22+
val img = URL(dataMap["url"] ?: dataMap["file"]
23+
?: "").openConnection().getInputStream().uploadAsImage(contact)
24+
if (dataMap["type"] == "flash") img.flash() else img
2725
}
26+
} catch (e: Exception) {
27+
MSG_EMPTY
28+
}
29+
"at" -> {
30+
if (dataMap["qq"] == "all")
31+
AtAll
32+
else
33+
dataMap["qq"]?.toLong()?.let { userId -> bot.getGroupOrNull(contact.id)?.getOrNull(userId)?.let { At(it) } }
34+
?: MSG_EMPTY
2835
}
29-
"at" -> dataMap["qq"]?.toLong()?.let { userId -> bot.getGroupOrNull(contact.id)?.getOrNull(userId)?.let { At(it) } }
30-
?: MSG_EMPTY
3136
else -> MSG_EMPTY
3237
}
3338
}

0 commit comments

Comments
 (0)