Compare commits
1
Commits
main
...
feature/dm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56c65a1165 |
No files matched your search
@@ -41,7 +41,6 @@ import cn.rtast.fancybot.util.str.fromJson
|
|||||||
import cn.rtast.rob.ROneBotFactory
|
import cn.rtast.rob.ROneBotFactory
|
||||||
import cn.rtast.rob.entity.AddFriendRequest
|
import cn.rtast.rob.entity.AddFriendRequest
|
||||||
import cn.rtast.rob.entity.FileEvent
|
import cn.rtast.rob.entity.FileEvent
|
||||||
import cn.rtast.rob.entity.GetMessage
|
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.entity.GroupRevokeMessage
|
import cn.rtast.rob.entity.GroupRevokeMessage
|
||||||
import cn.rtast.rob.enums.ArrayMessageType
|
import cn.rtast.rob.enums.ArrayMessageType
|
||||||
@@ -199,7 +198,8 @@ val commands = listOf(
|
|||||||
AsciiArtCommand(), StatusCommand(),
|
AsciiArtCommand(), StatusCommand(),
|
||||||
JueCommand(), ShortLinkCommand(),
|
JueCommand(), ShortLinkCommand(),
|
||||||
TenSetuCommand(), ShotSelfCommand(),
|
TenSetuCommand(), ShotSelfCommand(),
|
||||||
ShotOtherCommand(), ReverseGIFCommand()
|
ShotOtherCommand(), ReverseGIFCommand(),
|
||||||
|
DMCommand()
|
||||||
)
|
)
|
||||||
|
|
||||||
val START_UP_TIME = Instant.now().epochSecond
|
val START_UP_TIME = Instant.now().epochSecond
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.lookup
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.bili.Search
|
||||||
|
import cn.rtast.fancybot.util.Http
|
||||||
|
import cn.rtast.fancybot.util.parseTimeStamp
|
||||||
|
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||||
|
import cn.rtast.fancybot.util.str.extractPlainTextFromHtml
|
||||||
|
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.NodeMessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
|
class DMCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/dm")
|
||||||
|
|
||||||
|
private val searchAPIUrl = "https://api.bilibili.com/x/web-interface/wbi/search/all/v2"
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val keyword = args.first()
|
||||||
|
val response = Http.get<Search>(
|
||||||
|
searchAPIUrl, mapOf("keyword" to keyword),
|
||||||
|
).data.result.find { it.resultType == "media_bangumi" }!!
|
||||||
|
.data.first()
|
||||||
|
val nodeMsg = NodeMessageChain.Builder()
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
val imageBase64 = URI(response.cover).toURL().readBytes().encodeToBase64()
|
||||||
|
msg.addImage(imageBase64, true)
|
||||||
|
.addText("番名: ${response.title.extractPlainTextFromHtml()}(${response.orgTitle})")
|
||||||
|
.addNewLine()
|
||||||
|
.addText(response.styles)
|
||||||
|
.addNewLine()
|
||||||
|
.addText("${response.areas} · ${response.pubTime.parseTimeStamp().year} · ${response.indexShow}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText(response.desc)
|
||||||
|
.addNewLine()
|
||||||
|
.addText(response.url)
|
||||||
|
nodeMsg.addMessageChain(msg.build(), message.sender.userId)
|
||||||
|
listener.sendGroupForwardMsg(message.groupId, nodeMsg.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,22 +10,17 @@ package cn.rtast.fancybot.commands.lookup
|
|||||||
import cn.rtast.fancybot.entity.wiki.PageInfoResponse
|
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.fancybot.util.str.extractPlainTextFromHtml
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
import cn.rtast.rob.util.BaseCommand
|
||||||
import cn.rtast.rob.util.ob.MessageChain
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
import cn.rtast.rob.util.ob.OneBotListener
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
import org.jsoup.Jsoup
|
|
||||||
|
|
||||||
class WikipediaCommand : BaseCommand() {
|
class WikipediaCommand : BaseCommand() {
|
||||||
override val commandNames = listOf("/wiki", "/wk")
|
override val commandNames = listOf("/wiki", "/wk")
|
||||||
|
|
||||||
private val wikipediaAPI = "https://proxy.rtast.cn/https/zh.wikipedia.org/w/api.php"
|
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>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.bili
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class Search(
|
||||||
|
val data: Data
|
||||||
|
) {
|
||||||
|
data class Data(
|
||||||
|
val result: List<Result>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Result(
|
||||||
|
@SerializedName("result_type")
|
||||||
|
val resultType: String,
|
||||||
|
val data: List<EPData>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class EPData(
|
||||||
|
val url: String,
|
||||||
|
val desc: String,
|
||||||
|
val title: String,
|
||||||
|
@SerializedName("org_title")
|
||||||
|
val orgTitle: String,
|
||||||
|
val cover: String,
|
||||||
|
@SerializedName("pubtime")
|
||||||
|
val pubTime: Long,
|
||||||
|
@SerializedName("media_score")
|
||||||
|
val mediaScore: MediaScore,
|
||||||
|
@SerializedName("index_show")
|
||||||
|
val indexShow: String,
|
||||||
|
val areas: String,
|
||||||
|
val styles: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class MediaScore(
|
||||||
|
val score: Float,
|
||||||
|
@SerializedName("user_count")
|
||||||
|
val userCount: Int,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.util
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
|
||||||
|
fun Long.parseTimeStamp(): LocalDateTime {
|
||||||
|
val instant = Instant.ofEpochMilli(this)
|
||||||
|
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault())
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot.util.str
|
package cn.rtast.fancybot.util.str
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup
|
||||||
import java.awt.Graphics2D
|
import java.awt.Graphics2D
|
||||||
|
|
||||||
fun setTruncat(origin: String, g2d: Graphics2D, maxWidth: Int = 500): String {
|
fun setTruncat(origin: String, g2d: Graphics2D, maxWidth: Int = 500): String {
|
||||||
@@ -40,3 +41,8 @@ fun Int.formatNumberEnglish(): String {
|
|||||||
else -> this.toString()
|
else -> this.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.extractPlainTextFromHtml(): String {
|
||||||
|
val doc = Jsoup.parse(this)
|
||||||
|
return doc.text()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user