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, MutableList>> @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() } }