Skip to content

Commit

Permalink
feat: add scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
RTAkland committed Nov 19, 2024
1 parent 46194e7 commit 004df7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* Date: 2024/11/15
*/

@file:Suppress("unused")

package cn.rtast.rob.qqbot

import cn.rtast.rob.BaseBotInstance
import cn.rtast.rob.qqbot.qbot.QQBotAction
import cn.rtast.rob.qqbot.qbot.QQBotListener
import cn.rtast.rob.qqbot.util.HttpServer
import cn.rtast.rob.scheduler.BotCoroutineScheduler
import io.ktor.server.engine.*
import io.ktor.server.netty.*

Expand All @@ -25,6 +27,11 @@ class BotInstance internal constructor(
internal val action = QQBotAction(appId, clientSecret, this)
internal lateinit var httpServer: EmbeddedServer<NettyApplicationEngine, NettyApplicationEngine.Configuration>

/**
* Bot实例作用于的任务调度器
*/
val scheduler = BotCoroutineScheduler(this)

override suspend fun createBot(): BotInstance {
httpServer = HttpServer(port, appId, clientSecret, listener, this).startHttpServer()
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
* Date: 2024/11/11
*/

@file:Suppress("unused")

package cn.rtast.rob.qqbot

import cn.rtast.rob.BotFactory
import cn.rtast.rob.qqbot.qbot.QQBotListener
import cn.rtast.rob.scheduler.GlobalCoroutineScheduler

object QBotFactory : BotFactory {

internal val botInstances = mutableListOf<BotInstance>()

/**
* 全局作用域的任务调度器
*/
val globalScheduler = GlobalCoroutineScheduler(botInstances)

suspend fun createServer(port: Int, appId: String, clientSecret: String, listener: QQBotListener): BotInstance {
val instance = BotInstance(port, appId, clientSecret, listener).apply { createBot() }
botInstances.add(instance)
Expand Down

0 comments on commit 004df7d

Please sign in to comment.