Commit eb1da6a3 authored by Him188's avatar Him188

Add qAge and personalStatement for Profile

parent c271e340
...@@ -193,11 +193,14 @@ enum class MemberPermission { ...@@ -193,11 +193,14 @@ enum class MemberPermission {
data class Profile( data class Profile(
val qq: UInt, val qq: UInt,
val nickname: String, val nickname: String,
val englishName: String?,
val chineseName: String?,
val qAge: Int?, // q 龄
val zipCode: String?, val zipCode: String?,
val phone: String?, val phone: String?,
val gender: Gender, val gender: Gender,
val birthday: Date?, val birthday: Date?,
val personalStatus: String?, val personalStatement: String?,// 个人说明
val school: String?, val school: String?,
val homepage: String?, val homepage: String?,
val email: String?, val email: String?,
......
...@@ -60,9 +60,14 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR ...@@ -60,9 +60,14 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR
val qq = readUInt() val qq = readUInt()
discardExact(6) discardExact(6)
val map = readTLVMap(tagSize = 2, expectingEOF = true) val map = readTLVMap(tagSize = 2, expectingEOF = true)
map.printTLVMap("Profile(qq=$qq) raw=")
map.mapValues { it.value.encodeToString() }.printTLVMap("Profile(qq=$qq) str=")
val profile = Profile( val profile = Profile(
qq = qq, qq = qq,
nickname = map[0x4E22u]?.encodeToString() ?: "",//error("Cannot determine nickname") nickname = map[0x4E22u]?.encodeToString() ?: "",//error("Cannot determine nickname")
englishName = map[0x4E54u]?.encodeToString(),
chineseName = map[0x4E2Au]?.encodeToString(),
qAge = map[0x6597u]?.toUInt()?.toInt(),
zipCode = map[0x4E25u]?.encodeToString(), zipCode = map[0x4E25u]?.encodeToString(),
phone = map[0x4E27u]?.encodeToString(), phone = map[0x4E27u]?.encodeToString(),
gender = when (map[0x4E29u]?.let { it[0] }?.toUInt()) { gender = when (map[0x4E29u]?.let { it[0] }?.toUInt()) {
...@@ -73,7 +78,7 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR ...@@ -73,7 +78,7 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR
//else -> error("Cannot determine gender, bad value of 0x4E29u: ${map[0x4729u]!![0].toUHexString()}") //else -> error("Cannot determine gender, bad value of 0x4E29u: ${map[0x4729u]!![0].toUHexString()}")
}, },
birthday = map[0x4E3Fu]?.let { Date(it.toUInt().toInt()) }, birthday = map[0x4E3Fu]?.let { Date(it.toUInt().toInt()) },
personalStatus = map[0x4E33u]?.encodeToString(), personalStatement = map[0x4E33u]?.encodeToString(),
homepage = map[0x4E2Du]?.encodeToString(), homepage = map[0x4E2Du]?.encodeToString(),
company = map[0x5DC8u]?.encodeToString(), company = map[0x5DC8u]?.encodeToString(),
school = map[0x4E35u]?.encodeToString(), school = map[0x4E35u]?.encodeToString(),
......
...@@ -66,8 +66,12 @@ fun Input.readTLVMap(expectingEOF: Boolean = false, tagSize: Int = 1): MutableMa ...@@ -66,8 +66,12 @@ fun Input.readTLVMap(expectingEOF: Boolean = false, tagSize: Int = 1): MutableMa
return map return map
} }
fun Map<*, ByteArray>.printTLVMap(name: String) = fun Map<UInt, ByteArray>.printTLVMap(name: String) =
debugPrintln("TLVMap $name= " + this.mapValues { (_, value) -> value.toUHexString() }) debugPrintln("TLVMap $name= " + this.mapValues { (_, value) -> value.toUHexString() }.mapKeys { it.key.toInt().toUShort().toUHexString() })
@JvmName("printTLVStringMap")
fun Map<UInt, String>.printTLVMap(name: String) =
debugPrintln("TLVMap $name= " + this.mapKeys { it.key.toInt().toUShort().toUHexString() })
fun Input.readString(length: Int): String = String(this.readBytes(length)) fun Input.readString(length: Int): String = String(this.readBytes(length))
fun Input.readString(length: Long): String = String(this.readBytes(length.toInt())) fun Input.readString(length: Long): String = String(this.readBytes(length.toInt()))
......
...@@ -120,7 +120,10 @@ fun getRandomString(length: Int, vararg charRanges: CharRange): String = ...@@ -120,7 +120,10 @@ fun getRandomString(length: Int, vararg charRanges: CharRange): String =
* 本函数将 4 个 [Byte] 的 bits 连接得到 [Int] * 本函数将 4 个 [Byte] 的 bits 连接得到 [Int]
*/ */
fun ByteArray.toUInt(): UInt = fun ByteArray.toUInt(): UInt =
this[0].toUInt().and(255u).shl(24) + this[1].toUInt().and(255u).shl(16) + this[2].toUInt().and(255u).shl(8) + this[3].toUInt().and(255u).shl(0) (this[0].toUInt().and(255u) shl 24) + (this[1].toUInt().and(255u) shl 16) + (this[2].toUInt().and(255u) shl 8) + (this[3].toUInt().and(255u) shl 0)
fun ByteArray.toUShort(): UShort =
((this[0].toUInt().and(255u) shl 8) + (this[1].toUInt().and(255u) shl 0)).toUShort()
/** /**
* 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入. * 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入.
......
...@@ -7,13 +7,10 @@ import kotlinx.coroutines.GlobalScope ...@@ -7,13 +7,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import net.mamoe.mirai.Bot import net.mamoe.mirai.*
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.addFriend
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.login
import net.mamoe.mirai.message.Image import net.mamoe.mirai.message.Image
import net.mamoe.mirai.network.protocol.tim.packet.action.downloadAsByteArray import net.mamoe.mirai.network.protocol.tim.packet.action.downloadAsByteArray
import net.mamoe.mirai.network.protocol.tim.packet.event.FriendMessage import net.mamoe.mirai.network.protocol.tim.packet.event.FriendMessage
...@@ -55,8 +52,13 @@ suspend fun main() { ...@@ -55,8 +52,13 @@ suspend fun main() {
bot.subscribeMessages { bot.subscribeMessages {
"你好" reply "你好!" "你好" reply "你好!"
"profile" reply { startsWith("profile", removePrefix = true) {
sender.profile.await().toString() val account = it.trim()
if (account.isNotEmpty()) {
bot.getQQ(account.toUInt())
} else {
sender
}.profile.await().toString()
} }
has<Image> { has<Image> {
......
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