feat: add custom http cat
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.commands.lookup
|
|||||||
|
|
||||||
import cn.rtast.fancybot.annotations.CommandDescription
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
import cn.rtast.fancybot.enums.HttpStatusCode
|
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.misc.toURL
|
||||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
@@ -22,11 +23,16 @@ class HTTPCatCommand : BaseCommand() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val HTTP_CAT_API = "https://http.cat/###.jpg"
|
private const val HTTP_CAT_API = "https://http.cat/###.jpg"
|
||||||
|
private val notFoundCatBase64 = Resources.loadFromResourcesAsBytes("httpcat/404.png")!!.encodeToBase64()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
val randomStatusCode = HttpStatusCode.entries.random().code.toString()
|
val image = try {
|
||||||
val image = HTTP_CAT_API.replace("###", randomStatusCode).toURL().readBytes().encodeToBase64()
|
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 msg = MessageChain.Builder().addImage(image, true).build()
|
val msg = MessageChain.Builder().addImage(image, true).build()
|
||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 504 KiB |
Reference in New Issue
Block a user