
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 23s
- 修正BotFunction注解中的Service属性值。 - 直接使用KClass<out Event>初始化functionMap。- 在Initialization类中添加全局事件订阅。 - 重构BotConfig类,增加类型和管理员QQ配置。
49 lines
1.4 KiB
Kotlin
49 lines
1.4 KiB
Kotlin
package info.alinadace.miraibot.configuration
|
|
|
|
import info.alinadace.miraibot.service.Service
|
|
import jakarta.annotation.Resource
|
|
import net.mamoe.mirai.Bot
|
|
import net.mamoe.mirai.event.Event
|
|
import net.mamoe.mirai.event.GlobalEventChannel
|
|
import org.slf4j.Logger
|
|
import org.slf4j.LoggerFactory
|
|
import org.springframework.boot.context.event.ApplicationReadyEvent
|
|
import org.springframework.context.event.EventListener
|
|
import kotlin.reflect.KClass
|
|
|
|
/**
|
|
* 机器人功能初始化
|
|
* @author Kane
|
|
* @since 2024/9/4 18:49
|
|
*/
|
|
@org.springframework.stereotype.Service
|
|
class Initialization {
|
|
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
|
|
@Resource(name = "functionMap")
|
|
lateinit var functionMap: HashMap<KClass<out Event>, MutableList<Service<Event>>>
|
|
|
|
@Resource
|
|
lateinit var bot: Bot;
|
|
|
|
val log: Logger = LoggerFactory.getLogger(Initialization::class.java)
|
|
|
|
@EventListener(ApplicationReadyEvent::class)
|
|
suspend fun initFunction() {
|
|
functionMap.forEach { v ->
|
|
GlobalEventChannel.subscribeAlways(v.key) {
|
|
log.info("Event: {}", this)
|
|
val filter = v.value.filter { x -> x.entrance(this) }
|
|
filter.forEach { x -> x.active(this) }
|
|
}
|
|
}
|
|
|
|
GlobalEventChannel.subscribeAlways(Event::class) {
|
|
log.info("GlobalEvent: {}", this)
|
|
}
|
|
|
|
log.info("Channel complete")
|
|
log.info("Login: id:{}", bot.id)
|
|
bot.login()
|
|
}
|
|
}
|