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
dab3448f
Commit
dab3448f
authored
Mar 01, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add docs
parent
8de9357f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
9 deletions
+157
-9
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
+1
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+77
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...ore/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+77
-3
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
View file @
dab3448f
...
@@ -147,7 +147,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
...
@@ -147,7 +147,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
actual
abstract
val
network
:
BotNetworkHandler
actual
abstract
val
network
:
BotNetworkHandler
/**
/**
* 挂起直到 [Bot] 下线.
* 挂起
协程
直到 [Bot] 下线.
*/
*/
@JvmName
(
"joinSuspend"
)
@JvmName
(
"joinSuspend"
)
@JvmSynthetic
@JvmSynthetic
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
View file @
dab3448f
package
net.mamoe.mirai
package
net.mamoe.mirai
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
net.mamoe.mirai.contact.PermissionDeniedException
import
net.mamoe.mirai.contact.recall
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.network.LoginFailedException
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
java.util.concurrent.Future
import
java.util.concurrent.Future
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeoutException
import
java.util.concurrent.TimeoutException
import
kotlin.coroutines.CoroutineContext
/**
/**
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
...
@@ -30,42 +35,99 @@ actual abstract class BotJavaHappyAPI actual constructor() {
...
@@ -30,42 +35,99 @@ actual abstract class BotJavaHappyAPI actual constructor() {
return
(
this
as
Bot
).
run
{
future
(
block
)
}
return
(
this
as
Bot
).
run
{
future
(
block
)
}
}
}
/**
* 登录, 或重新登录.
* 这个函数总是关闭一切现有网路任务, 然后重新登录并重新缓存好友列表和群列表.
*
* 一般情况下不需要重新登录. Mirai 能够自动处理掉线情况.
*
* 最终调用 [net.mamoe.mirai.network.BotNetworkHandler.relogin]
*
* @throws LoginFailedException
*/
@JvmName
(
"login"
)
@JvmName
(
"login"
)
fun
__loginBlockingForJava__
()
{
fun
__loginBlockingForJava__
()
{
runBlocking
{
login
()
}
runBlocking
{
login
()
}
}
}
/**
* 撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @param source 消息源. 可从 [MessageReceipt.source] 获得, 或从消息事件中的 [MessageChain] 获得.
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
*
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
*/
@JvmName
(
"recall"
)
@JvmName
(
"recall"
)
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
runBlocking
{
recall
(
source
)
}
runBlocking
{
recall
(
source
)
}
}
}
/**
* 撤回这条消息.
* 根据 [message] 内的 [MessageSource] 进行相关判断.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
* @see Bot.recall
*/
@JvmName
(
"recall"
)
@JvmName
(
"recall"
)
fun
__recallBlockingForJava__
(
sourc
e
:
MessageChain
)
{
fun
__recallBlockingForJava__
(
messag
e
:
MessageChain
)
{
runBlocking
{
recall
(
sourc
e
)
}
runBlocking
{
recall
(
messag
e
)
}
}
}
/**
* 在一段时间后撤回这条消息.
* 将根据 [MessageSource.groupId] 判断消息是群消息还是好友消息.
*
* @param millis 延迟的时间, 单位为毫秒
* @see recall
*/
@JvmName
(
"recallIn"
)
@JvmName
(
"recallIn"
)
fun
__recallIn_MemberForJava__
(
source
:
MessageSource
,
millis
:
Long
)
{
fun
__recallIn_MemberForJava__
(
source
:
MessageSource
,
millis
:
Long
)
{
runBlocking
{
recallIn
(
source
,
millis
)
}
runBlocking
{
recallIn
(
source
,
millis
)
}
}
}
/**
* 在一段时间后撤回这条消息.
*
* @param millis 延迟的时间, 单位为毫秒
* @param coroutineContext 额外的 [CoroutineContext]
* @see recall
*/
@JvmName
(
"recallIn"
)
@JvmName
(
"recallIn"
)
fun
__recallIn_MemberForJava__
(
source
:
MessageChain
,
millis
:
Long
)
{
fun
__recallIn_MemberForJava__
(
source
:
MessageChain
,
millis
:
Long
)
{
runBlocking
{
recallIn
(
source
,
millis
)
}
runBlocking
{
recallIn
(
source
,
millis
)
}
}
}
/**
* 获取图片下载链接
*/
@JvmName
(
"queryImageUrl"
)
@JvmName
(
"queryImageUrl"
)
fun
__queryImageUrlBlockingForJava__
(
image
:
Image
):
String
{
fun
__queryImageUrlBlockingForJava__
(
image
:
Image
):
String
{
return
runBlocking
{
queryImageUrl
(
image
)
}
return
runBlocking
{
queryImageUrl
(
image
)
}
}
}
/**
* 阻塞当前线程直到 [Bot] 下线.
*/
@JvmName
(
"join"
)
@JvmName
(
"join"
)
fun
__joinBlockingForJava__
()
{
fun
__joinBlockingForJava__
()
{
runBlocking
{
join
()
}
runBlocking
{
join
()
}
}
}
/**
* 添加一个好友
*
* @param message 若需要验证请求时的验证消息.
* @param remark 好友备注
*/
@JvmOverloads
@JvmOverloads
@JvmName
(
"addFriend"
)
@JvmName
(
"addFriend"
)
fun
__addFriendBlockingForJava__
(
fun
__addFriendBlockingForJava__
(
...
@@ -77,21 +139,33 @@ actual abstract class BotJavaHappyAPI actual constructor() {
...
@@ -77,21 +139,33 @@ actual abstract class BotJavaHappyAPI actual constructor() {
return
runBlocking
{
addFriend
(
id
,
message
,
remark
)
}
return
runBlocking
{
addFriend
(
id
,
message
,
remark
)
}
}
}
/**
* 异步调用 [__loginBlockingForJava__]
*/
@JvmName
(
"loginAsync"
)
@JvmName
(
"loginAsync"
)
fun
__loginAsyncForJava__
():
Future
<
Unit
>
{
fun
__loginAsyncForJava__
():
Future
<
Unit
>
{
return
future
{
login
()
}
return
future
{
login
()
}
}
}
/**
* 异步调用 [__recallBlockingForJava__]
*/
@JvmName
(
"recallAsync"
)
@JvmName
(
"recallAsync"
)
fun
__recallAsyncForJava__
(
source
:
MessageSource
):
Future
<
Unit
>
{
fun
__recallAsyncForJava__
(
source
:
MessageSource
):
Future
<
Unit
>
{
return
future
{
recall
(
source
)
}
return
future
{
recall
(
source
)
}
}
}
/**
* 异步调用 [__recallBlockingForJava__]
*/
@JvmName
(
"recallAsync"
)
@JvmName
(
"recallAsync"
)
fun
__recallAsyncForJava__
(
source
:
MessageChain
):
Future
<
Unit
>
{
fun
__recallAsyncForJava__
(
source
:
MessageChain
):
Future
<
Unit
>
{
return
future
{
recall
(
source
)
}
return
future
{
recall
(
source
)
}
}
}
/**
* 异步调用 [__queryImageUrlBlockingForJava__]
*/
@JvmName
(
"queryImageUrlAsync"
)
@JvmName
(
"queryImageUrlAsync"
)
fun
__queryImageUrlAsyncForJava__
(
image
:
Image
):
Future
<
String
>
{
fun
__queryImageUrlAsyncForJava__
(
image
:
Image
):
Future
<
String
>
{
return
future
{
queryImageUrl
(
image
)
}
return
future
{
queryImageUrl
(
image
)
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
dab3448f
...
@@ -150,7 +150,7 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
...
@@ -150,7 +150,7 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
abstract
val
network
:
BotNetworkHandler
abstract
val
network
:
BotNetworkHandler
/**
/**
* 挂起直到 [Bot] 下线.
* 挂起
协程
直到 [Bot] 下线.
*/
*/
@JvmName
(
"joinSuspend"
)
@JvmName
(
"joinSuspend"
)
@JvmSynthetic
@JvmSynthetic
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
View file @
dab3448f
...
@@ -157,7 +157,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
...
@@ -157,7 +157,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
actual
abstract
val
network
:
BotNetworkHandler
actual
abstract
val
network
:
BotNetworkHandler
/**
/**
* 挂起直到 [Bot] 下线.
* 挂起
协程
直到 [Bot] 下线.
*/
*/
@JvmName
(
"joinSuspend"
)
@JvmName
(
"joinSuspend"
)
@JvmSynthetic
@JvmSynthetic
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
View file @
dab3448f
package
net.mamoe.mirai
package
net.mamoe.mirai
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
net.mamoe.mirai.contact.PermissionDeniedException
import
net.mamoe.mirai.contact.recall
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.network.LoginFailedException
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
java.util.concurrent.Future
import
java.util.concurrent.Future
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeoutException
import
java.util.concurrent.TimeoutException
import
kotlin.coroutines.CoroutineContext
/**
/**
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
* [Bot] 中为了让 Java 使用者调用更方便的 API 列表.
...
@@ -30,42 +35,99 @@ actual abstract class BotJavaHappyAPI actual constructor() {
...
@@ -30,42 +35,99 @@ actual abstract class BotJavaHappyAPI actual constructor() {
return
(
this
as
Bot
).
run
{
future
(
block
)
}
return
(
this
as
Bot
).
run
{
future
(
block
)
}
}
}
/**
* 登录, 或重新登录.
* 这个函数总是关闭一切现有网路任务, 然后重新登录并重新缓存好友列表和群列表.
*
* 一般情况下不需要重新登录. Mirai 能够自动处理掉线情况.
*
* 最终调用 [net.mamoe.mirai.network.BotNetworkHandler.relogin]
*
* @throws LoginFailedException
*/
@JvmName
(
"login"
)
@JvmName
(
"login"
)
fun
__loginBlockingForJava__
()
{
fun
__loginBlockingForJava__
()
{
runBlocking
{
login
()
}
runBlocking
{
login
()
}
}
}
/**
* 撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @param source 消息源. 可从 [MessageReceipt.source] 获得, 或从消息事件中的 [MessageChain] 获得.
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
*
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
*/
@JvmName
(
"recall"
)
@JvmName
(
"recall"
)
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
fun
__recallBlockingForJava__
(
source
:
MessageSource
)
{
runBlocking
{
recall
(
source
)
}
runBlocking
{
recall
(
source
)
}
}
}
/**
* 撤回这条消息.
* 根据 [message] 内的 [MessageSource] 进行相关判断.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
* @see Bot.recall
*/
@JvmName
(
"recall"
)
@JvmName
(
"recall"
)
fun
__recallBlockingForJava__
(
sourc
e
:
MessageChain
)
{
fun
__recallBlockingForJava__
(
messag
e
:
MessageChain
)
{
runBlocking
{
recall
(
sourc
e
)
}
runBlocking
{
recall
(
messag
e
)
}
}
}
/**
* 在一段时间后撤回这条消息.
* 将根据 [MessageSource.groupId] 判断消息是群消息还是好友消息.
*
* @param millis 延迟的时间, 单位为毫秒
* @see recall
*/
@JvmName
(
"recallIn"
)
@JvmName
(
"recallIn"
)
fun
__recallIn_MemberForJava__
(
source
:
MessageSource
,
millis
:
Long
)
{
fun
__recallIn_MemberForJava__
(
source
:
MessageSource
,
millis
:
Long
)
{
runBlocking
{
recallIn
(
source
,
millis
)
}
runBlocking
{
recallIn
(
source
,
millis
)
}
}
}
/**
* 在一段时间后撤回这条消息.
*
* @param millis 延迟的时间, 单位为毫秒
* @param coroutineContext 额外的 [CoroutineContext]
* @see recall
*/
@JvmName
(
"recallIn"
)
@JvmName
(
"recallIn"
)
fun
__recallIn_MemberForJava__
(
source
:
MessageChain
,
millis
:
Long
)
{
fun
__recallIn_MemberForJava__
(
source
:
MessageChain
,
millis
:
Long
)
{
runBlocking
{
recallIn
(
source
,
millis
)
}
runBlocking
{
recallIn
(
source
,
millis
)
}
}
}
/**
* 获取图片下载链接
*/
@JvmName
(
"queryImageUrl"
)
@JvmName
(
"queryImageUrl"
)
fun
__queryImageUrlBlockingForJava__
(
image
:
Image
):
String
{
fun
__queryImageUrlBlockingForJava__
(
image
:
Image
):
String
{
return
runBlocking
{
queryImageUrl
(
image
)
}
return
runBlocking
{
queryImageUrl
(
image
)
}
}
}
/**
* 阻塞当前线程直到 [Bot] 下线.
*/
@JvmName
(
"join"
)
@JvmName
(
"join"
)
fun
__joinBlockingForJava__
()
{
fun
__joinBlockingForJava__
()
{
runBlocking
{
join
()
}
runBlocking
{
join
()
}
}
}
/**
* 添加一个好友
*
* @param message 若需要验证请求时的验证消息.
* @param remark 好友备注
*/
@JvmOverloads
@JvmOverloads
@JvmName
(
"addFriend"
)
@JvmName
(
"addFriend"
)
fun
__addFriendBlockingForJava__
(
fun
__addFriendBlockingForJava__
(
...
@@ -77,21 +139,33 @@ actual abstract class BotJavaHappyAPI actual constructor() {
...
@@ -77,21 +139,33 @@ actual abstract class BotJavaHappyAPI actual constructor() {
return
runBlocking
{
addFriend
(
id
,
message
,
remark
)
}
return
runBlocking
{
addFriend
(
id
,
message
,
remark
)
}
}
}
/**
* 异步调用 [__loginBlockingForJava__]
*/
@JvmName
(
"loginAsync"
)
@JvmName
(
"loginAsync"
)
fun
__loginAsyncForJava__
():
Future
<
Unit
>
{
fun
__loginAsyncForJava__
():
Future
<
Unit
>
{
return
future
{
login
()
}
return
future
{
login
()
}
}
}
/**
* 异步调用 [__recallBlockingForJava__]
*/
@JvmName
(
"recallAsync"
)
@JvmName
(
"recallAsync"
)
fun
__recallAsyncForJava__
(
source
:
MessageSource
):
Future
<
Unit
>
{
fun
__recallAsyncForJava__
(
source
:
MessageSource
):
Future
<
Unit
>
{
return
future
{
recall
(
source
)
}
return
future
{
recall
(
source
)
}
}
}
/**
* 异步调用 [__recallBlockingForJava__]
*/
@JvmName
(
"recallAsync"
)
@JvmName
(
"recallAsync"
)
fun
__recallAsyncForJava__
(
source
:
MessageChain
):
Future
<
Unit
>
{
fun
__recallAsyncForJava__
(
source
:
MessageChain
):
Future
<
Unit
>
{
return
future
{
recall
(
source
)
}
return
future
{
recall
(
source
)
}
}
}
/**
* 异步调用 [__queryImageUrlBlockingForJava__]
*/
@JvmName
(
"queryImageUrlAsync"
)
@JvmName
(
"queryImageUrlAsync"
)
fun
__queryImageUrlAsyncForJava__
(
image
:
Image
):
Future
<
String
>
{
fun
__queryImageUrlAsyncForJava__
(
image
:
Image
):
Future
<
String
>
{
return
future
{
queryImageUrl
(
image
)
}
return
future
{
queryImageUrl
(
image
)
}
...
...
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