diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt index 5a0b3fdae..e8f94beeb 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt @@ -182,11 +182,11 @@ internal abstract class QQAndroidBotBase constructor( } @Suppress("RemoveExplicitTypeArguments") // false positive - @ExperimentalMessageSource override suspend fun recall(source: MessageSource) { // println(source._miraiContentToString()) check(source is MessageSourceImpl) + source.ensureSequenceIdAvailable() val response: PbMessageSvc.PbMsgWithDraw.Response = when (source) { is MessageSourceToGroupImpl, @@ -216,6 +216,7 @@ internal abstract class QQAndroidBotBase constructor( ).sendAndExpect() } } + is OfflineMessageSource, is MessageSourceFromFriendImpl, is MessageSourceToFriendImpl -> network.run { @@ -227,7 +228,7 @@ internal abstract class QQAndroidBotBase constructor( source.time ).sendAndExpect() } - else -> error("stub") + else -> error("stub!") } check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${source.id}: $response" } diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt index 64ef2a90f..49d023f10 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt @@ -12,8 +12,6 @@ package net.mamoe.mirai.qqandroid.utils -import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.message.data.AtAll.display import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -32,6 +30,7 @@ internal fun Int.toIpV4AddressString(): String { } } +/* internal fun String.chineseLength(upTo: Int): Int { return this.sumUpTo(upTo) { if (it in '\u0391'..'\uFFE5') 3 else 1 } } @@ -41,11 +40,10 @@ internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int = it.estimateLength(up) } -@OptIn(ExperimentalMessageSource::class) internal fun SingleMessage.estimateLength(upTo: Int = Int.MAX_VALUE): Int { return when (this) { is QuoteReply -> { - 700 + source.originalMessage.estimateLength(upTo) + 700 } // is Image -> 300 is PlainText -> stringValue.chineseLength(upTo) @@ -76,3 +74,4 @@ internal inline fun CharSequence.sumUpTo(upTo: Int, selector: (Char) -> Int): In } return sum } +*/ \ No newline at end of file diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt index bdbb0a9a1..5e0d51757 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt @@ -5,7 +5,6 @@ import net.mamoe.mirai.contact.PermissionDeniedException import net.mamoe.mirai.contact.recall import net.mamoe.mirai.data.AddFriendResult import net.mamoe.mirai.message.MessageReceipt -import net.mamoe.mirai.message.data.ExperimentalMessageSource import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageSource @@ -62,7 +61,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { * * @see Bot.recall (扩展函数) 接受参数 [MessageChain] */ - @ExperimentalMessageSource @JvmName("recall") fun __recallBlockingForJava__(source: MessageSource) { runBlocking { recall(source) } @@ -90,7 +88,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { * @param millis 延迟的时间, 单位为毫秒 * @see recall */ - @ExperimentalMessageSource @JvmName("recallIn") fun __recallIn_MemberForJava__(source: MessageSource, millis: Long) { runBlocking { recallIn(source, millis) } @@ -151,7 +148,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { /** * 异步调用 [__recallBlockingForJava__] */ - @ExperimentalMessageSource @JvmName("recallAsync") fun __recallAsyncForJava__(source: MessageSource): Future { return future { recall(source) } diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt index e2b75c1f8..ebf631b1e 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt @@ -11,7 +11,6 @@ import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.QQ -import net.mamoe.mirai.message.data.ExperimentalMessageSource import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.OnlineMessageSource import net.mamoe.mirai.message.data.QuoteReply @@ -24,16 +23,18 @@ import net.mamoe.mirai.utils.unsafeWeakRef * * 此对象持有 [Contact] 的弱引用, [Bot] 离线后将会释放引用, 届时 [target] 将无法访问. * + * @param source 指代发送出去的消息 + * @param target 消息发送对象 + * * @see Group.sendMessage 发送群消息, 返回回执(此对象) * @see QQ.sendMessage 发送群消息, 返回回执(此对象) * * @see MessageReceipt.sourceId 源 id - * @see MessageReceipt.sourceSequenceId 源序列号 * @see MessageReceipt.sourceTime 源时间 */ @Suppress("FunctionName") @OptIn(MiraiInternalAPI::class) -actual open class MessageReceipt @OptIn(ExperimentalMessageSource::class) +actual open class MessageReceipt actual constructor( actual val source: OnlineMessageSource.Outgoing, target: C, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index 92de5b796..82e751b6c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.event.BroadcastControllable import net.mamoe.mirai.event.CancellableEvent import net.mamoe.mirai.event.events.ImageUploadEvent.Failed import net.mamoe.mirai.event.events.ImageUploadEvent.Succeed -import net.mamoe.mirai.message.data.ExperimentalMessageSource import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageSource @@ -98,7 +97,6 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractCancellableEve /** * 消息撤回事件. 可是任意消息被任意人撤回. */ -@OptIn(ExperimentalMessageSource::class) sealed class MessageRecallEvent : BotEvent { /** * 消息原发送人 diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt index b0d975c1d..61c5c5846 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt @@ -34,7 +34,7 @@ import kotlin.jvm.JvmSynthetic * @see MessageReceipt.sourceId 源 id * @see MessageReceipt.sourceTime 源时间 */ -expect open class MessageReceipt @OptIn(ExperimentalMessageSource::class) constructor( +expect open class MessageReceipt( source: OnlineMessageSource.Outgoing, target: C, botAsMember: Member? diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt index 063420a62..dc5bf6cdd 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt @@ -69,7 +69,7 @@ interface Message { * * @param M 指代持有这个 Key 的消息类型 */ - interface Key + interface Key infix fun eq(other: Message): Boolean = this.toString() == other.toString() diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt index c6f47d73b..e48a29af1 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt @@ -132,7 +132,7 @@ inline fun MessageChain.any(): Boolean = this.any { it is /** * 获取第一个 [M] 类型的 [Message] 实例 */ -@OptIn(ExperimentalMessageSource::class, MiraiExperimentalAPI::class) +@OptIn(MiraiExperimentalAPI::class) @JvmSynthetic @Suppress("UNCHECKED_CAST") fun MessageChain.firstOrNull(key: Message.Key): M? = when (key) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt index 7da76914e..c884707de 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt @@ -28,12 +28,6 @@ import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic -/** - * MessageSource 正计划于 0.32 或 0.33 或之后进行 API 不兼容的重写. - */ -@RequiresOptIn(message = "MessageSource 正计划于 0.32 或 0.33 或之后进行 API 不兼容的重写", level = RequiresOptIn.Level.WARNING) -annotation class ExperimentalMessageSource - /** * 消息源, 它存在于 [MessageChain] 中, 用于表示这个消息的来源. * @@ -103,6 +97,8 @@ sealed class MessageSource : Message, MessageMetadata { */ @SinceMirai("0.33.0") sealed class OnlineMessageSource : MessageSource() { + companion object Key : Message.Key + /** * 消息发送人. 可能为 [机器人][Bot] 或 [好友][QQ] 或 [群员][Member]. * 即类型必定为 [Bot], [QQ] 或 [Member] @@ -125,6 +121,8 @@ sealed class OnlineMessageSource : MessageSource() { * 由 [机器人主动发送消息][Contact.sendMessage] 产生的 [MessageSource] */ sealed class Outgoing : OnlineMessageSource() { + companion object Key : Message.Key + abstract override val sender: Bot abstract override val target: Contact @@ -132,12 +130,16 @@ sealed class OnlineMessageSource : MessageSource() { final override val targetId: Long get() = target.id abstract class ToFriend : Outgoing() { + companion object Key : Message.Key + abstract override val target: QQ final override val subject: QQ get() = target // final override fun toString(): String = "OnlineMessageSource.ToFriend(target=${target.id})" } abstract class ToGroup : Outgoing() { + companion object Key : Message.Key + abstract override val target: Group final override val subject: Group get() = target // final override fun toString(): String = "OnlineMessageSource.ToGroup(group=${target.id})" @@ -148,6 +150,8 @@ sealed class OnlineMessageSource : MessageSource() { * 接收到的一条消息的 [MessageSource] */ sealed class Incoming : OnlineMessageSource() { + companion object Key : Message.Key + abstract override val sender: QQ // out QQ abstract override val target: Bot @@ -155,12 +159,16 @@ sealed class OnlineMessageSource : MessageSource() { final override val targetId: Long get() = target.id abstract class FromFriend : Incoming() { + companion object Key : Message.Key + abstract override val sender: QQ final override val subject: QQ get() = sender // final override fun toString(): String = "OnlineMessageSource.FromFriend(from=${sender.id})" } abstract class FromGroup : Incoming() { + companion object Key : Message.Key + abstract override val sender: Member final override val subject: Group get() = sender.group val group: Group get() = sender.group @@ -207,6 +215,7 @@ inline fun MessageSource.recallIn( */ @SinceMirai("0.33.0") abstract class OfflineMessageSource : MessageSource() { + companion object Key : Message.Key // final override fun toString(): String = "OfflineMessageSource(sender=$senderId, target=$targetId)" } // TODO: 2020/4/4 可能要分群和好友 diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt index 3974289d2..2958730af 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaFriendlyAPI.kt @@ -5,7 +5,6 @@ import net.mamoe.mirai.contact.PermissionDeniedException import net.mamoe.mirai.contact.recall import net.mamoe.mirai.data.AddFriendResult import net.mamoe.mirai.message.MessageReceipt -import net.mamoe.mirai.message.data.ExperimentalMessageSource import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageSource @@ -62,7 +61,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { * * @see Bot.recall (扩展函数) 接受参数 [MessageChain] */ - @ExperimentalMessageSource @JvmName("recall") fun __recallBlockingForJava__(source: MessageSource) { runBlocking { recall(source) } @@ -90,7 +88,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { * @param millis 延迟的时间, 单位为毫秒 * @see recall */ - @ExperimentalMessageSource @JvmName("recallIn") fun __recallIn_MemberForJava__(source: MessageSource, millis: Long) { runBlocking { recallIn(source, millis) } @@ -151,7 +148,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() { /** * 异步调用 [__recallBlockingForJava__] */ - @ExperimentalMessageSource @JvmName("recallAsync") fun __recallAsyncForJava__(source: MessageSource): Future { return future { recall(source) } diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt index 7b52cfd9f..837794f86 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/MessageReceipt.kt @@ -11,7 +11,6 @@ import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.QQ -import net.mamoe.mirai.message.data.ExperimentalMessageSource import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.OnlineMessageSource import net.mamoe.mirai.message.data.QuoteReply @@ -24,16 +23,18 @@ import net.mamoe.mirai.utils.unsafeWeakRef * * 此对象持有 [Contact] 的弱引用, [Bot] 离线后将会释放引用, 届时 [target] 将无法访问. * + * @param source 指代发送出去的消息 + * @param target 消息发送对象 + * * @see Group.sendMessage 发送群消息, 返回回执(此对象) * @see QQ.sendMessage 发送群消息, 返回回执(此对象) * * @see MessageReceipt.sourceId 源 id - * @see MessageReceipt.sourceSequenceId 源序列号 * @see MessageReceipt.sourceTime 源时间 */ @Suppress("FunctionName") @OptIn(MiraiInternalAPI::class) -actual open class MessageReceipt @OptIn(ExperimentalMessageSource::class) +actual open class MessageReceipt actual constructor( actual val source: OnlineMessageSource.Outgoing, target: C,