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
53ba8aba
Commit
53ba8aba
authored
May 03, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve docs
parent
e5404b39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
36 deletions
+48
-36
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
...-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
+3
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactory.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactory.kt
+45
-36
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
View file @
53ba8aba
...
@@ -14,6 +14,7 @@ package net.mamoe.mirai
...
@@ -14,6 +14,7 @@ package net.mamoe.mirai
import
net.mamoe.mirai.utils.BotConfiguration
import
net.mamoe.mirai.utils.BotConfiguration
import
net.mamoe.mirai.utils.Context
import
net.mamoe.mirai.utils.Context
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
/**
/**
* 构造 [Bot] 的工厂. 这是 [Bot] 唯一的构造方式.
* 构造 [Bot] 的工厂. 这是 [Bot] 唯一的构造方式.
...
@@ -49,6 +50,7 @@ expect interface BotFactory {
...
@@ -49,6 +50,7 @@ expect interface BotFactory {
/**
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
inline
fun
BotFactory
.
Bot
(
inline
fun
BotFactory
.
Bot
(
context
:
Context
,
context
:
Context
,
qq
:
Long
,
qq
:
Long
,
...
@@ -59,6 +61,7 @@ inline fun BotFactory.Bot(
...
@@ -59,6 +61,7 @@ inline fun BotFactory.Bot(
/**
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
inline
fun
BotFactory
.
Bot
(
inline
fun
BotFactory
.
Bot
(
context
:
Context
,
context
:
Context
,
qq
:
Long
,
qq
:
Long
,
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactory.kt
View file @
53ba8aba
...
@@ -12,7 +12,13 @@ import net.mamoe.mirai.utils.ContextImpl
...
@@ -12,7 +12,13 @@ import net.mamoe.mirai.utils.ContextImpl
*
*
* 请添加模块依赖 `mirai-core-qqandroid` 以获取协议支持.
* 请添加模块依赖 `mirai-core-qqandroid` 以获取协议支持.
*
*
* ### 自动选择协议模块并构造 [Bot]
* 在 Kotlin 使用包级函数 [Bot], 在 Java 使用 `BotFactoryJvm.newBot`
*
* mirai 通过 [Class.forName] 查找可用的协议实现, 如 `net.mamoe.mirai.qqandroid.QQAndroid`
* mirai 通过 [Class.forName] 查找可用的协议实现, 如 `net.mamoe.mirai.qqandroid.QQAndroid`
*
* ### 手动选择协议模块并构造 [Bot]
* 引用 `net.mamoe.mirai.qqandroid.QQAndroid` 并使用其成员函数 [Bot]
*/
*/
actual
interface
BotFactory
{
actual
interface
BotFactory
{
/**
/**
...
@@ -39,35 +45,8 @@ actual interface BotFactory {
...
@@ -39,35 +45,8 @@ actual interface BotFactory {
}
}
// Do not use ServiceLoader. Probably not working on MPP
@PublishedApi
internal
val
factory
:
BotFactory
=
run
{
runCatching
{
Class
.
forName
(
"net.mamoe.mirai.timpc.TIMPC"
).
kotlin
.
objectInstance
as
BotFactory
}.
getOrElse
{
runCatching
{
Class
.
forName
(
"net.mamoe.mirai.qqandroid.QQAndroid"
).
kotlin
.
objectInstance
as
BotFactory
}.
getOrNull
()
}
}
?:
error
(
"""
No BotFactory found. Please ensure that you've added dependency of protocol modules.
Available modules:
- net.mamoe:mirai-core-timpc (stays at 0.12.0)
- net.mamoe:mirai-core-qqandroid (recommended)
You should have at lease one protocol module installed.
-------------------------------------------------------
找不到 BotFactory. 请确保你依赖了至少一个协议模块.
可用的协议模块:
- net.mamoe:mirai-core-timpc (0.12.0 后停止更新)
- net.mamoe:mirai-core-qqandroid (推荐)
请添加上述任一模块的依赖(与 mirai-core 版本相同)
"""
.
trimIndent
()
)
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmName
(
"newBot"
)
@JvmName
(
"newBot"
)
@JvmOverloads
@JvmOverloads
...
@@ -75,7 +54,7 @@ fun Bot(context: Context, qq: Long, password: String, configuration: BotConfigur
...
@@ -75,7 +54,7 @@ fun Bot(context: Context, qq: Long, password: String, configuration: BotConfigur
factory
.
Bot
(
context
,
qq
,
password
,
configuration
)
factory
.
Bot
(
context
,
qq
,
password
,
configuration
)
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
@JvmSynthetic
inline
fun
Bot
(
context
:
Context
,
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
inline
fun
Bot
(
context
:
Context
,
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
...
@@ -83,7 +62,7 @@ inline fun Bot(context: Context, qq: Long, password: String, configuration: (Bot
...
@@ -83,7 +62,7 @@ inline fun Bot(context: Context, qq: Long, password: String, configuration: (Bot
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmName
(
"newBot"
)
@JvmName
(
"newBot"
)
@JvmOverloads
@JvmOverloads
...
@@ -91,7 +70,7 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu
...
@@ -91,7 +70,7 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu
factory
.
Bot
(
ContextImpl
(),
qq
,
password
,
configuration
)
factory
.
Bot
(
ContextImpl
(),
qq
,
password
,
configuration
)
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
@JvmSynthetic
inline
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
inline
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
...
@@ -99,7 +78,7 @@ inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -
...
@@ -99,7 +78,7 @@ inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmName
(
"newBot"
)
@JvmName
(
"newBot"
)
@JvmOverloads
@JvmOverloads
...
@@ -112,7 +91,7 @@ fun Bot(
...
@@ -112,7 +91,7 @@ fun Bot(
factory
.
Bot
(
context
,
qq
,
passwordMd5
,
configuration
)
factory
.
Bot
(
context
,
qq
,
passwordMd5
,
configuration
)
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
@JvmSynthetic
inline
fun
Bot
(
context
:
Context
,
qq
:
Long
,
passwordMd5
:
ByteArray
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
inline
fun
Bot
(
context
:
Context
,
qq
:
Long
,
passwordMd5
:
ByteArray
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
...
@@ -120,7 +99,7 @@ inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration
...
@@ -120,7 +99,7 @@ inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmName
(
"newBot"
)
@JvmName
(
"newBot"
)
@JvmOverloads
@JvmOverloads
...
@@ -128,8 +107,38 @@ fun Bot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration = BotC
...
@@ -128,8 +107,38 @@ fun Bot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration = BotC
factory
.
Bot
(
ContextImpl
(),
qq
,
passwordMd5
,
configuration
)
factory
.
Bot
(
ContextImpl
(),
qq
,
passwordMd5
,
configuration
)
/**
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*
自动
加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
*/
@JvmSynthetic
@JvmSynthetic
inline
fun
Bot
(
qq
:
Long
,
passwordMd5
:
ByteArray
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
inline
fun
Bot
(
qq
:
Long
,
passwordMd5
:
ByteArray
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
factory
.
Bot
(
ContextImpl
(),
qq
,
passwordMd5
,
BotConfiguration
().
apply
(
configuration
))
factory
.
Bot
(
ContextImpl
(),
qq
,
passwordMd5
,
BotConfiguration
().
apply
(
configuration
))
\ No newline at end of file
// Do not use ServiceLoader. Probably not working on MPP
@PublishedApi
internal
val
factory
:
BotFactory
=
run
{
runCatching
{
Class
.
forName
(
"net.mamoe.mirai.timpc.TIMPC"
).
kotlin
.
objectInstance
as
BotFactory
}.
getOrElse
{
runCatching
{
Class
.
forName
(
"net.mamoe.mirai.qqandroid.QQAndroid"
).
kotlin
.
objectInstance
as
BotFactory
}.
getOrNull
()
}
}
?:
error
(
"""
No BotFactory found. Please ensure that you've added dependency of protocol modules.
Available modules:
- net.mamoe:mirai-core-timpc (stays at 0.12.0)
- net.mamoe:mirai-core-qqandroid (recommended)
You should have at lease one protocol module installed.
-------------------------------------------------------
找不到 BotFactory. 请确保你依赖了至少一个协议模块.
可用的协议模块:
- net.mamoe:mirai-core-timpc (0.12.0 后停止更新)
- net.mamoe:mirai-core-qqandroid (推荐)
请添加上述任一模块的依赖(与 mirai-core 版本相同)
"""
.
trimIndent
()
)
\ 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