refactor(randomphoto): 重构随机图片服务发送逻辑
- 移除 ImageUtil 相关代码,改用 bot API 发送图片- 添加 JSON 和 Channel 引用,用于构造发送消息的参数- 更新发送逻辑,使用 sendFile 和 send 方法发送图片
This commit is contained in:
parent
4f8e447bdd
commit
c76c906881
@ -1,16 +1,16 @@
|
||||
package info.alinadace.sakuramiki.service.randomphoto
|
||||
|
||||
import com.alibaba.fastjson.JSON
|
||||
import com.mavis.service.AlistService
|
||||
import info.alinadace.sakuramiki.annotation.BotFunction
|
||||
import info.alinadace.sakuramiki.service.Service
|
||||
import info.alinadace.sakuramiki.service.randomphoto.domain.FileList
|
||||
import info.alinadace.sakuramiki.service.randomphoto.domain.SingleFile
|
||||
import info.alinadace.sakuramiki.util.ImageUtil
|
||||
import io.github.kloping.qqbot.api.v2.FriendMessageEvent
|
||||
import io.github.kloping.qqbot.api.v2.GroupMessageEvent
|
||||
import io.github.kloping.qqbot.api.v2.MessageV2Event
|
||||
import io.github.kloping.qqbot.entities.ex.Image
|
||||
import io.github.kloping.qqbot.entities.ex.PlainText
|
||||
import io.github.kloping.qqbot.entities.qqpd.Channel
|
||||
import jakarta.annotation.Resource
|
||||
|
||||
/**
|
||||
@ -55,14 +55,16 @@ class RandomPhotoService : Service<MessageV2Event> {
|
||||
event.send("文件获取失败")
|
||||
return
|
||||
}
|
||||
event.send("图片下载中...")
|
||||
val imageByte = ImageUtil.download(file.data.rawURL)
|
||||
if (imageByte == null) {
|
||||
event.send("图片下载失败")
|
||||
return
|
||||
}
|
||||
val compression = ImageUtil.compression(imageByte)
|
||||
val image = Image(compression)
|
||||
event.send(image)
|
||||
val map = HashMap<String, Any>()
|
||||
map["file_type"] = 1
|
||||
map["url"] = file.data.rawURL
|
||||
map["srv_send_msg"] = false
|
||||
val sendFile = event.bot.userBaseV2.sendFile(event.sender.cid, JSON.toJSONString(map), Channel.SEND_MESSAGE_HEADERS)
|
||||
val message = HashMap<String, Any>()
|
||||
message["content"] = " "
|
||||
message["msg_type"] = 7
|
||||
message["media"] = sendFile.file_info
|
||||
message["event_id"] = event.id
|
||||
event.bot.userBaseV2.send(event.sender.cid, JSON.toJSONString(message), Channel.SEND_MESSAGE_HEADERS)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user