Add qAge and personalStatement for Profile

This commit is contained in:
Him188 2019-11-15 18:22:29 +08:00
parent c271e3402e
commit eb1da6a326
5 changed files with 28 additions and 11 deletions

View File

@ -193,11 +193,14 @@ enum class MemberPermission {
data class Profile(
val qq: UInt,
val nickname: String,
val englishName: String?,
val chineseName: String?,
val qAge: Int?, // q 龄
val zipCode: String?,
val phone: String?,
val gender: Gender,
val birthday: Date?,
val personalStatus: String?,
val personalStatement: String?,// 个人说明
val school: String?,
val homepage: String?,
val email: String?,

View File

@ -60,9 +60,14 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR
val qq = readUInt()
discardExact(6)
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(
qq = qq,
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(),
phone = map[0x4E27u]?.encodeToString(),
gender = when (map[0x4E29u]?.let { it[0] }?.toUInt()) {
@ -73,7 +78,7 @@ object RequestProfileDetailsPacket : SessionPacketFactory<RequestProfileDetailsR
//else -> error("Cannot determine gender, bad value of 0x4E29u: ${map[0x4729u]!![0].toUHexString()}")
},
birthday = map[0x4E3Fu]?.let { Date(it.toUInt().toInt()) },
personalStatus = map[0x4E33u]?.encodeToString(),
personalStatement = map[0x4E33u]?.encodeToString(),
homepage = map[0x4E2Du]?.encodeToString(),
company = map[0x5DC8u]?.encodeToString(),
school = map[0x4E35u]?.encodeToString(),

View File

@ -66,8 +66,12 @@ fun Input.readTLVMap(expectingEOF: Boolean = false, tagSize: Int = 1): MutableMa
return map
}
fun Map<*, ByteArray>.printTLVMap(name: String) =
debugPrintln("TLVMap $name= " + this.mapValues { (_, value) -> value.toUHexString() })
fun Map<UInt, ByteArray>.printTLVMap(name: String) =
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: Long): String = String(this.readBytes(length.toInt()))

View File

@ -120,7 +120,10 @@ fun getRandomString(length: Int, vararg charRanges: CharRange): String =
* 本函数将 4 [Byte] bits 连接得到 [Int]
*/
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] 写入.

View File

@ -7,13 +7,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.addFriend
import net.mamoe.mirai.*
import net.mamoe.mirai.event.Subscribable
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.login
import net.mamoe.mirai.message.Image
import net.mamoe.mirai.network.protocol.tim.packet.action.downloadAsByteArray
import net.mamoe.mirai.network.protocol.tim.packet.event.FriendMessage
@ -55,8 +52,13 @@ suspend fun main() {
bot.subscribeMessages {
"你好" reply "你好!"
"profile" reply {
sender.profile.await().toString()
startsWith("profile", removePrefix = true) {
val account = it.trim()
if (account.isNotEmpty()) {
bot.getQQ(account.toUInt())
} else {
sender
}.profile.await().toString()
}
has<Image> {