1 Commits
Author SHA1 Message Date
RTAkland dff2c549dd feat: add stock data api 2024-10-01 11:50:35 +08:00
5 changed files with 74 additions and 1 deletions

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ dependencies {
implementation(libs.simple.java.mail)
implementation(libs.jsoup)
implementation(libs.nashorn.core)
implementation(libs.finnhub)
}
tasks.build {
+2
View File
@@ -10,6 +10,7 @@ animatedGifLibVersion = "1.4"
simpleJavaMailVersion = "8.11.3"
jsoupVersion = "1.18.1"
nashornVersion = "15.4"
finnhubVersion = "2.0.20"
[libraries]
rOneBot = { group = "cn.rtast", name = "ROneBot", version.ref = "ronebotVersion" }
@@ -22,6 +23,7 @@ animated-gif-lib = { group = "com.madgag", name = "animated-gif-lib", version.re
simple-java-mail = { group = "org.simplejavamail", name = "simple-java-mail", version.ref = "simpleJavaMailVersion" }
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoupVersion" }
nashorn-core = { group = "org.openjdk.nashorn", name = "nashorn-core", version.ref = "nashornVersion" }
finnhub = { group = "io.finnhub", name = "kotlin-client", version.ref = "finnhubVersion" }
[bundles]
+2 -1
View File
@@ -104,5 +104,6 @@ val commands = listOf(
DMSearchCommand(), LlamaCommand(),
QQMusicCommand(), BullShitGenerateCommand(),
NiuziRankCommand(), NiuziBankRankCommand(),
ShotSelfCommand(), TenSetuCommand()
ShotSelfCommand(), TenSetuCommand(),
StockDataCommand()
)
@@ -0,0 +1,50 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/10/1
*/
package cn.rtast.fancybot.commands.lookup
import cn.rtast.fancybot.configManager
import cn.rtast.fancybot.entity.stock.StockSymbolQuery
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
class StockDataCommand : BaseCommand() {
override val commandNames = listOf("sd", "股票")
private val apiUrl = "https://proxy.rtast.cn/https/finnhub.io"
private val apiKey = "crtmph1r01qv68qhn8n0crtmph1r01qv68qhn8ng"
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
val method = args.first()
when (method) {
"q" -> {
val messages = mutableListOf<MessageChain>()
val symbol = args.joinToString(" ")
val response = Http.get<StockSymbolQuery>(
"$apiUrl/api/v1/search",
mapOf(
"q" to symbol,
"token" to apiKey,
)
)
messages.add(MessageChain.Builder().addText("共搜索到${response.count}条结果").build())
response.result.forEach {
val tempMsg = MessageChain.Builder()
.addText("股票代码: ${it.displaySymbol}(${it.symbol}, ${it.description})")
.build()
messages.add(tempMsg)
}
message.reply(messages.asNode(configManager.selfId))
}
}
}
}
@@ -0,0 +1,19 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/10/1
*/
package cn.rtast.fancybot.entity.stock
data class StockSymbolQuery(
val count: Int,
val result: List<Result>
) {
data class Result(
val description: String,
val displaySymbol: String,
val symbol: String,
)
}