Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
fb072f3c
Commit
fb072f3c
authored
Mar 01, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Java-friendly APIs
parent
bd1a968d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
1 deletion
+138
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+35
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+32
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/javaHappy.kt
...i-core/src/commonMain/kotlin/net.mamoe.mirai/javaHappy.kt
+36
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...ore/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+35
-0
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
0 → 100644
View file @
fb072f3c
package
net.mamoe.mirai
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageSource
/**
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
*/
@Suppress
(
"FunctionName"
,
"INAPPLICABLE_JVM_NAME"
,
"unused"
)
actual
abstract
class
BotJavaHappyAPI
actual
constructor
()
{
init
{
@Suppress
(
"LeakingThis"
)
check
(
this
is
Bot
)
}
private
inline
fun
<
R
>
runBlocking
(
crossinline
block
:
suspend
Bot
.()
->
R
):
R
{
return
kotlinx
.
coroutines
.
runBlocking
{
block
(
this
@BotJavaHappyAPI
as
Bot
)
}
}
@JvmName
(
"login"
)
actual
open
fun
__loginBlockingForJava__
()
{
runBlocking
{
login
()
}
}
@JvmName
(
"recall"
)
actual
open
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
runBlocking
{
recall
(
source
)
}
}
@JvmName
(
"queryImageUrl"
)
actual
open
fun
__queryImageUrl__
(
image
:
Image
):
String
{
return
runBlocking
{
queryImageUrl
(
image
)
}
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
fb072f3c
...
@@ -28,7 +28,9 @@ import net.mamoe.mirai.network.LoginFailedException
...
@@ -28,7 +28,9 @@ import net.mamoe.mirai.network.LoginFailedException
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmSynthetic
/**
/**
* 机器人对象. 一个机器人实例登录一个 QQ 账号.
* 机器人对象. 一个机器人实例登录一个 QQ 账号.
...
@@ -39,8 +41,9 @@ import kotlin.jvm.JvmStatic
...
@@ -39,8 +41,9 @@ import kotlin.jvm.JvmStatic
* @see Contact 联系人
* @see Contact 联系人
* @see kotlinx.coroutines.isActive 判断 [Bot] 是否正常运行中. (在线, 且没有被 [close])
* @see kotlinx.coroutines.isActive 判断 [Bot] 是否正常运行中. (在线, 且没有被 [close])
*/
*/
@Suppress
(
"INAPPLICABLE_JVM_NAME"
)
@UseExperimental
(
MiraiInternalAPI
::
class
,
LowLevelAPI
::
class
)
@UseExperimental
(
MiraiInternalAPI
::
class
,
LowLevelAPI
::
class
)
abstract
class
Bot
:
CoroutineScope
,
LowLevelBotAPIAccessor
{
abstract
class
Bot
:
CoroutineScope
,
LowLevelBotAPIAccessor
,
BotJavaHappyAPI
()
{
companion
object
{
companion
object
{
/**
/**
* 复制一份此时的 [Bot] 实例列表.
* 复制一份此时的 [Bot] 实例列表.
...
@@ -161,8 +164,12 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -161,8 +164,12 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
/**
/**
* 挂起直到 [Bot] 下线.
* 挂起直到 [Bot] 下线.
*/
*/
@JvmName
(
"joinSuspend"
)
@JvmSynthetic
suspend
inline
fun
join
()
=
network
.
join
()
suspend
inline
fun
join
()
=
network
.
join
()
@JvmName
(
"awaitDisconnectionSuspend"
)
@JvmSynthetic
@Deprecated
(
"使用 join()"
,
ReplaceWith
(
"this.join()"
),
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"使用 join()"
,
ReplaceWith
(
"this.join()"
),
level
=
DeprecationLevel
.
HIDDEN
)
suspend
inline
fun
awaitDisconnection
()
=
join
()
suspend
inline
fun
awaitDisconnection
()
=
join
()
...
@@ -176,6 +183,8 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -176,6 +183,8 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
*
*
* @throws LoginFailedException
* @throws LoginFailedException
*/
*/
@JvmName
(
"loginSuspend"
)
@JvmSynthetic
abstract
suspend
fun
login
()
abstract
suspend
fun
login
()
// endregion
// endregion
...
@@ -196,11 +205,15 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -196,11 +205,15 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
* @see _lowLevelRecallFriendMessage 低级 API
* @see _lowLevelRecallFriendMessage 低级 API
* @see _lowLevelRecallGroupMessage 低级 API
* @see _lowLevelRecallGroupMessage 低级 API
*/
*/
@JvmName
(
"recallSuspend"
)
@JvmSynthetic
abstract
suspend
fun
recall
(
source
:
MessageSource
)
abstract
suspend
fun
recall
(
source
:
MessageSource
)
/**
/**
* 获取图片下载链接
* 获取图片下载链接
*/
*/
@JvmName
(
"queryImageUrlSuspend"
)
@JvmSynthetic
abstract
suspend
fun
queryImageUrl
(
image
:
Image
):
String
abstract
suspend
fun
queryImageUrl
(
image
:
Image
):
String
/**
/**
...
@@ -209,6 +222,8 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -209,6 +222,8 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
* @see ByteReadChannel.copyAndClose
* @see ByteReadChannel.copyAndClose
* @see ByteReadChannel.copyTo
* @see ByteReadChannel.copyTo
*/
*/
@JvmName
(
"openChannelSuspend"
)
@JvmSynthetic
abstract
suspend
fun
openChannel
(
image
:
Image
):
ByteReadChannel
abstract
suspend
fun
openChannel
(
image
:
Image
):
ByteReadChannel
/**
/**
...
@@ -217,12 +232,16 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -217,12 +232,16 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
* @param message 若需要验证请求时的验证消息.
* @param message 若需要验证请求时的验证消息.
* @param remark 好友备注
* @param remark 好友备注
*/
*/
@JvmName
(
"addFriendSuspend"
)
@JvmSynthetic
@MiraiExperimentalAPI
(
"未支持"
)
@MiraiExperimentalAPI
(
"未支持"
)
abstract
suspend
fun
addFriend
(
id
:
Long
,
message
:
String
?
=
null
,
remark
:
String
?
=
null
):
AddFriendResult
abstract
suspend
fun
addFriend
(
id
:
Long
,
message
:
String
?
=
null
,
remark
:
String
?
=
null
):
AddFriendResult
/**
/**
* 同意来自陌生人的加好友请求
* 同意来自陌生人的加好友请求
*/
*/
@JvmName
(
"approveFriendAddRequestSuspend"
)
@JvmSynthetic
@MiraiExperimentalAPI
(
"未支持"
)
@MiraiExperimentalAPI
(
"未支持"
)
abstract
suspend
fun
approveFriendAddRequest
(
id
:
Long
,
remark
:
String
?)
abstract
suspend
fun
approveFriendAddRequest
(
id
:
Long
,
remark
:
String
?)
...
@@ -242,6 +261,18 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -242,6 +261,18 @@ abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor {
@UseExperimental
(
LowLevelAPI
::
class
,
MiraiExperimentalAPI
::
class
)
@UseExperimental
(
LowLevelAPI
::
class
,
MiraiExperimentalAPI
::
class
)
final
override
fun
toString
():
String
=
"Bot(${uin})"
final
override
fun
toString
():
String
=
"Bot(${uin})"
@JvmName
(
"login"
)
@JavaHappyAPI
override
fun
__loginBlockingForJava__
()
=
super
.
__loginBlockingForJava__
()
@JvmName
(
"recall"
)
@JavaHappyAPI
override
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
=
super
.
__recallBlockingForJava__
(
source
)
@JvmName
(
"queryImageUrl"
)
@JavaHappyAPI
override
fun
__queryImageUrl__
(
image
:
Image
):
String
=
super
.
__queryImageUrl__
(
image
)
}
}
/**
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/javaHappy.kt
0 → 100644
View file @
fb072f3c
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageSource
import
kotlin.jvm.JvmName
/**
* 表明这个 API 是为了让 Java 使用者调用更方便.
*/
@Experimental
(
level
=
Experimental
.
Level
.
ERROR
)
@Target
(
AnnotationTarget
.
PROPERTY
,
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
TYPE
)
annotation
class
JavaHappyAPI
/**
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
*/
@Suppress
(
"FunctionName"
,
"INAPPLICABLE_JVM_NAME"
,
"unused"
)
expect
abstract
class
BotJavaHappyAPI
()
{
@JvmName
(
"login"
)
open
fun
__loginBlockingForJava__
()
@JvmName
(
"recall"
)
open
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
@JvmName
(
"queryImageUrl"
)
open
fun
__queryImageUrl__
(
image
:
Image
):
String
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
0 → 100644
View file @
fb072f3c
package
net.mamoe.mirai
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageSource
/**
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
*/
@Suppress
(
"FunctionName"
,
"INAPPLICABLE_JVM_NAME"
,
"unused"
)
actual
abstract
class
BotJavaHappyAPI
actual
constructor
()
{
init
{
@Suppress
(
"LeakingThis"
)
check
(
this
is
Bot
)
}
private
inline
fun
<
R
>
runBlocking
(
crossinline
block
:
suspend
Bot
.()
->
R
):
R
{
return
kotlinx
.
coroutines
.
runBlocking
{
block
(
this
@BotJavaHappyAPI
as
Bot
)
}
}
@JvmName
(
"login"
)
actual
open
fun
__loginBlockingForJava__
()
{
runBlocking
{
login
()
}
}
@JvmName
(
"recall"
)
actual
open
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
runBlocking
{
recall
(
source
)
}
}
@JvmName
(
"queryImageUrl"
)
actual
open
fun
__queryImageUrl__
(
image
:
Image
):
String
{
return
runBlocking
{
queryImageUrl
(
image
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment