Image support

This commit is contained in:
Him188 2020-01-30 23:51:25 +08:00
parent 08783fe2b2
commit 288d0df738
2 changed files with 30 additions and 12 deletions

View File

@ -2,6 +2,7 @@
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
import kotlinx.coroutines.delay
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.discardExact
import kotlinx.io.core.readBytes
@ -52,7 +53,11 @@ internal class OnlinePush {
override suspend fun QQAndroidBot.handle(packet: GroupMessage) {
if (packet.senderName == "Him188moe") {
this.getQQ(2978594313).sendMessage("FROM MIRAI")
packet.group.sendMessage("hello from mirai")
delay(100)
packet.group.sendMessage(packet.message)
delay(100)
this.getQQ(1040400290).sendMessage("FROM MIRAI")
}
}
}

View File

@ -16,6 +16,15 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
is At -> {
}
is Image -> {
elems.add(
ImMsgBody.Elem(
notOnlineImage = ImMsgBody.NotOnlineImage(
filePath = it.id.value
)
)
)
}
}
}
@ -23,23 +32,27 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
}
internal fun ImMsgBody.RichText.toMessageChain() : MessageChain{
internal fun ImMsgBody.RichText.toMessageChain(): MessageChain {
val message = MessageChain(initialCapacity = elems.size)
elems.forEach {
when {
it.notOnlineImage != null -> message.add(Image(
ImageIdQQA(
it.notOnlineImage.resId,
it.notOnlineImage.origUrl
it.notOnlineImage != null -> message.add(
Image(
ImageIdQQA(
it.notOnlineImage.resId,
it.notOnlineImage.origUrl
)
)
))
it.customFace != null -> message.add(Image(
ImageIdQQA(
it.customFace.filePath,
it.customFace.origUrl
)
it.customFace != null -> message.add(
Image(
ImageIdQQA(
it.customFace.filePath,
it.customFace.origUrl
)
)
))
)
it.text != null -> message.add(it.text.str.toMessage())
}
}