feat: add latest commmit info and add language name on github repo card
This commit is contained in:
4 files changed
+91
-1
No files matched your search
@@ -105,5 +105,6 @@ val commands = listOf(
|
|||||||
QQMusicCommand(), BullShitGenerateCommand(),
|
QQMusicCommand(), BullShitGenerateCommand(),
|
||||||
NiuziRankCommand(), NiuziBankRankCommand(),
|
NiuziRankCommand(), NiuziBankRankCommand(),
|
||||||
ShotSelfCommand(), TenSetuCommand(),
|
ShotSelfCommand(), TenSetuCommand(),
|
||||||
ReactionCommand(), MCSkinCommand()
|
ReactionCommand(), MCSkinCommand(),
|
||||||
|
GithubLatestCommitCommand()
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/3
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.lookup
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
|
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
||||||
|
import cn.rtast.fancybot.configManager
|
||||||
|
import cn.rtast.fancybot.entity.github.LatestCommit
|
||||||
|
import cn.rtast.fancybot.util.Http
|
||||||
|
import cn.rtast.fancybot.util.str.fromArrayJson
|
||||||
|
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
|
||||||
|
|
||||||
|
@CommandDescription("查询Github上的仓库的最新一次的提交信息")
|
||||||
|
class GithubLatestCommitCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf(".commit")
|
||||||
|
|
||||||
|
private val userInfoUrl = "https://api.github.com/repos"
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
message.reply("发送`.commit <用户名/仓库名>`即可查询仓库最新一次的提交信息")
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val (user, repo) = if (args.size == 1) {
|
||||||
|
args.first().split("/").first() to args.first().split("/").last()
|
||||||
|
} else {
|
||||||
|
args.first() to args.last()
|
||||||
|
}
|
||||||
|
val response = Http.get(
|
||||||
|
"$userInfoUrl/$user/$repo/commits",
|
||||||
|
headers = mapOf("Authorization" to configManager.githubKey)
|
||||||
|
).fromArrayJson<List<LatestCommit>>().first()
|
||||||
|
val image = GitHubParseCommand.creatRepoImage(user, repo)
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addImage(image, true)
|
||||||
|
.addText("最新提交ID: ${response.sha.substring(0, 7)}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("提交者: ${response.commit.committer.name}(${response.commit.committer.email})")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("提交日期: ${response.commit.committer.date}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("https://github.com/$user/$repo")
|
||||||
|
.build()
|
||||||
|
message.reply(msg)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
message.reply("查询失败~")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,6 +111,8 @@ object GitHubParseCommand {
|
|||||||
g2d.drawString(repoStat.description ?: "暂无描述~", 80, 400, 800)
|
g2d.drawString(repoStat.description ?: "暂无描述~", 80, 400, 800)
|
||||||
val avatarImage = ImageIO.read(URI(repoStat.owner.avatarUrl).toURL())
|
val avatarImage = ImageIO.read(URI(repoStat.owner.avatarUrl).toURL())
|
||||||
g2d.drawCustomImage(avatarImage, 1200, 160, 300.0, 300.0, true)
|
g2d.drawCustomImage(avatarImage, 1200, 160, 300.0, 300.0, true)
|
||||||
|
g2d.color = this.getLanguageColor(repoStat.language)
|
||||||
|
g2d.drawString(repoStat.language, 30, CANVAS_HEIGHT - 50)
|
||||||
g2d.dispose()
|
g2d.dispose()
|
||||||
return canvas.toByteArray().encodeToBase64()
|
return canvas.toByteArray().encodeToBase64()
|
||||||
}
|
}
|
||||||
@@ -123,4 +125,10 @@ object GitHubParseCommand {
|
|||||||
.build()
|
.build()
|
||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun creatRepoImage(user: String, repo: String): String {
|
||||||
|
val repoStat = this.getRepoStat(user, repo)
|
||||||
|
val image = this.createImage(repoStat)
|
||||||
|
return image
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/3
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.github
|
||||||
|
|
||||||
|
data class LatestCommit(
|
||||||
|
val sha: String,
|
||||||
|
val commit: Commit
|
||||||
|
) {
|
||||||
|
data class Commit(
|
||||||
|
val committer: Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Committer(
|
||||||
|
val email: String,
|
||||||
|
val name: String,
|
||||||
|
val date: String,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user