diff --git a/mirai-core-api/src/commonMain/kotlin/Bot.kt b/mirai-core-api/src/commonMain/kotlin/Bot.kt index 1887d4a06..defa622b9 100644 --- a/mirai-core-api/src/commonMain/kotlin/Bot.kt +++ b/mirai-core-api/src/commonMain/kotlin/Bot.kt @@ -15,6 +15,7 @@ package net.mamoe.mirai import kotlinx.coroutines.* +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.contact.* import net.mamoe.mirai.message.action.BotNudge import net.mamoe.mirai.message.action.MemberNudge @@ -165,7 +166,7 @@ public abstract class Bot internal constructor( * @throws LoginFailedException 正常登录失败时抛出 * @see alsoLogin `.apply { login() }` 捷径 */ - @JvmSynthetic + @JvmBlockingBridge public abstract suspend fun login() /** diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Contact.kt b/mirai-core-api/src/commonMain/kotlin/contact/Contact.kt index 1e8833bb3..aca73fa66 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Contact.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Contact.kt @@ -13,12 +13,13 @@ package net.mamoe.mirai.contact import kotlinx.coroutines.CoroutineScope +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.* import net.mamoe.mirai.event.events.* import net.mamoe.mirai.message.MessageReceipt +import net.mamoe.mirai.message.MessageReceipt.Companion.quote +import net.mamoe.mirai.message.MessageReceipt.Companion.recall import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.message.quote -import net.mamoe.mirai.message.recall import net.mamoe.mirai.utils.ExternalImage import net.mamoe.mirai.utils.OverFileSizeMaxException import net.mamoe.mirai.utils.WeakRefProperty @@ -57,7 +58,7 @@ public interface Contact : ContactOrBot, CoroutineScope { * * @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息. */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun sendMessage(message: Message): MessageReceipt /** @@ -71,7 +72,7 @@ public interface Contact : ContactOrBot, CoroutineScope { * @throws EventCancelledException 当发送消息事件被取消时抛出 * @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时抛出. (最大大小约为 20 MB, 但 mirai 限制的大小为 30 MB) */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun uploadImage(image: ExternalImage): Image /** diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Friend.kt b/mirai-core-api/src/commonMain/kotlin/contact/Friend.kt index fbae5dcc6..f97d1873c 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Friend.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Friend.kt @@ -12,16 +12,17 @@ package net.mamoe.mirai.contact import kotlinx.coroutines.CoroutineScope +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.Bot import net.mamoe.mirai.event.events.EventCancelledException import net.mamoe.mirai.event.events.FriendMessagePostSendEvent import net.mamoe.mirai.event.events.FriendMessagePreSendEvent import net.mamoe.mirai.message.FriendMessageEvent import net.mamoe.mirai.message.MessageReceipt +import net.mamoe.mirai.message.MessageReceipt.Companion.recall import net.mamoe.mirai.message.action.FriendNudge import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.isContentEmpty -import net.mamoe.mirai.message.recall import net.mamoe.mirai.utils.MiraiExperimentalApi /** @@ -70,8 +71,8 @@ public interface Friend : User, CoroutineScope { * * @return 消息回执. 可进行撤回 ([MessageReceipt.recall]) */ - @JvmSynthetic - override suspend fun sendMessage(message: Message): MessageReceipt + @JvmBlockingBridge + public override suspend fun sendMessage(message: Message): MessageReceipt /** * 创建一个 "戳一戳" 消息 diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Group.kt b/mirai-core-api/src/commonMain/kotlin/contact/Group.kt index 9d6c42822..87a18f6c3 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Group.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Group.kt @@ -18,11 +18,11 @@ import net.mamoe.mirai.LowLevelApi import net.mamoe.mirai.data.MemberInfo import net.mamoe.mirai.event.events.* import net.mamoe.mirai.message.MessageReceipt +import net.mamoe.mirai.message.MessageReceipt.Companion.recall import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.Voice import net.mamoe.mirai.message.data.isContentEmpty -import net.mamoe.mirai.message.recall import net.mamoe.mirai.utils.ExternalImage import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.OverFileSizeMaxException @@ -121,7 +121,7 @@ public interface Group : Contact, CoroutineScope { * @throws IllegalStateException 当机器人为群主时 * @return 退出成功时 true; 已经退出时 false */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun quit(): Boolean /** @@ -147,7 +147,7 @@ public interface Group : Contact, CoroutineScope { * * @return 消息回执. 可进行撤回 ([MessageReceipt.recall]) */ - @JvmSynthetic + @JvmBlockingBridge public override suspend fun sendMessage(message: Message): MessageReceipt @@ -162,7 +162,7 @@ public interface Group : Contact, CoroutineScope { * @throws EventCancelledException 当发送消息事件被取消 * @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时. (最大大小约为 20 MB) */ - @JvmSynthetic + @JvmBlockingBridge public override suspend fun uploadImage(image: ExternalImage): Image /** diff --git a/mirai-core-api/src/commonMain/kotlin/contact/Member.kt b/mirai-core-api/src/commonMain/kotlin/contact/Member.kt index 5bfb83850..b5aaaf854 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/Member.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/Member.kt @@ -11,16 +11,17 @@ package net.mamoe.mirai.contact +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.Bot import net.mamoe.mirai.JavaFriendlyAPI import net.mamoe.mirai.event.events.* import net.mamoe.mirai.getFriendOrNull import net.mamoe.mirai.message.MessageReceipt +import net.mamoe.mirai.message.MessageReceipt.Companion.recall import net.mamoe.mirai.message.action.MemberNudge import net.mamoe.mirai.message.action.Nudge import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.isContentEmpty -import net.mamoe.mirai.message.recall import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.WeakRefProperty import kotlin.time.Duration @@ -108,7 +109,7 @@ public interface Member : User { * * @throws PermissionDeniedException 无权限修改时抛出 */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun mute(durationSeconds: Int) /** @@ -122,7 +123,7 @@ public interface Member : User { * * @throws PermissionDeniedException 无权限修改时抛出 */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun unmute() /** @@ -133,7 +134,7 @@ public interface Member : User { * @see MemberLeaveEvent.Kick 成员被踢出事件. * @throws PermissionDeniedException 无权限修改时 */ - @JvmSynthetic + @JvmBlockingBridge public suspend fun kick(message: String = "") /** @@ -155,7 +156,7 @@ public interface Member : User { * * @return 消息回执. 可进行撤回 ([MessageReceipt.recall]) */ - @JvmSynthetic + @JvmBlockingBridge public override suspend fun sendMessage(message: Message): MessageReceipt /** diff --git a/mirai-core-api/src/commonMain/kotlin/contact/User.kt b/mirai-core-api/src/commonMain/kotlin/contact/User.kt index c200157d5..143a9c8dd 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/User.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/User.kt @@ -12,15 +12,16 @@ package net.mamoe.mirai.contact import kotlinx.coroutines.CoroutineScope +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.Bot import net.mamoe.mirai.event.events.* import net.mamoe.mirai.message.MessageReceipt +import net.mamoe.mirai.message.MessageReceipt.Companion.recall import net.mamoe.mirai.message.action.FriendNudge import net.mamoe.mirai.message.action.Nudge import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.isContentEmpty -import net.mamoe.mirai.message.recall import net.mamoe.mirai.utils.ExternalImage import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.OverFileSizeMaxException @@ -78,7 +79,7 @@ public interface User : Contact, CoroutineScope { * * @return 消息回执. 可进行撤回 ([MessageReceipt.recall]) */ - @JvmSynthetic + @JvmBlockingBridge public override suspend fun sendMessage(message: Message): MessageReceipt /** @@ -100,7 +101,7 @@ public interface User : Contact, CoroutineScope { * @throws EventCancelledException 当发送消息事件被取消 * @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时. (最大大小约为 20 MB) */ - @JvmSynthetic + @JvmBlockingBridge public override suspend fun uploadImage(image: ExternalImage): Image } diff --git a/mirai-core-api/src/commonMain/kotlin/message/MessageReceipt.kt b/mirai-core-api/src/commonMain/kotlin/message/MessageReceipt.kt index de2161b77..743b8f495 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/MessageReceipt.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/MessageReceipt.kt @@ -11,9 +11,12 @@ package net.mamoe.mirai.message +import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.IMirai import net.mamoe.mirai.Mirai import net.mamoe.mirai.contact.* +import net.mamoe.mirai.message.MessageReceipt.Companion.quote +import net.mamoe.mirai.message.MessageReceipt.Companion.quoteReply import net.mamoe.mirai.message.data.* import net.mamoe.mirai.message.data.MessageSource.Key.quote import net.mamoe.mirai.utils.MiraiExperimentalApi @@ -55,61 +58,59 @@ public open class MessageReceipt @MiraiExperimentalApi("The con * 是否为发送给群的消息的回执 */ public val isToGroup: Boolean get() = target is Group + + public companion object { + /** + * 撤回这条消息. [recallMessage] 或 [recallIn] 只能被调用一次. + * + * @see IMirai.recallMessage + * @throws IllegalStateException 当此消息已经被撤回或正计划撤回时 + */ + @JvmBlockingBridge + public suspend inline fun MessageReceipt<*>.recall() { + return Mirai.recallMessage(target.bot, source) + } + + /** + * 引用这条消息. + * @see MessageChain.quote 引用一条消息 + */ + public inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote() + + /** + * 引用这条消息并回复. + * @see MessageChain.quote 引用一条消息 + */ + @JvmBlockingBridge + public suspend inline fun MessageReceipt.quoteReply(message: Message): MessageReceipt { + @Suppress("UNCHECKED_CAST") + return target.sendMessage(this.quote() + message) as MessageReceipt + } + + /** + * 引用这条消息并回复. + * @see MessageChain.quote 引用一条消息 + */ + @JvmBlockingBridge + public suspend inline fun MessageReceipt.quoteReply(message: String): MessageReceipt { + return this.quoteReply(PlainText(message)) + } + } } -/** - * 撤回这条消息. [recallMessage] 或 [recallIn] 只能被调用一次. - * - * @see IMirai.recallMessage - * @throws IllegalStateException 当此消息已经被撤回或正计划撤回时 - */ -public suspend inline fun MessageReceipt<*>.recall() { - return Mirai.recallMessage(target.bot, source) -} - -/** - * 引用这条消息. - * @see MessageChain.quote 引用一条消息 - */ -@JvmSynthetic -public inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote() - -/** - * 引用这条消息并回复. - * @see MessageChain.quote 引用一条消息 - */ -@JvmSynthetic -public suspend inline fun MessageReceipt.quoteReply(message: Message): MessageReceipt { - @Suppress("UNCHECKED_CAST") - return target.sendMessage(this.quote() + message) as MessageReceipt -} - -/** - * 引用这条消息并回复. - * @see MessageChain.quote 引用一条消息 - */ -@JvmSynthetic -public suspend inline fun MessageReceipt.quoteReply(message: String): MessageReceipt { - return this.quoteReply(PlainText(message)) -} - - /** * 获取源消息 [MessageSource.ids] * * @see MessageSource.ids */ -@get:JvmSynthetic public inline val MessageReceipt<*>.sourceIds: IntArray get() = this.source.ids - /** * 获取源消息 [MessageSource.internalIds] * * @see MessageSource.ids */ -@get:JvmSynthetic public inline val MessageReceipt<*>.sourceInternalIds: IntArray get() = this.source.internalIds @@ -118,7 +119,5 @@ public inline val MessageReceipt<*>.sourceInternalIds: IntArray * * @see MessageSource.time */ -@get:JvmSynthetic public inline val MessageReceipt<*>.sourceTime: Int get() = this.source.time - diff --git a/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt b/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt index d8a7e9038..c2b3d6806 100644 --- a/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt @@ -93,7 +93,6 @@ internal class FriendImpl( override val remark: String get() = friendInfo.remark - @JvmSynthetic @Suppress("DuplicatedCode") override suspend fun sendMessage(message: Message): MessageReceipt { require(message.isContentNotEmpty()) { "message is empty" } @@ -108,8 +107,7 @@ internal class FriendImpl( override fun toString(): String = "Friend($id)" - @JvmSynthetic - @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") override suspend fun uploadImage(image: ExternalImage): Image = try { if (image.input is net.mamoe.mirai.utils.internal.DeferredReusableInput) { image.input.init(bot.configuration.fileCacheStrategy) diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index 5959fbc25..a7f220f7b 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -268,7 +268,6 @@ internal class GroupImpl( return members.firstOrNull { it.id == id } } - @JvmSynthetic override suspend fun sendMessage(message: Message): MessageReceipt { require(message.isContentNotEmpty()) { "message is empty" } check(!isBotMuted) { throw BotIsBeingMutedException(this) } @@ -381,7 +380,6 @@ internal class GroupImpl( @Suppress("DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @OptIn(ExperimentalTime::class) - @JvmSynthetic override suspend fun uploadImage(image: ExternalImage): Image = try { if (image.input is net.mamoe.mirai.utils.internal.DeferredReusableInput) { image.input.init(bot.configuration.fileCacheStrategy)