chore: use local image file instaed of api
This commit is contained in:
78 files changed
+6
-10
No files matched your search
@@ -10,7 +10,6 @@ package cn.rtast.fancybot.commands.lookup
|
||||
import cn.rtast.fancybot.annotations.CommandDescription
|
||||
import cn.rtast.fancybot.enums.HttpStatusCode
|
||||
import cn.rtast.fancybot.util.misc.Resources
|
||||
import cn.rtast.fancybot.util.misc.toURL
|
||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
@@ -21,18 +20,15 @@ import cn.rtast.rob.util.ob.OneBotListener
|
||||
class HTTPCatCommand : BaseCommand() {
|
||||
override val commandNames = listOf("http猫猫", "HTTP猫猫")
|
||||
|
||||
companion object {
|
||||
private const val HTTP_CAT_API = "https://http.cat/###.jpg"
|
||||
private val notFoundCatBase64 = Resources.loadFromResourcesAsBytes("httpcat/404.png")!!.encodeToBase64()
|
||||
private val notFoundCatBase64 = Resources.loadFromResourcesAsBytes("httpcat/0.jpg")!!.encodeToBase64()
|
||||
|
||||
private fun loadHTTPCat(code: String): String {
|
||||
return Resources.loadFromResourcesAsBytes("httpcat/${code}.jpg")?.encodeToBase64() ?: notFoundCatBase64
|
||||
}
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
val image = try {
|
||||
val statusCode = if (args.isEmpty()) HttpStatusCode.entries.random().code.toString() else args.first()
|
||||
HTTP_CAT_API.replace("###", statusCode).toURL().readBytes().encodeToBase64()
|
||||
} catch (_: Exception) {
|
||||
notFoundCatBase64
|
||||
}
|
||||
val statusCode = if (args.isEmpty()) HttpStatusCode.entries.random().code.toString() else args.first()
|
||||
val image = loadHTTPCat(statusCode)
|
||||
val msg = MessageChain.Builder().addImage(image, true).build()
|
||||
message.reply(msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user