NapNeko / NapCatQQ

现代化的基于 NTQQ 的 Bot 协议端实现
https://napcat.napneko.icu/
Other
2.51k stars 177 forks source link

[BUG] 添加好友以及接受好友请求后产生不正常事件 #77

Closed Ant00000ny closed 4 months ago

Ant00000ny commented 4 months ago

系统版本

docker image: mlikiowa/napcat-docker:latest

QQNT 版本

docker image

NapCat 版本

docker image

OneBot 客户端

simple-robot/simbot-component-onebot 0.6.0

发生了什么?

  1. 添加好友后,bot 会收到2-3个好友请求,其中一个是真实请求事件,另外一个事件里的 user_id 是完全无关的陌生人。用框架尝试接受这个异常好友请求后 bot 会主动发送好友请求给这个人。用同一个账号删除 bot 好友后再添加好友,异常事件里的陌生人 ID 是同一个人,我没有用其它账号测试过。

  2. 接受好友请求后,会收到一个 poke 事件。

{
  "time": 1718888977,
  "self_id": "xxx",
  "post_type": "notice",
  "notice_type": "notify",
  "sub_type": "poke",
  "target_id": "xxx",
  "user_id": "yyy",
  "sender_id": "yyy"
}

但是并没有任何人戳一戳。

具体见 https://github.com/simple-robot/simbot-component-onebot/issues/47#issuecomment-2180536880

  1. 以上两个情况高概率复现。

如何复现

好友请求事件处理代码:

@Listener
suspend fun onFriendRequest(event: OneBotFriendRequestEvent) {
    try {
        val reqInfo = botService.getStrangerInfo(event.requesterId) // 调用 GetStrangerInfoApi
        delay(1.seconds)
        event.accept()
        log.info("通过了 ${reqInfo.nickname} (${reqInfo.userId}) 的好友请求")
    } catch (e: Exception) {
        log.error("好友请求处理异常", e)
    }
}

期望的结果?

只收到一个好友请求事件,并且信息正确。

NapCat 运行日志

只有正常的 INFO 消息日志。

OneBot 客户端运行日志

这里 bot 实际上应该只收到了一次好友请求。

2024-06-20T21:36:21.228+08:00  INFO 13358 --- [nano-qq] [atcher-worker-2] f.f.n.h.request.FriendRequestHandler     : 通过了 xxx (xxx) 的好友请求
2024-06-20T21:36:21.237+08:00  INFO 13358 --- [nano-qq] [atcher-worker-7] f.f.n.h.request.FriendRequestHandler     : 通过了 yyy (yyy) 的好友请求
2024-06-20T21:36:24.155+08:00  INFO 13358 --- [nano-qq] [atcher-worker-2] f.f.n.h.request.FriendRequestHandler     : 通过了 xxx (xxx) 的好友请求
Exception in thread "DefaultDispatcher-worker-10" java.lang.IllegalStateException: Failed to resolve raw event {"time":1718890671,"self_id":xxx,"post_type":"notice","notice_type":"notify","sub_type":"poke","target_id":zzz,"user_id":yyy,"sender_id":yyy}, session and bot will be closed exceptionally
    at love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl$WsEventSession.receiveEvent(OneBotBotImpl.kt:457)
    at love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl$WsEventSession.access$receiveEvent(OneBotBotImpl.kt:278)
    at love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl$WsEventSession$receiveEvent$1.invokeSuspend(OneBotBotImpl.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@1a1e5442, Dispatchers.Default]
Caused by: kotlinx.serialization.MissingFieldException: Field 'group_id' is required for type with serial name 'love.forte.simbot.component.onebot.v11.event.notice.RawNotifyEvent', but it was missing
    at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
    at love.forte.simbot.component.onebot.v11.event.notice.RawNotifyEvent.<init>(RawNotifyEvent.kt:44)
    at love.forte.simbot.component.onebot.v11.event.notice.RawNotifyEvent$$serializer.deserialize(RawNotifyEvent.kt:44)
    at love.forte.simbot.component.onebot.v11.event.notice.RawNotifyEvent$$serializer.deserialize(RawNotifyEvent.kt:44)
    at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:77)
    at kotlinx.serialization.json.internal.AbstractJsonTreeDecoder.decodeSerializableValue(TreeJsonDecoder.kt:52)
    at kotlinx.serialization.json.internal.TreeJsonDecoderKt.readJson(TreeJsonDecoder.kt:25)
    at kotlinx.serialization.json.Json.decodeFromJsonElement(Json.kt:127)
    at love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl$WsEventSession.resolveRawEvent(OneBotBotImpl.kt:504)
    at love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl$WsEventSession.receiveEvent(OneBotBotImpl.kt:452)
    ... 8 more
MliKiowa commented 4 months ago

确实有此问题 包括表情回应也会异常触发

MliKiowa commented 4 months ago

下个版本修复

MliKiowa commented 4 months ago

v1.5.9已尝试修复

MliKiowa commented 4 months ago

1.5.9出现严重问题 推迟到1.6.1

Ant00000ny commented 4 months ago

docker 镜像更新到 1.6.1 版本后,不会有 poke 消息了,但是问题 1 仍然存在

Ant00000ny commented 4 months ago

@MliKiowa 这个问题在新版本中有计划解决吗

MliKiowa commented 4 months ago

@MliKiowa 这个问题在新版本中有计划解决吗

在计划内 不过最近很忙