mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-06 11:16:54 +08:00
Add Java-friendly APIs
This commit is contained in:
parent
fb072f3cbb
commit
ed712295fe
@ -207,8 +207,4 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
override suspend fun openChannel(image: Image): ByteReadChannel {
|
||||
return Http.get<HttpResponse>(queryImageUrl(image)).content
|
||||
}
|
||||
|
||||
override suspend fun approveFriendAddRequest(id: Long, remark: String?) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package net.mamoe.mirai
|
||||
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
|
||||
/**
|
||||
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
|
||||
*/
|
||||
@MiraiInternalAPI
|
||||
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME", "unused")
|
||||
actual abstract class BotJavaHappyAPI actual constructor() {
|
||||
init {
|
||||
@ -29,7 +33,23 @@ actual abstract class BotJavaHappyAPI actual constructor() {
|
||||
}
|
||||
|
||||
@JvmName("queryImageUrl")
|
||||
actual open fun __queryImageUrl__(image: Image): String {
|
||||
actual open fun __queryImageUrlBlockingForJava__(image: Image): String {
|
||||
return runBlocking { queryImageUrl(image) }
|
||||
}
|
||||
|
||||
@JvmName("join")
|
||||
actual open fun __joinBlockingForJava__() {
|
||||
runBlocking { join() }
|
||||
}
|
||||
|
||||
@UseExperimental(MiraiExperimentalAPI::class)
|
||||
@JvmOverloads
|
||||
@JvmName("addFriend")
|
||||
actual open fun __addFriendBlockingForJava__(
|
||||
id: Long,
|
||||
message: String?,
|
||||
remark: String?
|
||||
): AddFriendResult {
|
||||
return runBlocking { addFriend(id, message, remark) }
|
||||
}
|
||||
}
|
@ -168,11 +168,6 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaHappyAPI() {
|
||||
@JvmSynthetic
|
||||
suspend inline fun join() = network.join()
|
||||
|
||||
@JvmName("awaitDisconnectionSuspend")
|
||||
@JvmSynthetic
|
||||
@Deprecated("使用 join()", ReplaceWith("this.join()"), level = DeprecationLevel.HIDDEN)
|
||||
suspend inline fun awaitDisconnection() = join()
|
||||
|
||||
/**
|
||||
* 登录, 或重新登录.
|
||||
* 这个函数总是关闭一切现有网路任务, 然后重新登录并重新缓存好友列表和群列表.
|
||||
@ -237,14 +232,6 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaHappyAPI() {
|
||||
@MiraiExperimentalAPI("未支持")
|
||||
abstract suspend fun addFriend(id: Long, message: String? = null, remark: String? = null): AddFriendResult
|
||||
|
||||
/**
|
||||
* 同意来自陌生人的加好友请求
|
||||
*/
|
||||
@JvmName("approveFriendAddRequestSuspend")
|
||||
@JvmSynthetic
|
||||
@MiraiExperimentalAPI("未支持")
|
||||
abstract suspend fun approveFriendAddRequest(id: Long, remark: String?)
|
||||
|
||||
// endregion
|
||||
|
||||
/**
|
||||
@ -272,7 +259,16 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaHappyAPI() {
|
||||
|
||||
@JvmName("queryImageUrl")
|
||||
@JavaHappyAPI
|
||||
override fun __queryImageUrl__(image: Image): String = super.__queryImageUrl__(image)
|
||||
override fun __queryImageUrlBlockingForJava__(image: Image): String = super.__queryImageUrlBlockingForJava__(image)
|
||||
|
||||
@JvmName("addFriend")
|
||||
@JavaHappyAPI
|
||||
override fun __addFriendBlockingForJava__(id: Long, message: String?, remark: String?) =
|
||||
super.__addFriendBlockingForJava__(id, message, remark)
|
||||
|
||||
@JvmName("join")
|
||||
@JavaHappyAPI
|
||||
override fun __joinBlockingForJava__() = super.__joinBlockingForJava__()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,22 +9,30 @@
|
||||
|
||||
package net.mamoe.mirai
|
||||
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmOverloads
|
||||
|
||||
/**
|
||||
* 表明这个 API 是为了让 Java 使用者调用更方便.
|
||||
*/
|
||||
@MiraiInternalAPI
|
||||
@Experimental(level = Experimental.Level.ERROR)
|
||||
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
|
||||
annotation class JavaHappyAPI
|
||||
|
||||
/**
|
||||
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
|
||||
*/
|
||||
*/ // TODO: 2020/3/1 待 https://youtrack.jetbrains.com/issue/KT-36740 修复后添加 Future 相关 API.
|
||||
@MiraiInternalAPI
|
||||
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME", "unused")
|
||||
expect abstract class BotJavaHappyAPI() {
|
||||
expect abstract class BotJavaHappyAPI() { // 不要使用 interface, 会无法添加默认实现
|
||||
@JvmName("join")
|
||||
open fun __joinBlockingForJava__()
|
||||
|
||||
@JvmName("login")
|
||||
open fun __loginBlockingForJava__()
|
||||
|
||||
@ -32,5 +40,9 @@ expect abstract class BotJavaHappyAPI() {
|
||||
open fun __recallBlockingForJava__(source: MessageSource)
|
||||
|
||||
@JvmName("queryImageUrl")
|
||||
open fun __queryImageUrl__(image: Image): String
|
||||
open fun __queryImageUrlBlockingForJava__(image: Image): String
|
||||
|
||||
@JvmName("addFriend")
|
||||
@JvmOverloads
|
||||
open fun __addFriendBlockingForJava__(id: Long, message: String? = null, remark: String? = null): AddFriendResult
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package net.mamoe.mirai
|
||||
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
|
||||
/**
|
||||
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
|
||||
*/
|
||||
@MiraiInternalAPI
|
||||
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME", "unused")
|
||||
actual abstract class BotJavaHappyAPI actual constructor() {
|
||||
init {
|
||||
@ -29,7 +33,23 @@ actual abstract class BotJavaHappyAPI actual constructor() {
|
||||
}
|
||||
|
||||
@JvmName("queryImageUrl")
|
||||
actual open fun __queryImageUrl__(image: Image): String {
|
||||
actual open fun __queryImageUrlBlockingForJava__(image: Image): String {
|
||||
return runBlocking { queryImageUrl(image) }
|
||||
}
|
||||
|
||||
@JvmName("join")
|
||||
actual open fun __joinBlockingForJava__() {
|
||||
runBlocking { join() }
|
||||
}
|
||||
|
||||
@UseExperimental(MiraiExperimentalAPI::class)
|
||||
@JvmOverloads
|
||||
@JvmName("addFriend")
|
||||
actual open fun __addFriendBlockingForJava__(
|
||||
id: Long,
|
||||
message: String?,
|
||||
remark: String?
|
||||
): AddFriendResult {
|
||||
return runBlocking { addFriend(id, message, remark) }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user