2024-10-23 13:45:44 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/10/23
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2024-10-23 15:15:26 +08:00
|
|
|
package cn.rtast.fancybot.commands.misc
|
2024-10-23 13:45:44 +08:00
|
|
|
|
|
|
|
|
import cn.rtast.fancybot.annotations.CommandDescription
|
|
|
|
|
import cn.rtast.fancybot.enums.HttpStatusCode
|
2024-10-23 15:07:43 +08:00
|
|
|
import cn.rtast.fancybot.util.misc.Resources
|
2024-10-23 13:45:44 +08:00
|
|
|
import cn.rtast.fancybot.util.str.encodeToBase64
|
|
|
|
|
import cn.rtast.rob.entity.GroupMessage
|
2024-11-08 20:59:51 +08:00
|
|
|
import cn.rtast.rob.onebot.MessageChain
|
2024-10-23 13:45:44 +08:00
|
|
|
import cn.rtast.rob.util.BaseCommand
|
|
|
|
|
|
|
|
|
|
@CommandDescription("随机HTTP猫猫")
|
|
|
|
|
class HTTPCatCommand : BaseCommand() {
|
|
|
|
|
override val commandNames = listOf("http猫猫", "HTTP猫猫")
|
|
|
|
|
|
2024-10-23 15:12:14 +08:00
|
|
|
private val notFoundCatBase64 = Resources.loadFromResourcesAsBytes("httpcat/0.jpg")!!.encodeToBase64()
|
|
|
|
|
|
|
|
|
|
private fun loadHTTPCat(code: String): String {
|
|
|
|
|
return Resources.loadFromResourcesAsBytes("httpcat/${code}.jpg")?.encodeToBase64() ?: notFoundCatBase64
|
2024-10-23 13:45:44 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-31 14:02:04 +08:00
|
|
|
override suspend fun executeGroup(message: GroupMessage, args: List<String>) {
|
2024-10-23 15:12:14 +08:00
|
|
|
val statusCode = if (args.isEmpty()) HttpStatusCode.entries.random().code.toString() else args.first()
|
|
|
|
|
val image = loadHTTPCat(statusCode)
|
2024-10-23 13:45:44 +08:00
|
|
|
val msg = MessageChain.Builder().addImage(image, true).build()
|
|
|
|
|
message.reply(msg)
|
|
|
|
|
}
|
|
|
|
|
}
|