feat: add full url
This commit is contained in:
3 files changed
+46
No files matched your search
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot.commands.lookup
|
package cn.rtast.fancybot.commands.lookup
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.wiki.PageInfoResponse
|
||||||
import cn.rtast.fancybot.entity.wiki.WikipediaResponse
|
import cn.rtast.fancybot.entity.wiki.WikipediaResponse
|
||||||
import cn.rtast.fancybot.util.Http
|
import cn.rtast.fancybot.util.Http
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
@@ -26,6 +27,12 @@ class WikipediaCommand : BaseCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addText("发送`/wiki <关键字>`即可查询出最匹配的wiki页面~")
|
||||||
|
.build()
|
||||||
|
message.reply(msg)
|
||||||
|
}
|
||||||
val title = args.first()
|
val title = args.first()
|
||||||
val response = Http.get<WikipediaResponse>(
|
val response = Http.get<WikipediaResponse>(
|
||||||
wikipediaAPI,
|
wikipediaAPI,
|
||||||
@@ -36,10 +43,22 @@ class WikipediaCommand : BaseCommand() {
|
|||||||
"format" to "json"
|
"format" to "json"
|
||||||
)
|
)
|
||||||
).query.search.first()
|
).query.search.first()
|
||||||
|
val fullUrl = Http.get<PageInfoResponse>(
|
||||||
|
wikipediaAPI,
|
||||||
|
mapOf(
|
||||||
|
"action" to "query",
|
||||||
|
"prop" to "info",
|
||||||
|
"pageids" to response.pageId,
|
||||||
|
"inprop" to "url",
|
||||||
|
"format" to "json"
|
||||||
|
)
|
||||||
|
).query.pages.values.first().fullUrl
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addText("标题: ${response.title} 内容片段如下")
|
.addText("标题: ${response.title} 内容片段如下")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText(response.snippet.extractPlainTextFromHtml())
|
.addText(response.snippet.extractPlainTextFromHtml())
|
||||||
|
.addNewLine(2)
|
||||||
|
.addText(fullUrl)
|
||||||
.build()
|
.build()
|
||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/20
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.wiki
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class PageInfoResponse(
|
||||||
|
val query: Query
|
||||||
|
) {
|
||||||
|
data class Query(
|
||||||
|
val pages: Map<String, PageInfo>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PageInfo(
|
||||||
|
@SerializedName("fullurl")
|
||||||
|
val fullUrl: String
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot.entity.wiki
|
package cn.rtast.fancybot.entity.wiki
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
data class WikipediaResponse(
|
data class WikipediaResponse(
|
||||||
val query: Query
|
val query: Query
|
||||||
) {
|
) {
|
||||||
@@ -15,6 +17,8 @@ data class WikipediaResponse(
|
|||||||
)
|
)
|
||||||
|
|
||||||
data class Search(
|
data class Search(
|
||||||
|
@SerializedName("pageid")
|
||||||
|
val pageId: Long,
|
||||||
val title: String,
|
val title: String,
|
||||||
val snippet: String,
|
val snippet: String,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user