Move @JvmBlockingBridge on member functions to containing classes

This commit is contained in:
Him188 2021-02-08 12:15:58 +08:00
parent bdcc92f0e9
commit aaa655f167
12 changed files with 16 additions and 64 deletions

View File

@ -162,6 +162,8 @@ public abstract interface class net/mamoe/mirai/LowLevelApiAccessor {
public abstract fun recallGroupMessageRaw (Lnet/mamoe/mirai/Bot;J[I[ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun recallGroupTempMessageRaw (Lnet/mamoe/mirai/Bot;JJ[I[II)Z
public abstract fun recallGroupTempMessageRaw (Lnet/mamoe/mirai/Bot;JJ[I[IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public synthetic fun refreshKeys (Lnet/mamoe/mirai/Bot;)Lkotlin/Unit;
public fun refreshKeys (Lnet/mamoe/mirai/Bot;)V
public abstract fun refreshKeys (Lnet/mamoe/mirai/Bot;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun sendGroupAnnouncement (Lnet/mamoe/mirai/Bot;JLnet/mamoe/mirai/data/GroupAnnouncement;)Ljava/lang/String;
public abstract fun sendGroupAnnouncement (Lnet/mamoe/mirai/Bot;JLnet/mamoe/mirai/data/GroupAnnouncement;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@ -414,7 +416,9 @@ public abstract interface class net/mamoe/mirai/contact/Member : net/mamoe/mirai
public fun mute (I)V
public abstract fun mute (ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun nudge ()Lnet/mamoe/mirai/message/action/MemberNudge;
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
public abstract fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
public abstract fun sendMessage (Lnet/mamoe/mirai/message/data/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

View File

@ -43,6 +43,7 @@ public suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
*
* @see BotFactory 构造 [Bot] 的工厂, [Bot] 唯一的构造方式.
*/
@JvmBlockingBridge
public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
/**
* Bot 配置
@ -161,7 +162,6 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
* @throws LoginFailedException 正常登录失败时抛出
* @see alsoLogin `.apply { login() }` 捷径
*/
@JvmBlockingBridge
public suspend fun login()
/**
@ -232,7 +232,6 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
* 挂起协程直到 [Bot] 协程被关闭 ([Bot.close]).
* 即使 [Bot] 离线, 也会等待直到协程关闭.
*/
@JvmBlockingBridge
public suspend fun join(): Unit = supervisorJob.join()
@ -243,7 +242,6 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
*
* @param cause 原因. null 时视为正常关闭, null 时视为异常关闭
*/
@JvmBlockingBridge
public suspend fun closeAndJoin(cause: Throwable? = null) {
close(cause)
join()

View File

@ -41,6 +41,7 @@ public val Mirai: IMirai by lazy { findMiraiInstance() }
*
* @see Mirai 获取实例
*/
@JvmBlockingBridge
public interface IMirai : LowLevelApiAccessor {
/**
* 请优先使用 [BotFactory.INSTANCE]
@ -121,13 +122,11 @@ public interface IMirai : LowLevelApiAccessor {
* @see IMirai.recallMessage (扩展函数) 接受参数 [MessageChain]
* @see MessageSource.recall 撤回消息扩展
*/
@JvmBlockingBridge
public suspend fun recallMessage(bot: Bot, source: MessageSource)
/**
* 发送戳一戳消息
*/
@JvmBlockingBridge
public suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean
/**
@ -143,7 +142,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @see Image.queryUrl [Image] 的扩展函数
*/
@JvmBlockingBridge
public suspend fun queryImageUrl(bot: Bot, image: Image): String
/**
@ -151,7 +149,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @since 2.1
*/
@JvmBlockingBridge
public suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile
/**
@ -173,7 +170,6 @@ public interface IMirai : LowLevelApiAccessor {
/**
* @since 2.3
*/
@JvmBlockingBridge
public suspend fun downloadLongMessage(
bot: Bot,
resourceId: String,
@ -182,7 +178,6 @@ public interface IMirai : LowLevelApiAccessor {
/**
* @since 2.3
*/
@JvmBlockingBridge
public suspend fun downloadForwardMessage(
bot: Bot,
resourceId: String,
@ -193,7 +188,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @param event 好友验证的事件对象
*/
@JvmBlockingBridge
public suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent)
/**
@ -202,7 +196,6 @@ public interface IMirai : LowLevelApiAccessor {
* @param event 好友验证的事件对象
* @param blackList 拒绝后是否拉入黑名单
*/
@JvmBlockingBridge
public suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false)
/**
@ -210,7 +203,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @param event 加群验证的事件对象
*/
@JvmBlockingBridge
public suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent)
/**
@ -219,7 +211,6 @@ public interface IMirai : LowLevelApiAccessor {
* @param event 加群验证的事件对象
* @param blackList 拒绝后是否拉入黑名单
*/
@JvmBlockingBridge
public suspend fun rejectMemberJoinRequest(
event: MemberJoinRequestEvent,
blackList: Boolean = false,
@ -230,7 +221,6 @@ public interface IMirai : LowLevelApiAccessor {
* 获取在线的 [OtherClient] 列表
* @param mayIncludeSelf 服务器返回的列表可能包含 [Bot] 自己. [mayIncludeSelf] `false` 会排除自己
*/
@JvmBlockingBridge
public suspend fun getOnlineOtherClientsList(
bot: Bot,
mayIncludeSelf: Boolean = false
@ -242,7 +232,6 @@ public interface IMirai : LowLevelApiAccessor {
* @param event 加群验证的事件对象
* @param blackList 忽略后是否拉入黑名单
*/
@JvmBlockingBridge
public suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
/**
@ -250,7 +239,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @param event 邀请入群的事件对象
*/
@JvmBlockingBridge
public suspend fun acceptInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
/**
@ -258,7 +246,6 @@ public interface IMirai : LowLevelApiAccessor {
*
* @param event 邀请入群的事件对象
*/
@JvmBlockingBridge
public suspend fun ignoreInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
}

View File

@ -36,6 +36,7 @@ public annotation class LowLevelApi
* **警告**: 所有的低级 API 都可能在任意时刻不经过任何警告和迭代就被修改. 因此非常不建议在任何情况下使用这些 API.
*/
@LowLevelApi
@JvmBlockingBridge
public interface LowLevelApiAccessor {
/**
* 主动刷新 keys, SKey, PSKey .
@ -70,7 +71,6 @@ public interface LowLevelApiAccessor {
* @see recallMessage
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun recallGroupMessageRaw(
bot: Bot,
groupCode: Long,
@ -83,7 +83,6 @@ public interface LowLevelApiAccessor {
* @see recallMessage
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun recallFriendMessageRaw(
bot: Bot,
targetId: Long,
@ -97,7 +96,6 @@ public interface LowLevelApiAccessor {
* @see recallMessage
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun recallGroupTempMessageRaw(
bot: Bot,
groupUin: Long,
@ -111,7 +109,6 @@ public interface LowLevelApiAccessor {
* 向服务器查询群列表. 返回值高 32 bits uin, 32 bits groupCode
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun getRawGroupList(bot: Bot): Sequence<Long>
/**
@ -123,7 +120,6 @@ public interface LowLevelApiAccessor {
* @see IMirai.calculateGroupUinByGroupCode 使用 groupCode 计算 groupUin
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun getRawGroupMemberList(
bot: Bot,
groupUin: Long,
@ -137,7 +133,6 @@ public interface LowLevelApiAccessor {
*/
@LowLevelApi
@MiraiExperimentalApi
@JvmBlockingBridge
public suspend fun getRawGroupAnnouncements(
bot: Bot,
groupId: Long,
@ -151,7 +146,6 @@ public interface LowLevelApiAccessor {
* @return 公告的fid
*/
@LowLevelApi
@JvmBlockingBridge
@MiraiExperimentalApi
public suspend fun sendGroupAnnouncement(
bot: Bot,
@ -165,7 +159,6 @@ public interface LowLevelApiAccessor {
* @param fid [GroupAnnouncement.fid]
*/
@LowLevelApi
@JvmBlockingBridge
@MiraiExperimentalApi
public suspend fun deleteGroupAnnouncement(
bot: Bot,
@ -178,7 +171,6 @@ public interface LowLevelApiAccessor {
* @param fid [GroupAnnouncement.fid]
*/
@LowLevelApi
@JvmBlockingBridge
@MiraiExperimentalApi
public suspend fun getGroupAnnouncement(
bot: Bot,
@ -193,7 +185,6 @@ public interface LowLevelApiAccessor {
* page从0开始传入可以得到发言列表
*/
@LowLevelApi
@JvmBlockingBridge
@MiraiExperimentalApi
public suspend fun getRawGroupActiveData(bot: Bot, groupId: Long, page: Int = -1): GroupActiveData
@ -203,7 +194,6 @@ public interface LowLevelApiAccessor {
*/
@LowLevelApi
@MiraiExperimentalApi
@JvmBlockingBridge
public suspend fun getRawGroupHonorListData(
bot: Bot,
groupId: Long,
@ -214,7 +204,6 @@ public interface LowLevelApiAccessor {
/**
* 处理一个账号请求添加机器人为好友的事件
*/
@JvmBlockingBridge
@LowLevelApi
public suspend fun solveNewFriendRequestEvent(
bot: Bot,
@ -229,7 +218,6 @@ public interface LowLevelApiAccessor {
* 处理被邀请加入一个群请求事件
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun solveBotInvitedJoinGroupRequestEvent(
bot: Bot,
eventId: Long,
@ -242,7 +230,6 @@ public interface LowLevelApiAccessor {
* 处理账号请求加入群事件
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun solveMemberJoinRequestEvent(
bot: Bot,
eventId: Long,
@ -258,7 +245,6 @@ public interface LowLevelApiAccessor {
* 查询语音的下载连接
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun getGroupVoiceDownloadUrl(
bot: Bot,
md5: ByteArray,
@ -272,7 +258,6 @@ public interface LowLevelApiAccessor {
* @param anonymousId [AnonymousMember.anonymousId]
*/
@LowLevelApi
@JvmBlockingBridge
public suspend fun muteAnonymousMember(
bot: Bot,
anonymousId: String,

View File

@ -27,6 +27,7 @@ import java.io.InputStream
/**
* 联系对象, 即可以与 [Bot] 互动的对象. 包含 [用户][User], [][Group].
*/
@JvmBlockingBridge
public interface Contact : ContactOrBot, CoroutineScope {
/**
* 这个联系对象所属 [Bot].
@ -57,14 +58,12 @@ public interface Contact : ContactOrBot, CoroutineScope {
*
* @return 消息回执. [引用][MessageReceipt.quote] [撤回][MessageReceipt.recall] 这条消息.
*/
@JvmBlockingBridge
public suspend fun sendMessage(message: Message): MessageReceipt<Contact>
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public suspend fun sendMessage(message: String): MessageReceipt<Contact> = this.sendMessage(message.toPlainText())
/**
@ -84,9 +83,9 @@ public interface Contact : ContactOrBot, CoroutineScope {
* @throws EventCancelledException 当发送消息事件被取消时抛出
* @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时抛出. (最大大小约为 20 MB, mirai 限制的大小为 30 MB)
*/
@JvmBlockingBridge
public suspend fun uploadImage(resource: ExternalResource): Image
@JvmBlockingBridge
public companion object {
/**
* 读取 [InputStream] 到临时文件并将其作为图片发送到指定联系人
@ -98,7 +97,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
* @see FileCacheStrategy
*/
@JvmStatic
@JvmBlockingBridge
@JvmOverloads
public suspend fun <C : Contact> C.sendImage(
imageStream: InputStream,
@ -112,7 +110,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
* @see FileCacheStrategy
*/
@JvmStatic
@JvmBlockingBridge
@JvmOverloads
public suspend fun <C : Contact> C.sendImage(
file: File,
@ -124,7 +121,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
*
* @see Contact.sendMessage 最终调用, 发送消息.
*/
@JvmBlockingBridge
@JvmStatic
public suspend fun <C : Contact> C.sendImage(resource: ExternalResource): MessageReceipt<C> =
resource.sendAsImageTo(this)
@ -139,7 +135,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
* @throws OverFileSizeMaxException
*/
@JvmStatic
@JvmBlockingBridge
@JvmOverloads
public suspend fun Contact.uploadImage(
imageStream: InputStream,
@ -152,7 +147,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
* @throws OverFileSizeMaxException
*/
@JvmStatic
@JvmBlockingBridge
@JvmOverloads
public suspend fun Contact.uploadImage(
file: File,
@ -165,7 +159,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
*/
@Throws(OverFileSizeMaxException::class)
@JvmStatic
@JvmBlockingBridge
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "EXTENSION_SHADOWED_BY_MEMBER")
@kotlin.internal.LowPriorityInOverloadResolution // for better Java API
public suspend fun Contact.uploadImage(resource: ExternalResource): Image = this.uploadImage(resource)

View File

@ -31,6 +31,7 @@ import net.mamoe.mirai.message.data.toPlainText
*
* @see FriendMessageEvent
*/
@JvmBlockingBridge
public interface Friend : User, CoroutineScope {
/**
* QQ 号码
@ -62,7 +63,6 @@ public interface Friend : User, CoroutineScope {
*
* @return 消息回执. [引用][MessageReceipt.quote] [撤回][MessageReceipt.recall] 这条消息.
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: Message): MessageReceipt<Friend>
/**
@ -70,14 +70,12 @@ public interface Friend : User, CoroutineScope {
*
* @see FriendDeleteEvent 好友删除事件
*/
@JvmBlockingBridge
public suspend fun delete()
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: String): MessageReceipt<Friend> =
this.sendMessage(message.toPlainText())

View File

@ -25,6 +25,7 @@ import net.mamoe.mirai.utils.OverFileSizeMaxException
/**
* .
*/
@JvmBlockingBridge
public interface Group : Contact, CoroutineScope {
/**
* 群名称.
@ -123,7 +124,6 @@ public interface Group : Contact, CoroutineScope {
* @throws IllegalStateException 当机器人为群主时
* @return 退出成功时 true; 已经退出时 false
*/
@JvmBlockingBridge
public suspend fun quit(): Boolean
/**
@ -141,14 +141,12 @@ public interface Group : Contact, CoroutineScope {
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: Message): MessageReceipt<Group>
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: String): MessageReceipt<Group> =
this.sendMessage(message.toPlainText())
@ -163,7 +161,6 @@ public interface Group : Contact, CoroutineScope {
* @throws EventCancelledException 当发送消息事件被取消
* @throws OverFileSizeMaxException 当语音文件过大而被服务器拒绝上传时. (最大大小约为 1 MB)
*/
@JvmBlockingBridge
public suspend fun uploadVoice(resource: ExternalResource): Voice
@ -175,7 +172,6 @@ public interface Group : Contact, CoroutineScope {
*
* @since 2.2
*/
@JvmBlockingBridge
public suspend fun setEssenceMessage(source: MessageSource): Boolean
public companion object {

View File

@ -34,6 +34,7 @@ import net.mamoe.mirai.utils.WeakRefProperty
* - [Member.asFriend] 转换为 [Friend]
* - [Member.asStranger] 转换为 [Stranger]
*/
@JvmBlockingBridge
public interface Member : User {
/**
* 所在的群.
@ -79,7 +80,6 @@ public interface Member : User {
*
* @see Member.mute 支持 Kotlin [kotlin.time.Duration] 的扩展
*/
@JvmBlockingBridge
public suspend fun mute(durationSeconds: Int)
/**

View File

@ -27,6 +27,7 @@ import kotlin.time.ExperimentalTime
* 群成员可能也是好友, 但他们在对象类型上不同.
* 群成员可以通过 [asFriend] 得到相关好友对象.
*/
@JvmBlockingBridge
public interface NormalMember : Member {
/**
* 群名片. 可能为空.
@ -88,7 +89,6 @@ public interface NormalMember : Member {
*
* @throws PermissionDeniedException 无权限修改时抛出
*/
@JvmBlockingBridge
public suspend fun unmute()
/**
@ -100,7 +100,6 @@ public interface NormalMember : Member {
* @throws PermissionDeniedException 无权限修改时
*
*/
@JvmBlockingBridge
public suspend fun kick(message: String)
/**
@ -122,14 +121,12 @@ public interface NormalMember : Member {
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: Message): MessageReceipt<NormalMember>
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: String): MessageReceipt<NormalMember> =
this.sendMessage(message.toPlainText())

View File

@ -39,6 +39,7 @@ import net.mamoe.mirai.message.data.toPlainText
*
* @see StrangerMessageEvent
*/
@JvmBlockingBridge
public interface Stranger : User, CoroutineScope {
/**
* QQ 号码
@ -66,7 +67,6 @@ public interface Stranger : User, CoroutineScope {
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: Message): MessageReceipt<Stranger>
/**
@ -74,14 +74,12 @@ public interface Stranger : User, CoroutineScope {
*
* @see StrangerRelationChangeEvent.Deleted 陌生人删除事件
*/
@JvmBlockingBridge
public suspend fun delete()
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: String): MessageReceipt<Stranger> =
this.sendMessage(message.toPlainText())

View File

@ -36,6 +36,7 @@ import net.mamoe.mirai.message.data.toPlainText
*
* 对于同一个 [Bot] 任何一个人的 [User] 实例都是单一的.
*/
@JvmBlockingBridge
public interface User : Contact, UserOrBot, CoroutineScope {
/**
* QQ 号码
@ -72,14 +73,12 @@ public interface User : Contact, UserOrBot, CoroutineScope {
*
* @return 消息回执. [引用][MessageReceipt.quote] [撤回][MessageReceipt.recall] 这条消息.
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: Message): MessageReceipt<User>
/**
* 发送纯文本消息
* @see sendMessage
*/
@JvmBlockingBridge
public override suspend fun sendMessage(message: String): MessageReceipt<User> =
this.sendMessage(message.toPlainText())
@ -95,7 +94,6 @@ public interface User : Contact, UserOrBot, CoroutineScope {
*
* @since 2.1
*/
@JvmBlockingBridge
public suspend fun queryProfile(): UserProfile = Mirai.queryProfile(bot, this.id)
}

View File

@ -39,6 +39,7 @@ import net.mamoe.mirai.utils.MiraiInternalApi
* @see MessageReceipt.sourceIds ids
* @see MessageReceipt.sourceTime 源时间
*/
@JvmBlockingBridge
public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
/**
* 指代发送出去的消息.
@ -59,7 +60,6 @@ public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
*
* @see IMirai.recallMessage
*/
@JvmBlockingBridge
public suspend inline fun recall() {
return Mirai.recallMessage(target.bot, source)
}
@ -82,7 +82,6 @@ public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
* 引用这条消息并回复.
* @see MessageSource.quote 引用一条消息
*/
@JvmBlockingBridge
public suspend inline fun quoteReply(message: Message): MessageReceipt<C> {
@Suppress("UNCHECKED_CAST")
return target.sendMessage(this.quote() + message) as MessageReceipt<C>
@ -92,7 +91,6 @@ public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
* 引用这条消息并回复.
* @see MessageSource.quote 引用一条消息
*/
@JvmBlockingBridge
public suspend inline fun quoteReply(message: String): MessageReceipt<C> {
return this.quoteReply(PlainText(message))
}