diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Member.kt b/mirai-core-api/src/commonMain/kotlin/contact/Member.kt index 5b93e26f4..6c3bde212 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Member.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Member.kt @@ -94,8 +94,8 @@ public interface Member : User { * @see FriendMessagePreSendEvent 当此成员是好友时发送消息前事件 * @see FriendMessagePostSendEvent 当此成员是好友时发送消息后事件 * - * @see TempMessagePreSendEvent 当此成员不是好友时发送消息前事件 - * @see TempMessagePostSendEvent 当此成员不是好友时发送消息后事件 + * @see GroupTempMessagePreSendEvent 当此成员不是好友时发送消息前事件 + * @see GroupTempMessagePostSendEvent 当此成员不是好友时发送消息后事件 * * @throws EventCancelledException 当发送消息事件被取消时抛出 * @throws BotIsBeingMutedException 发送群消息时若 [Bot] 被禁言抛出 diff --git a/mirai-core-api/src/commonMain/kotlin/contact/NormalMember.kt b/mirai-core-api/src/commonMain/kotlin/contact/NormalMember.kt index b9d306cb6..dd94b0e1f 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/NormalMember.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/NormalMember.kt @@ -98,8 +98,8 @@ public interface NormalMember : Member { * @see FriendMessagePreSendEvent 当此成员是好友时发送消息前事件 * @see FriendMessagePostSendEvent 当此成员是好友时发送消息后事件 * - * @see TempMessagePreSendEvent 当此成员不是好友时发送消息前事件 - * @see TempMessagePostSendEvent 当此成员不是好友时发送消息后事件 + * @see GroupTempMessagePreSendEvent 当此成员不是好友时发送消息前事件 + * @see GroupTempMessagePostSendEvent 当此成员不是好友时发送消息后事件 * * @throws EventCancelledException 当发送消息事件被取消时抛出 * @throws BotIsBeingMutedException 发送群消息时若 [Bot] 被禁言抛出 diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt index 0ff874685..4bb3ddff1 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessageEvent.kt @@ -86,7 +86,7 @@ public interface MessageEvent : Event, Packet, BotPassiveEvent { // TODO: 2021/1 * 来自 [User] 的消息 * * @see FriendMessageEvent - * @see TempMessageEvent + * @see GroupTempMessageEvent */ public interface UserMessageEvent : MessageEvent { public override val subject: User @@ -146,7 +146,7 @@ public class OtherClientMessageEvent constructor( * 来自一个可以知道其 [Group] 的用户消息 * * @see FriendMessageEvent - * @see TempMessageEvent + * @see GroupTempMessageEvent */ public interface GroupAwareMessageEvent : MessageEvent { public val group: Group @@ -198,21 +198,7 @@ public sealed class TempMessageEvent constructor( public override val sender: NormalMember, public override val message: MessageChain, public override val time: Int -) : AbstractMessageEvent(), GroupAwareMessageEvent, UserMessageEvent { - init { - val source = message[MessageSource] ?: error("Cannot find MessageSource from message") - check(source is OnlineMessageSource.Incoming.FromTemp) { "source provided to a TempMessageEvent must be an instance of OnlineMessageSource.Incoming.FromTemp" } - } - - public override val bot: Bot get() = sender.bot - public override val subject: NormalMember get() = sender - public override val group: Group get() = sender.group - public override val senderName: String get() = sender.nameCardOrNick - public override val source: OnlineMessageSource.Incoming.FromTemp get() = message.source as OnlineMessageSource.Incoming.FromTemp - - public override fun toString(): String = - "TempMessageEvent(sender=${sender.id} from group(${sender.group.id}), message=$message)" -} +) : AbstractMessageEvent(), GroupAwareMessageEvent, UserMessageEvent // support by mirai 2.1 // @@ -233,7 +219,7 @@ public class GroupTempMessageEvent( ) : @Suppress("DEPRECATION_ERROR") TempMessageEvent(sender, message, time), GroupAwareMessageEvent, UserMessageEvent { init { val source = message[MessageSource] ?: error("Cannot find MessageSource from message") - check(source is OnlineMessageSource.Incoming.FromTemp) { "source provided to a TempMessageEvent must be an instance of OnlineMessageSource.Incoming.FromTemp" } + check(source is OnlineMessageSource.Incoming.FromTemp) { "source provided to a GroupTempMessageEvent must be an instance of OnlineMessageSource.Incoming.FromTemp" } } public override val bot: Bot get() = sender.bot 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 20792b7d5..d4ca5a41f 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePostSendEvent.kt @@ -147,7 +147,15 @@ public data class FriendMessagePostSendEvent @MiraiInternalApi constructor( * 在群临时会话消息发送后广播的事件. * @see MessagePostSendEvent */ -public data class TempMessagePostSendEvent @MiraiInternalApi constructor( +@Deprecated( + "mirai 正计划支持其他渠道发起的临时会话, 届时此事件会变动. 原 TempMessagePostSendEvent 已更改为 GroupTempMessagePostSendEvent", + replaceWith = ReplaceWith( + "GroupTempMessagePostSendEvent", + "net.mamoe.mirai.event.events.GroupTempMessagePostSendEvent" + ), + DeprecationLevel.ERROR +) +public sealed class TempMessagePostSendEvent @MiraiInternalApi constructor( /** 发信目标. */ public override val target: Member, /** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */ @@ -163,7 +171,30 @@ public data class TempMessagePostSendEvent @MiraiInternalApi constructor( */ public override val receipt: MessageReceipt? ) : UserMessagePostSendEvent() { - public val group: Group get() = target.group + public open val group: Group get() = target.group +} + +/** + * 在群临时会话消息发送后广播的事件. + * @see MessagePostSendEvent + */ +public data class GroupTempMessagePostSendEvent @MiraiInternalApi constructor( + /** 发信目标. */ + public override val target: Member, + /** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */ + public override val message: MessageChain, + /** + * 发送消息时抛出的异常. `null` 表示消息成功发送. + * @see result + */ + public override val exception: Throwable?, + /** + * 发送消息成功时的回执. `null` 表示消息发送失败. + * @see result + */ + 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 351c1fa34..5c74ef5f3 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/MessagePreSendEvent.kt @@ -73,16 +73,37 @@ public data class FriendMessagePreSendEvent @MiraiInternalApi constructor( ) : UserMessagePreSendEvent() /** - * 在发送群临时会话消息前广播的事件. + * 在发送临时会话消息前广播的事件. * @see MessagePreSendEvent */ -public data class TempMessagePreSendEvent @MiraiInternalApi constructor( +@Deprecated( + "mirai 正计划支持其他渠道发起的临时会话, 届时此事件会变动. 原 TempMessagePreSendEvent 已更改为 GroupTempMessagePreSendEvent", + replaceWith = ReplaceWith( + "GroupTempMessagePreSendEvent", + "net.mamoe.mirai.event.events.GroupTempMessagePreSendEvent" + ), + DeprecationLevel.ERROR +) +public sealed class TempMessagePreSendEvent @MiraiInternalApi constructor( /** 发信目标. */ public override val target: Member, /** 待发送的消息. 修改后将会同时应用于发送. */ public override var message: Message ) : UserMessagePreSendEvent() { - public val group: Group get() = target.group + public open val group: Group get() = target.group +} + +/** + * 在发送群临时会话消息前广播的事件. + * @see MessagePreSendEvent + */ +public data class GroupTempMessagePreSendEvent @MiraiInternalApi constructor( + /** 发信目标. */ + public override val target: Member, + /** 待发送的消息. 修改后将会同时应用于发送. */ + public override var message: Message +) : @kotlin.Suppress("DEPRECATION_ERROR") TempMessagePreSendEvent(target, message) { + public override val group: Group get() = target.group } /** diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/README.md b/mirai-core-api/src/commonMain/kotlin/event/events/README.md index 9c87c1215..9f85d5a3e 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/README.md +++ b/mirai-core-api/src/commonMain/kotlin/event/events/README.md @@ -28,15 +28,21 @@ - 被动收到消息:[MessageEvent](MessageEvent.kt) - 群消息:GroupMessageEvent - 好友消息:FriendMessageEvent - - 群临时会话消息:TempMessageEvent + - 群临时会话消息:GroupTempMessageEvent + - 陌生人消息:StrangerMessageEvent + - 其他客户端消息:OtherClientMessageEvent - 主动发送消息前: [MessagePreSendEvent](MessagePreSendEvent.kt) - 群消息: GroupMessagePreSendEvent - 好友消息: FriendMessagePreSendEvent - - 群临时会话消息: TempMessagePreSendEvent + - 群临时会话消息: GroupTempMessagePreSendEvent + - 陌生人消息:StrangerMessagePreSendEvent + - 其他客户端消息:OtherClientMessagePreSendEvent - 主动发送消息后: [MessagePostSendEvent](MessagePostSendEvent.kt) - 群消息: GroupMessagePostSendEvent - 好友消息: FriendMessagePostSendEvent - - 群临时会话消息: TempMessagePostSendEvent + - 群临时会话消息: GroupTempMessagePostSendEvent + - 陌生人消息:StrangerMessagePostSendEvent + - 其他客户端消息:OtherClientMessagePostSendEvent - 消息撤回: [MessageRecallEvent](MessageRecallEvent.kt) - 好友撤回: FriendRecall - 群撤回: GroupRecall diff --git a/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt b/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt index c7c475204..cd387354f 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt @@ -69,7 +69,7 @@ public typealias MessageEventSubscribersBuilder = MessageSubscribersBuilder { val chain = kotlin.runCatching { - TempMessagePreSendEvent(this, message).broadcast() + GroupTempMessagePreSendEvent(this, message).broadcast() }.onSuccess { check(!it.isCancelled) { - throw EventCancelledException("cancelled by TempMessagePreSendEvent") + throw EventCancelledException("cancelled by GroupTempMessagePreSendEvent") } }.getOrElse { - throw EventCancelledException("exception thrown when broadcasting TempMessagePreSendEvent", it) + throw EventCancelledException("exception thrown when broadcasting GroupTempMessagePreSendEvent", it) }.message.toMessageChain() chain.firstIsInstanceOrNull()?.source?.ensureSequenceIdAvailable() @@ -98,10 +98,10 @@ internal class NormalMemberImpl constructor( result.fold( onSuccess = { - TempMessagePostSendEvent(this, chain, null, it) + GroupTempMessagePostSendEvent(this, chain, null, it) }, onFailure = { - TempMessagePostSendEvent(this, chain, it, null) + GroupTempMessagePostSendEvent(this, chain, it, null) } ).broadcast() diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/PbMessageSvc.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/PbMessageSvc.kt index a975366f6..a8083d4b5 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/PbMessageSvc.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/PbMessageSvc.kt @@ -79,7 +79,7 @@ internal class PbMessageSvc { } } - fun createForTempMessage( + fun createForGroupTempMessage( client: QQAndroidClient, groupUin: Long, toUin: Long,