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

[BUG] 同一张图片,只有第一次发送能成功,缓存之后就无法发送了 #138

Open
Metric-Void opened this issue Feb 19, 2021 · 11 comments

Comments

@Metric-Void
Copy link
Contributor

发送的消息文本中有网络图片链接,类似于"[CQ:image,file=https://github.com/howmanybots/onebot/raw/master/assets/logo-256.png]"

第一次发送时

2021-02-19 16:42:52 I/OneBot: 此链接图片将缓存为30E625FDE4A1767A2B830077BC0F4D76.cqimg

但是之后如果再次发送同样的消息的话,就会出现如下bug

2021-02-19 16:54:34 I/OneBot: 此链接图片已缓存, 如需删除缓存请至 D:\Users\...\mirai-runtime\data\OneBot\image\30E625FDE4A1767A2B830077BC0F4D76.cqimg
2021-02-19 16:54:34 E/OneBot: Exception in WebsocketServer
java.lang.NoClassDefFoundError: Could not initialize class com.github.yyuueexxiinngg.onebot.util.ImgUtil
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt.tryResolveCachedImage(CQMessgeParser.kt:592)
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt$tryResolveMedia$2.invokeSuspend(CQMessgeParser.kt:418)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

=====================================================================

复现

在图片第一次发送完成后,再次发送同一张图片

我使用的是nodejs,相关代码如下

<socket是哪里来的就先不管了>

function _priv_msg_request(target, content) {
    return {
        action: "send_private_msg",
        params: {
            user_id: target,
            message: content
        },
        echo: rand_string(16)
    }
}

async function sendPrivMsgNr(socket, target, content) {
    socket.ws.send(JSON.stringify(_priv_msg_request(target, content)))
}

sendPrivMsg(socket, 随便啥qq号, "[CQ:image,file=https://github.com/howmanybots/onebot/raw/master/assets/logo-256.png]")

// 这里定了个10秒的延迟
setTimeout(sendPrivMsg, 10000, socket, 随便啥qq号, "[CQ:image,file=https://github.com/howmanybots/onebot/raw/master/assets/logo-256.png]")

在我这里,以上代码报错的是

2021-02-19 17:06:18 I/OneBot: 此链接图片将缓存为80F65671342E1F31588E6F04DBA27D9C.cqimg
2021-02-19 17:06:18 V/Bot.2959414660: Friend(随便啥qq号) <- [mirai:image:{17321A12-0E16-FC1A-55C1-4E973A79649B}.png]
2021-02-19 17:06:26 I/OneBot: 此链接图片已缓存, 如需删除缓存请至 D:\Users\...\mirai-runtime\data\OneBot\image\80F65671342E1F31588E6F04DBA27D9C.cqimg
2021-02-19 17:06:26 E/OneBot: Exception in WebsocketServer
java.lang.NoClassDefFoundError: Could not initialize class com.github.yyuueexxiinngg.onebot.util.ImgUtil
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt.tryResolveCachedImage(CQMessgeParser.kt:592)
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt$tryResolveMedia$2.invokeSuspend(CQMessgeParser.kt:418)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

版本

onebot-kotlin - 0.3.4

mirai-core-2.4.0

mirai-console-2.4.0

@Metric-Void
Copy link
Contributor Author

从仓库中重新编译了一份 行号有变化

2021-02-19 17:35:52 I/OneBot: 此链接图片已缓存, 如需删除缓存请至 D:\Users\...\mirai-runtime\data\OneBot\image\80F65671342E1F31588E6F04DBA27D9C.cqimg
2021-02-19 17:35:52 E/OneBot: Exception in WebsocketServer
java.lang.ExceptionInInitializerError
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt.tryResolveCachedImage(CQMessgeParser.kt:578)
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt$tryResolveMedia$2.invokeSuspend(CQMessgeParser.kt:404)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: java.lang.ClassNotFoundException: net.mamoe.mirai.internal.network.QQAndroidBotNetworkHandler
        at net.mamoe.mirai.console.internal.plugin.JvmPluginClassLoader.findClass$mirai_console(JvmPluginClassLoader.kt:110)
        at net.mamoe.mirai.console.internal.plugin.JvmPluginClassLoader.findClass(JvmPluginClassLoader.kt:51)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:377)
        at com.github.yyuueexxiinngg.onebot.util.ImgUtil.<clinit>(ImgUtil.kt:23)
        ... 8 more

2021-02-19 17:36:02 I/OneBot: 此链接图片已缓存, 如需删除缓存请至 D:\Users\...\mirai-runtime\data\OneBot\image\80F65671342E1F31588E6F04DBA27D9C.cqimg
2021-02-19 17:36:02 E/OneBot: Exception in WebsocketServer
java.lang.NoClassDefFoundError: Could not initialize class com.github.yyuueexxiinngg.onebot.util.ImgUtil
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt.tryResolveCachedImage(CQMessgeParser.kt:578)
        at com.github.yyuueexxiinngg.onebot.util.CQMessgeParserKt$tryResolveMedia$2.invokeSuspend(CQMessgeParser.kt:404)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

@OhnkytaBlabdey
Copy link

我遇到了同样的问题

@Metric-Void
Copy link
Contributor Author

我遇到了同样的问题

看看我的PR,构建一下,应该能解决问题

@a08381
Copy link

a08381 commented Mar 4, 2021

我遇到了同样的问题

看看我的PR,构建一下,应该能解决问题

不需要自行构建,actions会自己构建pr

https://github.com/yyuueexxiinngg/onebot-kotlin/actions/runs/583096688

@OhnkytaBlabdey
Copy link

我遇到了同样的问题

看看我的PR,构建一下,应该能解决问题

会有另一个报错
`
2021-03-04 11:07:50 E/OneBot: Exception in coroutine Plugin OneBot of OneBot
kotlinx.serialization.SerializationException: Class 'ForwardMessageInternal' is not registered for polymorphic serializa
tion in the scope of 'SingleMessage'.
Mark the base class as 'sealed' or register the serializer explicitly.
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicS
erializer.kt:103)
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicS
erializer.kt:113)
at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
at kotlinx.serialization.json.internal.PolymorphicKt.findActualSerializer(Polymorphic.kt:29)
at kotlinx.serialization.json.internal.PolymorphicKt.access$findActualSerializer(Polymorphic.kt:1)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:226)

    at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:71)
    at kotlinx.serialization.internal.ListLikeSerializer.serialize(CollectionSerializers.kt:69)
    at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:251)
    at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:246)
    at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)

    at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:71)
    at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData.write$Self(MessageSerializersImpl.kt)

    at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData$$serializer.serialize(MessageSerializ

ersImpl.kt)
at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData$$serializer.serialize(MessageSerializ
ersImpl.kt:59)
at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$$special$$inlined$map$1.serialize(MessageSeriali
zersImpl.kt:234)
at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl.serialize(MessageSerializersImpl.kt)
at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl.serialize(MessageSerializersImpl.kt:45)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:228)

    at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:71)
    at kotlinx.serialization.internal.ListLikeSerializer.serialize(CollectionSerializers.kt:69)
    at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:251)
    at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:246)
    at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)

    at kotlinx.serialization.json.Json.encodeToString(Json.kt:73)
    at net.mamoe.mirai.message.data.MessageChain$Companion.serializeToJsonString(MessageChain.kt:303)
    at net.mamoe.mirai.message.data.MessageChain$Companion.serializeToJsonString$default(MessageChain.kt:302)
    at com.github.yyuueexxiinngg.onebot.util.DatabaseUtilsKt.saveMessageToDB(DatabaseUtils.kt:25)
    at com.github.yyuueexxiinngg.onebot.PluginBase$onEnable$2.invokeSuspend(PluginBase.kt:140)
    at com.github.yyuueexxiinngg.onebot.PluginBase$onEnable$2.invoke(PluginBase.kt)
    at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invokeSuspend(EventChannel.kt:431)
    at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invoke(EventChannel.kt)
    at net.mamoe.mirai.internal.event.Handler$onEvent$2.invokeSuspend(InternalEventListeners.kt:49)
    at net.mamoe.mirai.internal.event.Handler$onEvent$2.invoke(InternalEventListeners.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at net.mamoe.mirai.internal.event.Handler.onEvent(InternalEventListeners.kt:49)
    at net.mamoe.mirai.event.EventKt.broadcast(Event.kt:226)
    at net.mamoe.mirai.internal.network.handler.QQAndroidBotNetworkHandler$handlePacket$7.invokeSuspend(QQAndroidBot

NetworkHandler.kt:554)
at net.mamoe.mirai.internal.network.handler.QQAndroidBotNetworkHandler$handlePacket$7.invoke(QQAndroidBotNetwork
Handler.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
at net.mamoe.mirai.internal.network.handler.QQAndroidBotNetworkHandler.handlePacket(QQAndroidBotNetworkHandler.k
t:547)
at net.mamoe.mirai.internal.network.handler.QQAndroidBotNetworkHandler$generifiedParsePacket$2.invokeSuspend(QQA
ndroidBotNetworkHandler.kt:504)
at net.mamoe.mirai.internal.network.handler.QQAndroidBotNetworkHandler$generifiedParsePacket$2.invoke(QQAndroidB
otNetworkHandler.kt)
at net.mamoe.mirai.internal.network.protocol.packet.KnownPacketFactories.handleIncomingPacket$mirai_core(PacketF
actory.kt:289)
at net.mamoe.mirai.internal.network.protocol.packet.KnownPacketFactories$handleIncomingPacket$1.invokeSuspend(Pa
cketFactory.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:188)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:144)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:90)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:188)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:144)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:90)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:188)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:144)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:90)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:188)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:144)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:15)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:90)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
`

@Metric-Void
Copy link
Contributor Author

看起来是kotlin-serialization的方法又变了 有空改一下

@Metric-Void
Copy link
Contributor Author

我遇到了同样的问题

看看我的PR,构建一下,应该能解决问题

会有另一个报错
`
2021-03-04 11:07:50 E/OneBot: Exception in coroutine Plugin OneBot of OneBot
kotlinx.serialization.SerializationException: Class 'ForwardMessageInternal' is not registered for polymorphic serializa
tion in the scope of 'SingleMessage'.
Mark the base class as 'sealed' or register the serializer explicitly.
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicS
erializer.kt:103)
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicS
erializer.kt:113)
at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
at kotlinx.serialization.json.internal.PolymorphicKt.findActualSerializer(Polymorphic.kt:29)
at kotlinx.serialization.json.internal.PolymorphicKt.access$findActualSerializer(Polymorphic.kt:1)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:226)

你的这个看起来更像是mirai本身的问题,往mirai那里报吧,
另外,多行代码需要三个点才能包住,```

@FlandreCirno
Copy link

兼容性问题,建议直接用onebot-korlin,内置mirai的版本,可以解决这个问题

@zhouhuichen741
Copy link

大佬onebot-mirai-0.3.4-all也出现了这个问题,有办法更新一下mirai版本吗

@Z233
Copy link

Z233 commented May 5, 2022

使用的最新版本,遇到了同样的问题

@DanielToyama
Copy link

使用的最新版本,遇到了同样的问题

我在.\mirai\data\com.github.yyuueexxiinngg.onebot下放了个叫做image的空文件直接不给他缓存了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants