feat: add wiki command
This commit is contained in:
5 files changed
+72
-1
No files matched your search
@@ -37,6 +37,7 @@ dependencies {
|
|||||||
implementation(libs.motdPinger)
|
implementation(libs.motdPinger)
|
||||||
implementation(libs.animated.gif.lib)
|
implementation(libs.animated.gif.lib)
|
||||||
implementation(libs.simple.java.mail)
|
implementation(libs.simple.java.mail)
|
||||||
|
implementation(libs.jsoup)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.build {
|
tasks.build {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ sqliteJDBCVersion = "3.46.1.0"
|
|||||||
motdPingerVersion = "1.0.1"
|
motdPingerVersion = "1.0.1"
|
||||||
animatedGifLibVersion = "1.4"
|
animatedGifLibVersion = "1.4"
|
||||||
simpleJavaMailVersion = "8.11.3"
|
simpleJavaMailVersion = "8.11.3"
|
||||||
|
jsoupVersion = "1.18.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
rOneBot = { group = "cn.rtast", name = "ROneBot", version.ref = "ronebotVersion" }
|
rOneBot = { group = "cn.rtast", name = "ROneBot", version.ref = "ronebotVersion" }
|
||||||
@@ -18,6 +19,7 @@ exposedJDBC = { group = "org.jetbrains.exposed", name = "exposed-jdbc", version.
|
|||||||
sqliteJDBC = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqliteJDBCVersion" }
|
sqliteJDBC = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqliteJDBCVersion" }
|
||||||
animated-gif-lib = { group = "com.madgag", name = "animated-gif-lib", version.ref = "animatedGifLibVersion" }
|
animated-gif-lib = { group = "com.madgag", name = "animated-gif-lib", version.ref = "animatedGifLibVersion" }
|
||||||
simple-java-mail = { group = "org.simplejavamail", name = "simple-java-mail", version.ref = "simpleJavaMailVersion" }
|
simple-java-mail = { group = "org.simplejavamail", name = "simple-java-mail", version.ref = "simpleJavaMailVersion" }
|
||||||
|
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoupVersion" }
|
||||||
|
|
||||||
[bundles]
|
[bundles]
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import cn.rtast.fancybot.commands.lookup.NslookupCommand
|
|||||||
import cn.rtast.fancybot.commands.lookup.PixivCommand
|
import cn.rtast.fancybot.commands.lookup.PixivCommand
|
||||||
import cn.rtast.fancybot.commands.lookup.QRCodeCommand
|
import cn.rtast.fancybot.commands.lookup.QRCodeCommand
|
||||||
import cn.rtast.fancybot.commands.lookup.WeatherCommand
|
import cn.rtast.fancybot.commands.lookup.WeatherCommand
|
||||||
|
import cn.rtast.fancybot.commands.lookup.WikipediaCommand
|
||||||
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
||||||
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
||||||
import cn.rtast.fancybot.commands.parse.ImageURLCommand
|
import cn.rtast.fancybot.commands.parse.ImageURLCommand
|
||||||
@@ -167,7 +168,7 @@ val commands = listOf(
|
|||||||
GithubUserCommand(), AboutCommand(),
|
GithubUserCommand(), AboutCommand(),
|
||||||
MusicPlayUrlCommand(), DomainPriceCommand(),
|
MusicPlayUrlCommand(), DomainPriceCommand(),
|
||||||
SendMailCommand(), ZiBiCommand(),
|
SendMailCommand(), ZiBiCommand(),
|
||||||
UnsetZiBiCommand()
|
UnsetZiBiCommand(), WikipediaCommand()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun initFilesDir() {
|
fun initFilesDir() {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/19
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.lookup
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.wiki.WikipediaResponse
|
||||||
|
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 org.jsoup.Jsoup
|
||||||
|
|
||||||
|
class WikipediaCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/wiki", "/wk")
|
||||||
|
|
||||||
|
private val wikipediaAPI = "https://proxy.rtast.cn/https/zh.wikipedia.org/w/api.php"
|
||||||
|
|
||||||
|
private fun String.extractPlainTextFromHtml(): String {
|
||||||
|
val doc = Jsoup.parse(this)
|
||||||
|
return doc.text()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val title = args.first()
|
||||||
|
val response = Http.get<WikipediaResponse>(
|
||||||
|
wikipediaAPI,
|
||||||
|
mapOf(
|
||||||
|
"action" to "query",
|
||||||
|
"list" to "search",
|
||||||
|
"srsearch" to title,
|
||||||
|
"format" to "json"
|
||||||
|
)
|
||||||
|
).query.search.first()
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addText("标题: ${response.title} 内容片段如下")
|
||||||
|
.addNewLine()
|
||||||
|
.addText(response.snippet.extractPlainTextFromHtml())
|
||||||
|
.build()
|
||||||
|
message.reply(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/19
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.wiki
|
||||||
|
|
||||||
|
data class WikipediaResponse(
|
||||||
|
val query: Query
|
||||||
|
) {
|
||||||
|
data class Query(
|
||||||
|
val search: List<Search>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Search(
|
||||||
|
val title: String,
|
||||||
|
val snippet: String,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user