From 433e1fdadc3024572cc1a772c2945c93acaae94b Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 27 Nov 2019 20:28:27 +0800 Subject: [PATCH] Add queryPreviousNameList --- .../kotlin/net.mamoe.mirai/contact/QQ.kt | 10 +++++++++ .../contact/internal/ContactImpl.kt | 21 +++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt index da33fd3a2..2e77aa3cc 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.Deferred import net.mamoe.mirai.Bot import net.mamoe.mirai.contact.data.Profile import net.mamoe.mirai.network.BotSession +import net.mamoe.mirai.network.protocol.tim.packet.action.PreviousNameList /** * QQ 对象. @@ -33,4 +34,13 @@ interface QQ : Contact { * 将会同步更新 property [profile] */ suspend fun updateProfile(): Profile + + /** + * 查询曾用名. + * + * 曾用名可能是: + * - 昵称 + * - 共同群内的群名片 + */ + suspend fun queryPreviousNameList(): PreviousNameList } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt index 5c825547c..76a12a6bb 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt @@ -13,10 +13,7 @@ import net.mamoe.mirai.message.Message import net.mamoe.mirai.message.MessageChain import net.mamoe.mirai.message.chain import net.mamoe.mirai.message.singleChain -import net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsPacket -import net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsResponse -import net.mamoe.mirai.network.protocol.tim.packet.action.SendFriendMessagePacket -import net.mamoe.mirai.network.protocol.tim.packet.action.SendGroupMessagePacket +import net.mamoe.mirai.network.protocol.tim.packet.action.* import net.mamoe.mirai.network.sessionKey import net.mamoe.mirai.utils.SuspendLazy @@ -41,11 +38,11 @@ internal data class GroupImpl internal constructor(override val bot: Bot, val gr override suspend fun getMember(id: UInt): Member = if (_members.containsKey(id)) _members[id]!! else membersLock.withLock { - _members.getOrPut(id) { MemberImpl(bot, bot.getQQ(id), this) } + _members.getOrPut(id) { MemberImpl(bot.getQQ(id), this) } } override suspend fun sendMessage(message: MessageChain) { - bot.sendPacket(SendGroupMessagePacket(bot.qqAccount, internalId, bot.sessionKey, message)) + bot.sendPacket(GroupPacket.Message(bot.qqAccount, internalId, bot.sessionKey, message)) } override fun toString(): String = "Group(${this.id})" @@ -67,18 +64,16 @@ internal data class QQImpl internal constructor(override val bot: Bot, override return _profile!! } + override suspend fun queryPreviousNameList(): PreviousNameList = bot.withSession { + QueryPreviousNamePacket(bot.qqAccount, sessionKey, id).sendAndExpect() + } + override fun toString(): String = "QQ(${this.id})" } /** * 群成员 */ -internal data class MemberImpl(override val bot: Bot, private val delegate: QQ, override val group: Group) : Member, ContactImpl() { - override val profile: Deferred get() = delegate.profile - override val id: UInt get() = delegate.id - - override suspend fun updateProfile(): Profile = delegate.updateProfile() - override suspend fun sendMessage(message: MessageChain) = delegate.sendMessage(message) - +internal data class MemberImpl(private val delegate: QQ, override val group: Group) : QQ by delegate, Member { override fun toString(): String = "Member(${this.id})" } \ No newline at end of file