refactor(miraibot): 更新注解和服务配置
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 23s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 23s
- 修正BotFunction注解中的Service属性值。 - 直接使用KClass<out Event>初始化functionMap。- 在Initialization类中添加全局事件订阅。 - 重构BotConfig类,增加类型和管理员QQ配置。
This commit is contained in:
parent
885e6c7780
commit
90307e1ee9
@ -13,5 +13,5 @@ import kotlin.reflect.KClass
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@org.springframework.stereotype.Service("BotFunction")
|
||||
@org.springframework.stereotype.Service
|
||||
annotation class BotFunction(vararg val value: KClass<out Event>)
|
||||
|
@ -6,17 +6,30 @@ import org.springframework.context.annotation.Configuration
|
||||
|
||||
/**
|
||||
* 机器人配置
|
||||
* @param id 机器人QQ号
|
||||
* @param password 机器人密码
|
||||
* @author Kane
|
||||
* @since 2024/8/29 下午2:39
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties("bot")
|
||||
class BotConfig {
|
||||
/**
|
||||
* 机器人QQ号
|
||||
*/
|
||||
final var id: Long = 0L
|
||||
|
||||
/**
|
||||
* 机器人密码
|
||||
*/
|
||||
final var password: String = ""
|
||||
|
||||
/**
|
||||
* 机器人登录方式
|
||||
*/
|
||||
final var type: LoginType = LoginType.PASSWORD
|
||||
|
||||
/**
|
||||
* 管理员QQ
|
||||
*/
|
||||
final var admin: Long = 0L
|
||||
|
||||
constructor()
|
||||
|
@ -18,6 +18,7 @@ import kotlin.reflect.KClass
|
||||
*/
|
||||
@org.springframework.stereotype.Service
|
||||
class Initialization {
|
||||
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
|
||||
@Resource(name = "functionMap")
|
||||
lateinit var functionMap: HashMap<KClass<out Event>, MutableList<Service<Event>>>
|
||||
|
||||
@ -36,6 +37,10 @@ class Initialization {
|
||||
}
|
||||
}
|
||||
|
||||
GlobalEventChannel.subscribeAlways(Event::class) {
|
||||
log.info("GlobalEvent: {}", this)
|
||||
}
|
||||
|
||||
log.info("Channel complete")
|
||||
log.info("Login: id:{}", bot.id)
|
||||
bot.login()
|
||||
|
Loading…
Reference in New Issue
Block a user