From 0b2bb82d10e5282420943550ef854ed288379ebc Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 12 Jan 2021 18:08:33 +0800 Subject: [PATCH] Change Member to NormalMember for capable events --- .../event/events/MessagePostSendEvent.kt | 4 +-- .../event/events/MessagePreSendEvent.kt | 2 +- .../commonMain/kotlin/event/events/group.kt | 28 +++++++++---------- .../commonMain/kotlin/contact/GroupImpl.kt | 4 +-- .../chat/receive/OnlinePush.PbPushTransMsg.kt | 4 ++- .../packet/chat/receive/OnlinePush.ReqPush.kt | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt index d4ca5a41f..880c616ac 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt @@ -180,7 +180,7 @@ public sealed class TempMessagePostSendEvent @MiraiInternalApi constructor( */ public data class GroupTempMessagePostSendEvent @MiraiInternalApi constructor( /** 发信目标. */ - public override val target: Member, + public override val target: NormalMember, /** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */ public override val message: MessageChain, /** @@ -192,7 +192,7 @@ public data class GroupTempMessagePostSendEvent @MiraiInternalApi constructor( * 发送消息成功时的回执. `null` 表示消息发送失败. * @see result */ - public override val receipt: MessageReceipt? + public override val receipt: MessageReceipt? ) : @kotlin.Suppress("DEPRECATION_ERROR") TempMessagePostSendEvent(target, message, exception, receipt) { public override val group: Group get() = target.group } diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt index 5c74ef5f3..d4b7755b8 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt @@ -99,7 +99,7 @@ public sealed class TempMessagePreSendEvent @MiraiInternalApi constructor( */ public data class GroupTempMessagePreSendEvent @MiraiInternalApi constructor( /** 发信目标. */ - public override val target: Member, + public override val target: NormalMember, /** 待发送的消息. 修改后将会同时应用于发送. */ public override var message: Message ) : @kotlin.Suppress("DEPRECATION_ERROR") TempMessagePreSendEvent(target, message) { diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt index 02dbd75f7..39c7d9bcd 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt @@ -46,7 +46,7 @@ public sealed class BotLeaveEvent : BotEvent, Packet, AbstractEvent() { */ @MiraiExperimentalApi("BotLeaveEvent 的子类可能在将来改动. 使用 BotLeaveEvent 以保证兼容性.") public data class Kick @MiraiInternalApi constructor( - public override val operator: Member + public override val operator: NormalMember ) : BotLeaveEvent(), GroupOperableEvent { public override val group: Group get() = operator.group @@ -74,7 +74,7 @@ public data class BotMuteEvent @MiraiInternalApi constructor( /** * 操作人. */ - public val operator: Member + public val operator: NormalMember ) : GroupEvent, Packet, BotPassiveEvent, AbstractEvent() { public override val group: Group get() = operator.group @@ -87,7 +87,7 @@ public data class BotUnmuteEvent @MiraiInternalApi constructor( /** * 操作人. */ - public val operator: Member + public val operator: NormalMember ) : GroupEvent, Packet, BotPassiveEvent, AbstractEvent() { public override val group: Group get() = operator.group @@ -119,7 +119,7 @@ public sealed class BotJoinGroupEvent : GroupEvent, BotPassiveEvent, Packet, Abs /** * 邀请人 */ - public val invitor: Member + public val invitor: NormalMember ) : BotJoinGroupEvent() { public override val group: Group get() = invitor.group @@ -163,7 +163,7 @@ public data class GroupNameChangeEvent @MiraiInternalApi constructor( /** * 操作人. 为 null 时则是机器人操作 */ - public override val operator: Member? + public override val operator: NormalMember? ) : GroupSettingChangeEvent, Packet, GroupOperableEvent, AbstractEvent() /** @@ -176,7 +176,7 @@ public data class GroupEntranceAnnouncementChangeEvent @MiraiInternalApi constru /** * 操作人. 为 null 时则是机器人操作 */ - public override val operator: Member? + public override val operator: NormalMember? ) : GroupSettingChangeEvent, Packet, GroupOperableEvent, AbstractEvent() @@ -190,7 +190,7 @@ public data class GroupMuteAllEvent @MiraiInternalApi constructor( /** * 操作人. 为 null 时则是机器人操作 */ - public override val operator: Member? + public override val operator: NormalMember? ) : GroupSettingChangeEvent, Packet, GroupOperableEvent, AbstractEvent() @@ -204,7 +204,7 @@ public data class GroupAllowAnonymousChatEvent @MiraiInternalApi constructor( /** * 操作人. 为 null 时则是机器人操作 */ - public override val operator: Member? + public override val operator: NormalMember? ) : GroupSettingChangeEvent, Packet, GroupOperableEvent, AbstractEvent() @@ -228,7 +228,7 @@ public data class GroupAllowMemberInviteEvent @MiraiInternalApi constructor( /** * 操作人. 为 null 时则是机器人操作 */ - public override val operator: Member? + public override val operator: NormalMember? ) : GroupSettingChangeEvent, Packet, GroupOperableEvent, AbstractEvent() @@ -417,7 +417,7 @@ public data class MemberCardChangeEvent @MiraiInternalApi constructor( */ public val new: String, - public override val member: Member + public override val member: NormalMember ) : GroupMemberEvent, Packet, AbstractEvent() /** @@ -434,7 +434,7 @@ public data class MemberSpecialTitleChangeEvent @MiraiInternalApi constructor( */ public val new: String, - public override val member: Member, + public override val member: NormalMember, /** * 操作人. @@ -453,7 +453,7 @@ public data class MemberSpecialTitleChangeEvent @MiraiInternalApi constructor( * 成员权限改变的事件. 成员不可能是机器人自己. */ public data class MemberPermissionChangeEvent @MiraiInternalApi constructor( - public override val member: Member, + public override val member: NormalMember, public val origin: MemberPermission, public val new: MemberPermission ) : GroupMemberEvent, BotPassiveEvent, Packet, AbstractEvent() @@ -513,7 +513,7 @@ public sealed class MemberHonorChangeEvent : GroupMemberEvent, BotPassiveEvent, */ public data class Achieve(override val member: NormalMember, override val honorType: GroupHonorType) : MemberHonorChangeEvent() { - + override fun toString(): String { return "MemberHonorChangeEvent.Achieve(member=$member, honorType=$honorType)" } @@ -524,7 +524,7 @@ public sealed class MemberHonorChangeEvent : GroupMemberEvent, BotPassiveEvent, */ public data class Lose(override val member: NormalMember, override val honorType: GroupHonorType) : MemberHonorChangeEvent() { - + override fun toString(): String { return "MemberHonorChangeEvent.Lose(member=$member, honorType=$honorType)" } diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index 7abefb676..8e28bcae2 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -322,7 +322,7 @@ internal fun Group.newMember(memberInfo: MemberInfo): Member { ) } -internal fun GroupImpl.newAnonymous(name: String, id: String): Member = newMember( +internal fun GroupImpl.newAnonymous(name: String, id: String): AnonymousMemberImpl = newMember( MemberInfoImpl( uin = 80000000L, nick = name, @@ -333,4 +333,4 @@ internal fun GroupImpl.newAnonymous(name: String, id: String): Member = newMembe muteTimestamp = 0, anonymousId = id, ) -) +) as AnonymousMemberImpl diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt index dea55ff20..b5f391b80 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt @@ -19,6 +19,7 @@ import kotlinx.io.core.discardExact import kotlinx.io.core.readUByte import kotlinx.io.core.readUInt import net.mamoe.mirai.contact.MemberPermission +import net.mamoe.mirai.contact.NormalMember import net.mamoe.mirai.event.events.* import net.mamoe.mirai.internal.QQAndroidBot import net.mamoe.mirai.internal.contact.* @@ -136,7 +137,8 @@ internal object OnlinePushPbPushTransMsg : owner.checkIsMemberImpl().permission = MemberPermission.OWNER group.members.delegate.add(owner) results.add(MemberJoinEvent.Retrieve(owner)) - } + }.cast() + if (newOwner.permission != MemberPermission.OWNER) { results.add( MemberPermissionChangeEvent( diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt index 1ea64c5f2..387953ab1 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt @@ -169,7 +169,7 @@ internal inline fun lambda732(crossinline block: ByteReadPacket.(GroupImpl, QQAn private fun handleMuteMemberPacket( bot: QQAndroidBot, group: GroupImpl, - operator: Member, + operator: NormalMember, target: Long, timeSeconds: Int ): Packet? {