Sakura-Miki/src/main/kotlin/info/alinadace/sakuramiki/service/ExampleService.kt
Grand-cocoa fbfb1c1a7f feat(service): 添加随机照片服务- 新增 RandomPhotoService 类实现随机照片功能
- 添加 FileList 和 SingleFile 数据模型用于解析 JSON 响应
- 集成 AlistService 获取文件列表和文件信息
- 使用 OkHttpClient 下载图片
- 更新 application.yml 配置,添加 AList 相关设置
- 修改 ExampleService 中的 entrance 方法返回值
2024-11-11 20:48:56 +08:00

48 lines
1.3 KiB
Kotlin

package info.alinadace.sakuramiki.service
import info.alinadace.sakuramiki.annotation.BotFunction
import info.alinadace.sakuramiki.configuration.BotConfig
import io.github.kloping.qqbot.api.v2.FriendMessageEvent
import io.github.kloping.qqbot.api.v2.GroupMessageEvent
import io.github.kloping.qqbot.api.v2.MessageV2Event
import io.github.kloping.qqbot.entities.ex.PlainText
import jakarta.annotation.Resource
import org.slf4j.Logger
import org.slf4j.LoggerFactory
/**
* @author Kane
* @since 2024/8/29 下午3:47
*/
@BotFunction(FriendMessageEvent::class, GroupMessageEvent::class)
class ExampleService : Service<MessageV2Event> {
companion object {
val log: Logger = LoggerFactory.getLogger(this::class.java)
}
@Resource
lateinit var botConfig: BotConfig
/**
* 服务入口
*/
override fun entrance(event: MessageV2Event): Boolean {
val chain = event.message
if (chain.size == 1 && chain[0] is PlainText && event.sender.id == botConfig.admin) {
if (chain[0].toString() == "测试") {
return true
}
}
return false
}
/**
* 服务行为
*/
override fun active(event: MessageV2Event) {
log.info("ExampleService: sender:{}", event.sender.id)
event.send("测试成功")
}
}