Merge PR #1499: fix(qq): add msg_seq to prevent message deduplication error

fix(qq): add msg_seq to prevent message deduplication error
This commit is contained in:
Xubin Ren
2026-03-05 10:39:45 +08:00
committed by GitHub

View File

@@ -56,6 +56,7 @@ class QQChannel(BaseChannel):
self.config: QQConfig = config self.config: QQConfig = config
self._client: "botpy.Client | None" = None self._client: "botpy.Client | None" = None
self._processed_ids: deque = deque(maxlen=1000) self._processed_ids: deque = deque(maxlen=1000)
self._msg_seq: int = 1 # 消息序列号,避免被 QQ API 去重
async def start(self) -> None: async def start(self) -> None:
"""Start the QQ bot.""" """Start the QQ bot."""
@@ -102,11 +103,13 @@ class QQChannel(BaseChannel):
return return
try: try:
msg_id = msg.metadata.get("message_id") msg_id = msg.metadata.get("message_id")
self._msg_seq += 1 # 递增序列号
await self._client.api.post_c2c_message( await self._client.api.post_c2c_message(
openid=msg.chat_id, openid=msg.chat_id,
msg_type=0, msg_type=0,
content=msg.content, content=msg.content,
msg_id=msg_id, msg_id=msg_id,
msg_seq=self._msg_seq, # 添加序列号避免去重
) )
except Exception as e: except Exception as e:
logger.error("Error sending QQ message: {}", e) logger.error("Error sending QQ message: {}", e)
@@ -133,3 +136,4 @@ class QQChannel(BaseChannel):
) )
except Exception: except Exception:
logger.exception("Error handling QQ message") logger.exception("Error handling QQ message")