feat: add the history of today command
This commit is contained in:
6 files changed
+82
-3
No files matched your search
@@ -66,7 +66,8 @@ val DEFAULT_CONFIG = Config(
|
||||
llamaModel = "llama3.1",
|
||||
qqMusicApiUrl = "http://127.0.0.1:3200",
|
||||
startUpNoticeUser = 114514L,
|
||||
selfId = 114514L
|
||||
selfId = 114514L,
|
||||
tianXingApiKey = "1145141919810"
|
||||
)
|
||||
|
||||
val configManager = ConfigManager()
|
||||
@@ -122,4 +123,5 @@ val commands = listOf(
|
||||
ZDJDCommand(), ScanQRCodeCommand(),
|
||||
TTSCommand(), SlimeChunkHelperCommand(),
|
||||
SupportMeCommand(), TheCatCommand(),
|
||||
TheHistoryOfTodayCommand()
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/10/8
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.configManager
|
||||
import cn.rtast.fancybot.entity.tianxing.HistoryOfToday
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OneBotListener
|
||||
import cn.rtast.rob.util.ob.asNode
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class TheHistoryOfTodayCommand : BaseCommand() {
|
||||
override val commandNames = listOf("历史上的今天")
|
||||
|
||||
private val tianXingApiUrl = "https://apis.tianapi.com/lishi/index"
|
||||
private val tianXingApiKey = configManager.tianXingApiKey
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
val currentDateTime = LocalDateTime.now(ZoneId.of("Asia/Shanghai"))
|
||||
val formatter = DateTimeFormatter.ofPattern("MMdd")
|
||||
val currentDate = currentDateTime.format(formatter)
|
||||
val messages = mutableListOf<MessageChain>()
|
||||
Http.get<HistoryOfToday>(
|
||||
tianXingApiUrl,
|
||||
mapOf(
|
||||
"key" to tianXingApiKey,
|
||||
"date" to currentDate,
|
||||
)
|
||||
).result.list.forEach {
|
||||
messages.add(
|
||||
MessageChain.Builder()
|
||||
.addText("事件: ${it.title}")
|
||||
.addNewLine()
|
||||
.addText("发生日期: ${it.lsDate}")
|
||||
.build()
|
||||
)
|
||||
}
|
||||
message.reply(messages.asNode(configManager.selfId))
|
||||
}
|
||||
}
|
||||
@@ -34,5 +34,6 @@ data class Config(
|
||||
val llamaModel: String,
|
||||
val qqMusicApiUrl: String,
|
||||
val startUpNoticeUser: Long,
|
||||
val selfId: Long
|
||||
val selfId: Long,
|
||||
val tianXingApiKey: String,
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/10/8
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.tianxing
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class HistoryOfToday(
|
||||
val result: Result
|
||||
) {
|
||||
data class Result(
|
||||
val list: List<Element>
|
||||
)
|
||||
|
||||
data class Element(
|
||||
val title: String,
|
||||
@SerializedName("lsdate")
|
||||
val lsDate: String
|
||||
)
|
||||
}
|
||||
@@ -36,4 +36,5 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
val qqMusicApiUrl = config.qqMusicApiUrl
|
||||
val startUpNoticeUser = config.startUpNoticeUser
|
||||
val selfId = config.selfId
|
||||
val tianXingApiKey = config.tianXingApiKey
|
||||
}
|
||||
@@ -27,5 +27,6 @@
|
||||
"llamaModel": "llama3.1",
|
||||
"qqMusicApiUrl": "http://127.0.0.1:3200",
|
||||
"startUpNoticeUser": 114514,
|
||||
"selfId": 114514
|
||||
"selfId": 114514,
|
||||
"tianXingApiKey": "1145141919810"
|
||||
}
|
||||
Reference in New Issue
Block a user