simple-robot / simpler-robot

Simple Robot,一个bot风格的Kotlin多平台事件调度框架,异步高效、Java友好!/ A Bot-style Kotlin Multiplatform event scheduling framework, asynchronous and high-performance, java-friendly! 🐱😼😻😸
https://simbot.forte.love
GNU Lesser General Public License v3.0
512 stars 44 forks source link

Q: MessageContentBuilder构建图片消息时报错 #260

Closed Chowhound-ch closed 2 years ago

Chowhound-ch commented 2 years ago

疑问描述

相对路径报错,绝对路径没问题,工作目录也检查过了 和去年十月的一哥们问题一样,但我把Maven: love.forte.simple-robot:component-mirai:2.3.4换成v2.3.0-ALPHA.6 ,v2.3.0-ALPHA.5 ,还有其他几个2.3.8版本的都没解决问题 @ForteScarlet v2.3.4

Tips: 你知道吗?simbot开发团队与catCode开发团队的关系非常好,经常会一起玩玩游戏摸摸鱼。

[2022-04-26T17:46:56.310464100]-[INFO ] | love.simbot.example.SimbotExampleApplication : Active resources: [simbot.properties, simbot.yml] [2022-04-26T17:46:57.024551700]-[INFO ] | org.quartz.impl.StdSchedulerFactory : Using default implementation for ThreadExecutor [2022-04-26T17:46:57.026546400]-[INFO ] | org.quartz.simpl.SimpleThreadPool : Job execution threads will use class loader of thread: main [2022-04-26T17:46:57.032530500]-[INFO ] | org.quartz.core.SchedulerSignalerImpl : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl [2022-04-26T17:46:57.032530500]-[INFO ] | org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.2 created. [2022-04-26T17:46:57.033527800]-[INFO ] | org.quartz.simpl.RAMJobStore : RAMJobStore initialized. [2022-04-26T17:46:57.033527800]-[INFO ] | org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.2) 'SimbotQuartzScheduler' with instanceId 'NON_CLUSTERED' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

[2022-04-26T17:46:57.033527800]-[INFO ] | org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'SimbotQuartzScheduler' initialized from an externally provided properties instance. [2022-04-26T17:46:57.033527800]-[INFO ] | org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.2 [2022-04-26T17:46:57.070430900]-[INFO ] | love.f.s.c.m.c.MiraiEventCacheConfiguration : Disable default mirai message cache. 2022-04-26 17:46:57 I/WindowHelperJvm: Mirai 正在使用桌面环境. 如遇到验证码将会弹出对话框. 可添加 JVM 属性 mirai.no-desktop 以关闭. 2022-04-26 17:46:57 I/WindowHelperJvm: Mirai is using desktop. Captcha will be thrown by window popup. You can add mirai.no-desktop to JVM properties (-Dmirai.no-desktop) to disable it. [2022-04-26T17:46:57.951314900]-[INFO ] | love.f.s.c.m.n.2385607214 : Server list: msfwifi.3g.qq.com:8080, 183.194.238.168:8080, 39.156.126.209:80, 36.155.201.162:80, 39.156.125.97:14000, 39.156.125.59:14000, 39.156.126.167:80, 36.155.227.171:443, 120.232.67.218:80, 120.232.67.160:80. [2022-04-26T17:46:58.442833100]-[INFO ] | love.f.s.c.m.b.2385607214 : Loaded account secrets from local cache. [2022-04-26T17:46:58.444826600]-[INFO ] | love.f.s.c.m.n.2385607214 : ECDH key is valid. [2022-04-26T17:46:58.714994800]-[INFO ] | love.f.s.c.m.b.2385607214 : Saved account secrets to local cache for fast login. [2022-04-26T17:46:58.887977700]-[INFO ] | love.f.s.c.m.b.2385607214 : Login successful. [2022-04-26T17:46:58.887977700]-[INFO ] | love.f.s.c.m.n.2385607214 : Server time updated, serverTime: 1650966420, diff: 2ms=0.002s [2022-04-26T17:46:58.890970200]-[INFO ] | love.f.s.c.m.n.2385607214 : Syncing friend message history... [2022-04-26T17:46:58.896955]-[INFO ] | love.f.s.c.m.n.2385607214 : Start loading friend list... [2022-04-26T17:46:58.896955]-[INFO ] | love.f.s.c.m.n.2385607214 : Start loading stranger list... [2022-04-26T17:46:58.960783100]-[INFO ] | love.f.s.c.m.n.2385607214 : Successfully loaded stranger list: 0 in total [2022-04-26T17:46:59.029264500]-[INFO ] | love.f.s.c.m.n.2385607214 : No OtherClient online. [2022-04-26T17:46:59.032240100]-[INFO ] | love.f.s.c.m.n.2385607214 : Start loading group list... [2022-04-26T17:46:59.037227100]-[INFO ] | love.f.s.c.m.n.2385607214 : Syncing friend message history: Success. [2022-04-26T17:46:59.063317100]-[INFO ] | love.f.s.c.m.n.2385607214 : Successfully loaded friend list: 3 in total [2022-04-26T17:46:59.470349100]-[INFO ] | love.f.s.c.m.n.2385607214 : Successfully loaded group list: 2 in total. [2022-04-26T17:46:59.476108100]-[INFO ] | love.f.s.c.m.n.2385607214 : Scheduled key refresh in 23h 55min 0.0s. [2022-04-26T17:46:59.476108100]-[INFO ] | love.f.s.c.m.n.2385607214 : Scheduled refresh login session in 19d 23h 55min 0.0s. [2022-04-26T17:46:59.477106100]-[INFO ] | love.f.s.c.m.b.2385607214 : Bot login successful. [2022-04-26T17:46:59.488719200]-[INFO ] | love.f.s.c.c.CoreMethodPostListenerRegistrar : Ready to register method listeners. [2022-04-26T17:46:59.488719200]-[INFO ] | love.f.s.c.c.CoreMethodPostListenerRegistrar : If you want to view the details, please enable log debug. [2022-04-26T17:46:59.773987800]-[INFO ] | love.f.s.c.c.CoreMethodPostListenerRegistrar : Method listeners Registration is complete. [2022-04-26T17:47:00.174973200]-[INFO ] | love.f.s.c.c.CoreListenerRegistrar : Registration Bot: code=2385607214, name=1, level=1 [2022-04-26T17:47:02.075021400]-[ERROR] | fun love.s.e.l.M.F.f.s.a.m.e.G.f.s.a.s.M.U.FightMo : Listener execution exception: java.io.FileNotFoundException: da.jpg java.io.FileNotFoundException: da.jpg at love.forte.simbot.component.mirai.message.MiraiMessageContentBuilder.imageLocal(MiraiMessageContentBuilder.kt:119) at love.forte.simbot.component.mirai.message.MiraiMessageContentBuilder.imageLocal(MiraiMessageContentBuilder.kt:71) at love.forte.simbot.api.message.MessageContentBuilder.imageLocal(MessageContentBuilder.kt:101) at love.forte.simbot.api.message.MessageContentBuilder.image(MessageContentBuilder.kt:117) at love.simbot.example.listener.MyGroupListen.FightMo(MyGroupListen.java:92) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:113) at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$functionCaller$2.invokeSuspend(FunctionFromClassListenerFunction.kt:72) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$functionCaller$2.invoke(FunctionFromClassListenerFunction.kt) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$functionCaller$2.invoke(FunctionFromClassListenerFunction.kt) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$invoker$1.invokeSuspend(FunctionFromClassListenerFunction.kt:616) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$invoker$1.invoke(FunctionFromClassListenerFunction.kt) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction$invoker$1.invoke(FunctionFromClassListenerFunction.kt) at love.forte.simbot.core.listener.FunctionFromClassListenerFunction.invoke(FunctionFromClassListenerFunction.kt:638) at love.forte.simbot.core.listener.ListenerInvokerImpl.invoke(ListenerInvokerImpl.kt:36) at love.forte.simbot.core.listener.CoreListenerManager$doListenerFunctionInvoker$2.invokeSuspend(CoreListenerManager.kt:475) at love.forte.simbot.core.listener.CoreListenerManager$doListenerFunctionInvoker$2.invoke(CoreListenerManager.kt) at love.forte.simbot.core.listener.CoreListenerManager$doListenerFunctionInvoker$2.invoke(CoreListenerManager.kt) at love.forte.simbot.core.listener.CoreListenerManager.onMsg0$doListen(CoreListenerManager.kt:521) at love.forte.simbot.core.listener.CoreListenerManager.onMsg0(CoreListenerManager.kt:585) at love.forte.simbot.core.listener.CoreListenerManager.onMsg1(CoreListenerManager.kt:443) at love.forte.simbot.core.listener.CoreListenerManager.access$onMsg1(CoreListenerManager.kt:115) at love.forte.simbot.core.listener.CoreListenerManager$onMsg$2.invokeSuspend(CoreListenerManager.kt:412) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833)

ForteScarlet commented 2 years ago

提供相关代码、文件目录结构

Chowhound-ch commented 2 years ago
  报错代码:

MessageContentBuilder messageContentBuilder = messageBuilderFactory.getMessageContentBuilder(); MessageContent messageContent = messageContentBuilder.image("da.jpg").text("◆").at(number).text( Fightmo() + score + Out() ).build(); msgSender.SENDER.sendGroupMsg(groupMsg.getGroupInfo().getGroupCode(), messageContent); 文件位置:G:\simbot-mirai-demo-master\src\main 文件名称:da.jpg 工作目录:G:\simbot-mirai-demo-master\src\main

文件是通过这些代码从网上保存下来的 BufferedImage bufferedImage = ImageIO.read(new URL(""));

        File file = new File("da.jpg");
        file.createNewFile();
        FileOutputStream fileOutputStream = new FileOutputStream(file);

        ImageIO.write(bufferedImage, "jpg", fileOutputStream);
ForteScarlet commented 2 years ago

尝试下述几种方式:

builder.imageLocal("da.jpg");
builder.image("file:da.jpg")
// try - catch - close
builder.image(inputStream)
inputStream.close()
Chowhound-ch commented 2 years ago

谢谢大大,前两种不行,第三种先用这个相对路径创建一个FileInputStream类再image(fileinputStream)就可以了。

对了,顺便说一下,昨天那个报错时不时跳出来但不影响程序运行,今天在看就没了。