Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用deserializeMiraiCode获得的图片消息,图片格式不准确 #2760

Closed
pilgrim773 opened this issue Jul 29, 2023 · 0 comments · Fixed by #2761
Closed

用deserializeMiraiCode获得的图片消息,图片格式不准确 #2760

pilgrim773 opened this issue Jul 29, 2023 · 0 comments · Fixed by #2761
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Milestone

Comments

@pilgrim773
Copy link

pilgrim773 commented Jul 29, 2023

问题描述

数据库记录了一张图片Id: [mirai:image:{881AD697-863A-88B1-8A00-B1E6BB9E7AB9}.jpg], 图片源文件也存在自己服务器的某目录下;保存代码如:

if (s instanceof Image) {
      String id = ((Image) s).getImageId();
      ImageType type = ((Image) s).getImageType();
      File imageDir = new File(
      AskAndAnswerPluginMain.INSTANCE.getDataFolderPath() + "/image/" + type.getFormatName());

然后是查询数据库与文件系统,获得构造图片信息并准备发送的代码:

MessageChain rawChain = MiraiCode.deserializeMiraiCode(answer);
for (SingleMessage singleMessage : rawChain) {
 if (singleMessage instanceof Image) {
               Image i = (Image) singleMessage;
               if (!Image.isUploaded(i, Bot.getInstance(Long.valueOf(BotConfig.botQQNumber)))) {
                    String imagePath = AskAndAnswerPluginMain.INSTANCE.getDataFolderPath() + "/image/" + i.getImageType().getFormatName();
                        File file = IOUtils.openFile(imagePath, i.getImageId() + "." + i.getImageType().getFormatName());
                        ctx.getLogger().info("*********************试图寻找服务器保存图片: " + file.getAbsolutePath() + "*********************");
}

日志输出:
image

可以看到发送时的 i.getImageType().getFormatName()得到的是gif,但是这图片显然是jpg,且保存的时候的type.getFormatName()能得到jpg,现在这张图片文件就是存在……/image/jpg/{881AD697-863A-88B1-8A00-B1E6BB9E7AB9}.jpg.jpg,发送时根据变量拼接结果就到gif目录下去找了

复现

见描述

mirai-core 版本

2.14.0

bot-protocol

ANDROID_PAD

其他组件版本

No response

系统日志

No response

网络日志

No response

补充信息

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Projects
None yet
2 participants