From c76c9068810b7eb8d018dde4ae16f71c7aec0851 Mon Sep 17 00:00:00 2001 From: Grand-cocoa <1075576561@qq.com49111108+grand-cocoa@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:14:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(randomphoto):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E5=9B=BE=E7=89=87=E6=9C=8D=E5=8A=A1=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 ImageUtil 相关代码,改用 bot API 发送图片- 添加 JSON 和 Channel 引用,用于构造发送消息的参数- 更新发送逻辑,使用 sendFile 和 send 方法发送图片 --- .../service/randomphoto/RandomPhotoService.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/info/alinadace/sakuramiki/service/randomphoto/RandomPhotoService.kt b/src/main/kotlin/info/alinadace/sakuramiki/service/randomphoto/RandomPhotoService.kt index 3d1030e..b4c9c0b 100644 --- a/src/main/kotlin/info/alinadace/sakuramiki/service/randomphoto/RandomPhotoService.kt +++ b/src/main/kotlin/info/alinadace/sakuramiki/service/randomphoto/RandomPhotoService.kt @@ -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 { 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() + 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() + 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) } }