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
a496a934
Commit
a496a934
authored
Dec 20, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto loader for BotFactory
parent
7b9e6e53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
1 deletion
+90
-1
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPCBot.kt
...c/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPCBot.kt
+0
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
...-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
+90
-0
No files found.
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPCBot.kt
View file @
a496a934
...
@@ -11,7 +11,6 @@ import net.mamoe.mirai.data.Packet
...
@@ -11,7 +11,6 @@ import net.mamoe.mirai.data.Packet
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.ImageId0x03
import
net.mamoe.mirai.message.data.ImageId0x03
import
net.mamoe.mirai.message.data.ImageId0x06
import
net.mamoe.mirai.message.data.ImageId0x06
import
net.mamoe.mirai.network.data.*
import
net.mamoe.mirai.qqAccount
import
net.mamoe.mirai.qqAccount
import
net.mamoe.mirai.timpc.internal.RawGroupInfo
import
net.mamoe.mirai.timpc.internal.RawGroupInfo
import
net.mamoe.mirai.timpc.network.GroupImpl
import
net.mamoe.mirai.timpc.network.GroupImpl
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
0 → 100644
View file @
a496a934
@
file
:
Suppress
(
"FunctionName"
,
"unused"
)
package
net.mamoe.mirai
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.utils.MiraiLogger
// Do not use ServiceLoader. Probably not working on MPP
private
val
factory
=
run
{
try
{
Class
.
forName
(
"net.mamoe.mirai.timpc.TIMPC"
).
kotlin
.
objectInstance
as
BotFactory
}
catch
(
ignored
:
Exception
)
{
null
}
}
?:
error
(
"""
No BotFactory found. Please ensure that you've added dependency of protocol modules.
Available modules:
- net.mamoe:mirai-core-timpc
You should have at lease one protocol module installed.
"""
.
trimIndent
()
)
/**
* 加载现有协议的 [BotFactory], 并调用其 [BotFactory.Bot]
*
* 在当前 CoroutineScope 下构造 Bot 实例
* 该 Bot 实例的生命周期将会跟随这个 CoroutineScope.
* 这个 CoroutineScope 也会等待 Bot 的结束才会结束.
*
* ```kotlin
* suspend fun myProcess(){
* TIMPC.Bot(account, logger)
* }
* ```
*/
suspend
fun
Bot
(
account
:
BotAccount
,
logger
:
MiraiLogger
?
=
null
):
Bot
=
factory
.
Bot
(
account
,
logger
)
/**
* 加载现有协议的 [BotFactory], 并调用其 [BotFactory.Bot]
*
* 在当前 CoroutineScope 下构造 Bot 实例
* 该 Bot 实例的生命周期将会跟随这个 CoroutineScope.
* 这个 CoroutineScope 也会等待 Bot 的结束才会结束.
*
* ```kotlin
* suspend fun myProcess(){
* TIMPC.Bot(account, logger)
* }
* ```
*/
suspend
fun
Bot
(
qq
:
Long
,
password
:
String
,
logger
:
MiraiLogger
?
=
null
):
Bot
=
factory
.
Bot
(
qq
,
password
,
logger
)
/**
* 加载现有协议的 [BotFactory], 并调用其 [BotFactory.Bot]
*
* 在特定的 CoroutineScope 下构造 Bot 实例
* 该 Bot 实例的生命周期将会跟随这个 CoroutineScope.
* 这个 CoroutineScope 也会等待 Bot 的结束才会结束.
*
* ```kotlin
* fun myProcess(){
* TIMPC.run {
* GlobalScope.Bot(account, logger)
* }
* }
* ```
*/
fun
CoroutineScope
.
Bot
(
qq
:
Long
,
password
:
String
,
logger
:
MiraiLogger
?
=
null
):
Bot
=
factory
.
run
{
this
@Bot
.
Bot
(
qq
,
password
,
logger
)
}
/**
* 加载现有协议的 [BotFactory], 并调用其 [BotFactory.Bot]
*
* 在特定的 CoroutineScope 下构造 Bot 实例
* 该 Bot 实例的生命周期将会跟随这个 CoroutineScope.
* 这个 CoroutineScope 也会等待 Bot 的结束才会结束.
*
* ```kotlin
* fun myProcess(){
* TIMPC.run {
* GlobalScope.Bot(account, logger)
* }
* }
* ```
*/
fun
CoroutineScope
.
Bot
(
account
:
BotAccount
,
logger
:
MiraiLogger
?
=
null
):
Bot
=
factory
.
run
{
this
@Bot
.
Bot
(
account
,
logger
)
}
\ 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