Commit dcdee6b8 authored by Him188's avatar Him188

At supported

parent bf8e65e9
...@@ -218,10 +218,10 @@ suspend inline fun ImageId.sendTo(contact: Contact) = contact.sendMessage(this.i ...@@ -218,10 +218,10 @@ suspend inline fun ImageId.sendTo(contact: Contact) = contact.sendMessage(this.i
/** /**
* At 一个人 * At 一个人
*/ */
inline class At(val targetQQ: UInt) : Message { inline class At(val target: UInt) : Message {
constructor(target: QQ) : this(target.id) constructor(target: QQ) : this(target.id)
override val stringValue: String get() = "[@$targetQQ]" override val stringValue: String get() = "[@$target]" // TODO: 2019/11/25 使用群名称进行 at. 因为手机端只会显示这个文字
override fun toString(): String = stringValue override fun toString(): String = stringValue
companion object Key : Message.Key<At> companion object Key : Message.Key<At>
......
...@@ -6,7 +6,7 @@ package net.mamoe.mirai.message ...@@ -6,7 +6,7 @@ package net.mamoe.mirai.message
@Suppress("unused") @Suppress("unused")
enum class MessageType(val value: UByte) { enum class MessageType(val value: UByte) {
PLAIN_TEXT(0x01u), PLAIN_TEXT(0x01u),
AT(0x06u), AT(0x01u), // same as PLAIN
FACE(0x02u), FACE(0x02u),
/** /**
* [ImageId.value] 长度为 42 的图片 * [ImageId.value] 长度为 42 的图片
......
...@@ -18,9 +18,16 @@ internal fun IoBuffer.parseMessageFace(): Face { ...@@ -18,9 +18,16 @@ internal fun IoBuffer.parseMessageFace(): Face {
return Face(id1) return Face(id1)
} }
internal fun IoBuffer.parsePlainText(): PlainText { internal fun IoBuffer.parsePlainTextOrAt(): Message {
discardExact(1)//0x01 // 06 00 0D 00 01 00 00 00 08 00 76 E4 B8 DD 00 00
return PlainText(readUShortLVString()) discardExact(1)// 0x01 whenever plain or at
val msg = readUShortLVString()
return if (this.readRemaining == 0) {
PlainText(msg)
} else {
discardExact(10)
At(readUInt())
}
} }
internal fun IoBuffer.parseLongText0x19(): PlainText { internal fun IoBuffer.parseLongText0x19(): PlainText {
...@@ -59,7 +66,7 @@ internal fun IoBuffer.parseMessageImage0x06(): Image { ...@@ -59,7 +66,7 @@ internal fun IoBuffer.parseMessageImage0x06(): Image {
internal fun IoBuffer.parseMessageImage0x03(): Image { internal fun IoBuffer.parseMessageImage0x03(): Image {
//discardExact(1) //discardExact(1)
val tlv = readTLVMap(expectingEOF = true, tagSize = 1) val tlv = readTLVMap(expectingEOF = true, tagSize = 1)
tlv.printTLVMap("parseMessageImage0x03") //tlv.printTLVMap("parseMessageImage0x03")
// 02 [ ] IMAGE ID // 02 [ ] IMAGE ID
// 04 [00 04] 8B 88 95 C1 // 04 [00 04] 8B 88 95 C1
// 05 [00 04] 3B 24 59 FC // 05 [00 04] 3B 24 59 FC
...@@ -85,7 +92,7 @@ internal fun IoBuffer.parseMessageImage0x03(): Image { ...@@ -85,7 +92,7 @@ internal fun IoBuffer.parseMessageImage0x03(): Image {
uniqueId = tlv[0x04u]!!.read { readUInt() }, uniqueId = tlv[0x04u]!!.read { readUInt() },
height = tlv[0x16u]!!.toUInt().toInt(), height = tlv[0x16u]!!.toUInt().toInt(),
width = tlv[0x15u]!!.toUInt().toInt() width = tlv[0x15u]!!.toUInt().toInt()
).also { debugPrintln("ImageId: $it") } )//.also { debugPrintln("ImageId: $it") }
) )
//} else { //} else {
// Image( // Image(
...@@ -113,8 +120,7 @@ internal fun ByteReadPacket.readMessage(): Message? { ...@@ -113,8 +120,7 @@ internal fun ByteReadPacket.readMessage(): Message? {
return try { return try {
when (messageType) { when (messageType) {
//todo 在每个parse里面都 discard 了第一 byte. 0x01 -> sectionData.parsePlainTextOrAt()
0x01 -> sectionData.parsePlainText()
0x02 -> sectionData.parseMessageFace() 0x02 -> sectionData.parseMessageFace()
0x03 -> sectionData.parseMessageImage0x03() 0x03 -> sectionData.parseMessageImage0x03()
0x06 -> sectionData.parseMessageImage0x06() 0x06 -> sectionData.parseMessageImage0x06()
...@@ -196,7 +202,18 @@ fun MessageChain.toPacket(): ByteReadPacket = buildPacket { ...@@ -196,7 +202,18 @@ fun MessageChain.toPacket(): ByteReadPacket = buildPacket {
} }
} }
is At -> throw UnsupportedOperationException("At is not supported now but is expecting to be supported") is At -> buildPacket {
writeUByte(MessageType.AT.value)
writeShortLVPacket {
writeByte(0x01)
writeShortLVString(stringValue) // 这个应该是 "@群名", 手机上面会显示这个消息, 电脑会显示下面那个
// 06 00 0D 00 01 00 00 00 08 00 76 E4 B8 DD 00 00
writeHex("06 00 0D 00 01 00 00 00 08 00")
writeUInt(target)
writeZero(2)
}
}
is Image -> buildPacket { is Image -> buildPacket {
when (id.value.length) { when (id.value.length) {
......
...@@ -4,9 +4,10 @@ package net.mamoe.mirai.network.protocol.tim.packet.event ...@@ -4,9 +4,10 @@ package net.mamoe.mirai.network.protocol.tim.packet.event
import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.ByteReadPacket
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.utils.io.toUHexString
inline class IgnoredEventPacket(val id: UShort) : EventPacket { inline class IgnoredEventPacket(val id: UShort) : EventPacket {
override fun toString(): String = "IgnoredEventPacket(id=$id)" override fun toString(): String = "IgnoredEventPacket(id=0x${id.toUHexString("")})"
} }
object IgnoredEventIds : List<IgnoredEventParserAndHandler> by { object IgnoredEventIds : List<IgnoredEventParserAndHandler> by {
......
...@@ -12,6 +12,7 @@ import net.mamoe.mirai.contact.MemberPermission ...@@ -12,6 +12,7 @@ import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.Subscribable import net.mamoe.mirai.event.Subscribable
import net.mamoe.mirai.event.subscribeAlways import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.event.subscribeMessages import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.message.At
import net.mamoe.mirai.message.Image import net.mamoe.mirai.message.Image
import net.mamoe.mirai.message.getValue import net.mamoe.mirai.message.getValue
import net.mamoe.mirai.message.sendAsImageTo import net.mamoe.mirai.message.sendAsImageTo
...@@ -60,6 +61,8 @@ suspend fun main() { ...@@ -60,6 +61,8 @@ suspend fun main() {
} }
bot.subscribeMessages { bot.subscribeMessages {
case("at me") { At(sender).reply() }
"你好" reply "你好!" "你好" reply "你好!"
startsWith("profile", removePrefix = true) { startsWith("profile", removePrefix = true) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment