chore: update github repo parser
This commit is contained in:
5 files changed
+21
-27
No files matched your search
@@ -27,6 +27,7 @@ import java.net.URI
|
||||
class FancyBot : OneBotListener {
|
||||
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.IO)
|
||||
private val githubRegex = Regex("""github\.com/([^/]+)/([^/]+)""")
|
||||
|
||||
override suspend fun onWebsocketOpenEvent() {
|
||||
this.sendPrivateMessage(configManager.startUpNoticeUser, "FancyBot启动完成~")
|
||||
@@ -68,17 +69,17 @@ class FancyBot : OneBotListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (message.rawMessage.startsWith("https://github.com/") || message.rawMessage.startsWith("git@github.com:")) {
|
||||
GitHubParseCommand.parse(this, message)
|
||||
val matchedResult = githubRegex.find(message.rawMessage)
|
||||
if (message.rawMessage.contains("github.com") && matchedResult != null) {
|
||||
val (user, repo) = matchedResult.destructured
|
||||
GitHubParseCommand.parse(message, user, repo)
|
||||
}
|
||||
|
||||
if (message.rawMessage.startsWith("BV") ||
|
||||
message.rawMessage.startsWith("https://www.bilibili.com") ||
|
||||
message.rawMessage.contains("https://b23.tv/") ||
|
||||
message.message.find { it.type == ArrayMessageType.json } != null
|
||||
) {
|
||||
BVParseCommand.parse(this, message)
|
||||
}
|
||||
) BVParseCommand.parse(this, message)
|
||||
|
||||
coroutineScope.launch {
|
||||
message.message.forEach {
|
||||
|
||||
@@ -155,7 +155,7 @@ object BVParseCommand {
|
||||
message.rawMessage
|
||||
} else if (message.rawMessage.split(" ").last().startsWith("https://b23.tv/")) {
|
||||
val shortUrl = message.rawMessage.split(" ").last()
|
||||
BVParseCommand.getShortUrlBVID(shortUrl)
|
||||
getShortUrlBVID(shortUrl)
|
||||
} else if (message.message.find { it.type == ArrayMessageType.json } != null) {
|
||||
val card = message.message.find { it.type == ArrayMessageType.json }!!
|
||||
.data.data!!.toString().fromJson<CardShare>()
|
||||
@@ -166,7 +166,7 @@ object BVParseCommand {
|
||||
if (!card.meta.detail.title.contains("哔哩哔哩")) return
|
||||
card.meta.detail.qqDocUrl
|
||||
}
|
||||
BVParseCommand.getShortUrlBVID(shortUrl)
|
||||
getShortUrlBVID(shortUrl)
|
||||
} else {
|
||||
message.rawMessage.split("?").first()
|
||||
.split("/")
|
||||
|
||||
@@ -19,7 +19,6 @@ import cn.rtast.fancybot.util.str.setTruncate
|
||||
import cn.rtast.fancybot.util.toByteArray
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OneBotListener
|
||||
import java.awt.Color
|
||||
import java.awt.Font
|
||||
import java.awt.RenderingHints
|
||||
@@ -63,6 +62,8 @@ object GitHubParseCommand {
|
||||
"Shell" to Color(137, 224, 81),
|
||||
"CMake" to Color(218, 52, 52),
|
||||
"HTML" to Color(227, 76, 38),
|
||||
"C#" to Color(23, 134, 0),
|
||||
"F#" to Color(184, 69, 252),
|
||||
"Unknown" to Color(211, 211, 211)
|
||||
)
|
||||
|
||||
@@ -114,20 +115,12 @@ object GitHubParseCommand {
|
||||
return canvas.toByteArray().encodeToBase64()
|
||||
}
|
||||
|
||||
suspend fun parse(listener: OneBotListener, message: GroupMessage) {
|
||||
val path = message.rawMessage
|
||||
.replace(".git", "")
|
||||
.replace("https://github.com/", "")
|
||||
.replace("git@github.com:", "")
|
||||
.split("/")
|
||||
val user = path.first()
|
||||
val repo = path.last()
|
||||
suspend fun parse(message: GroupMessage, user: String, repo: String) {
|
||||
val repoStat = this.getRepoStat(user, repo)
|
||||
val image = this.createImage(repoStat)
|
||||
val msg = MessageChain.Builder()
|
||||
.addReply(message.messageId)
|
||||
.addImage(image, true)
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
message.reply(msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user