From b75e35d17a19ac7e9cd893048bb39e34ecd4f46d Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 12:09:37 +0800 Subject: [PATCH 1/6] feat: store xml in vendor_specific --- efb_wechat_comwechat_slave/ComWechat.py | 6 +++--- efb_wechat_comwechat_slave/MsgProcess.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 5102e57..b91f962 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -32,7 +32,7 @@ from .ChatMgr import ChatMgr from .CustomTypes import EFBGroupChat, EFBPrivateChat, EFBGroupMember, EFBSystemUser from .MsgDeco import qutoed_text -from .MsgProcess import MsgProcess +from .MsgProcess import MsgProcess, MsgWrapper from .Utils import download_file , load_config , load_temp_file_to_local , WC_EMOTICON_CONVERSION from rich.console import Console @@ -501,7 +501,7 @@ def handle_msg(self , msg : Dict[str, Any] , author : 'ChatMember' , chat : 'Cha self.file_msg[msg["filepath"]] = ( msg , author , chat ) return - self.send_efb_msgs(MsgProcess(msg, chat), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) + self.send_efb_msgs(MsgWrapper(msg["message"], MsgProcess(msg, chat)), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) def handle_file_msg(self): while True: @@ -533,7 +533,7 @@ def handle_file_msg(self): if flag: del self.file_msg[path] - self.send_efb_msgs(MsgProcess(msg, chat), author=author, chat=chat, uid=msg['msgid']) + self.send_efb_msgs(MsgWrapper(msg["message"], MsgProcess(msg, chat)), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) if len(self.delete_file): for k in list(self.delete_file.keys()): diff --git a/efb_wechat_comwechat_slave/MsgProcess.py b/efb_wechat_comwechat_slave/MsgProcess.py index e938061..db1e43a 100644 --- a/efb_wechat_comwechat_slave/MsgProcess.py +++ b/efb_wechat_comwechat_slave/MsgProcess.py @@ -12,6 +12,16 @@ from ehforwarderbot import utils as efb_utils from ehforwarderbot.message import Message +def MsgWrapper(xml, efb_msgs: Union[Message, List[Message]]): + efb_msgs = [efb_msgs] if isinstance(efb_msgs, Message) else efb_msgs + if not efb_msgs: + return + for efb_msg in efb_msgs: + vendor_specific = getattr(efb_msg, "vendor_specific", {}) + vendor_specific["wx_xml"] = xml + setattr(efb_msg, "vendor_specific", vendor_specific) + return efb_msgs + def MsgProcess(msg : dict , chat) -> Union[Message, List[Message]]: if msg["type"] == "text": From f4d80a5bdd78117645cd1a9b56eb766b997149be Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 12:15:07 +0800 Subject: [PATCH 2/6] feat: add displayname and content in quoto message --- efb_wechat_comwechat_slave/ComWechat.py | 114 ++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 5 deletions(-) diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index b91f962..1125159 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -8,6 +8,7 @@ import os import base64 from pathlib import Path +from xml.sax.saxutils import escape import re import json @@ -41,8 +42,108 @@ from PIL import Image from pyqrcode import QRCode -QUOTE_MESSAGE = '%s5700001%s%s%s01' -QUOTE_GROUP_MESSAGE = '%s5700001%s%s%s%s01' +QUOTE_GROUP_MESSAGE=""" + %s + 0 + + + %s + + view + 57 + 0 + + + + + + + + + + 1 + %s + %s + %s + %s + %s + + + + + + + 0 + + + + + + + + + + 0 + + + + + 1 + Window wechat + + +""" +QUOTE_MESSAGE=""" + %s + 0 + + + %s + + view + 57 + 0 + + + + + + + + + + 1 + %s + %s + + %s + %s + + + + + + + 0 + + + + + + + + + + 0 + + + + + 1 + Window wechat + + +""" class ComWeChatChannel(SlaveChannel): channel_name : str = "ComWechatChannel" @@ -86,7 +187,8 @@ def __init__(self, instance_id: InstanceID = None): self.qrcode_timeout = self.config.get("qrcode_timeout", 10) self.login() - self.wxid = self.bot.GetSelfInfo()["data"]["wxId"] + self.me = self.bot.GetSelfInfo()["data"] + self.wxid = self.me["wxId"] self.base_path = self.config["base_path"] if "base_path" in self.config else self.bot.get_base_path() self.dir = self.config["dir"] if not self.dir.endswith(os.path.sep): @@ -794,10 +896,12 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message': else: msgid = msg.target.uid sender = msg.target.author.uid + displayname = msg.target.author.display_name + content = escape(msg.target.vendor_specific.get("wx_xml", "")) if "@chatroom" in msg.author.chat.uid: - xml = QUOTE_GROUP_MESSAGE % (text, msgid, sender, msg.author.chat.uid, self.wxid) + xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, msg.author.chat.uid, displayname, content) else: - xml = QUOTE_MESSAGE % (text, msgid, sender, self.wxid) + xml = QUOTE_MESSAGE % (self.wxid, text, msgid, sender, displayname, content) return self.bot.SendXml(wxid = wxid , xml = xml, img_path = "") return self.bot.SendText(wxid = wxid , msg = text) From 6089f88d93dff67c60cbe5a0263fa7bf9d61b4a3 Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 17:19:55 +0800 Subject: [PATCH 3/6] fix: add chatusr in quoto message --- efb_wechat_comwechat_slave/ComWechat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 1125159..5cbd2fa 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -115,7 +115,7 @@ 1 %s %s - + %s %s %s @@ -896,12 +896,12 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message': else: msgid = msg.target.uid sender = msg.target.author.uid - displayname = msg.target.author.display_name + displayname = msg.target.author.name content = escape(msg.target.vendor_specific.get("wx_xml", "")) if "@chatroom" in msg.author.chat.uid: xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, msg.author.chat.uid, displayname, content) else: - xml = QUOTE_MESSAGE % (self.wxid, text, msgid, sender, displayname, content) + xml = QUOTE_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) return self.bot.SendXml(wxid = wxid , xml = xml, img_path = "") return self.bot.SendText(wxid = wxid , msg = text) From c455e6682fdf7504aab582e7798680bef1281846 Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 19:25:27 +0800 Subject: [PATCH 4/6] refator: move constants --- efb_wechat_comwechat_slave/ComWechat.py | 104 +----------------------- efb_wechat_comwechat_slave/Constant.py | 102 +++++++++++++++++++++++ 2 files changed, 103 insertions(+), 103 deletions(-) create mode 100644 efb_wechat_comwechat_slave/Constant.py diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 5cbd2fa..79a6a3e 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -35,6 +35,7 @@ from .MsgDeco import qutoed_text from .MsgProcess import MsgProcess, MsgWrapper from .Utils import download_file , load_config , load_temp_file_to_local , WC_EMOTICON_CONVERSION +from .Constant import QUOTE_MESSAGE, QUOTE_GROUP_MESSAGE from rich.console import Console from rich import print as rprint @@ -42,109 +43,6 @@ from PIL import Image from pyqrcode import QRCode -QUOTE_GROUP_MESSAGE=""" - %s - 0 - - - %s - - view - 57 - 0 - - - - - - - - - - 1 - %s - %s - %s - %s - %s - - - - - - - 0 - - - - - - - - - - 0 - - - - - 1 - Window wechat - - -""" -QUOTE_MESSAGE=""" - %s - 0 - - - %s - - view - 57 - 0 - - - - - - - - - - 1 - %s - %s - %s - %s - %s - - - - - - - 0 - - - - - - - - - - 0 - - - - - 1 - Window wechat - - -""" - class ComWeChatChannel(SlaveChannel): channel_name : str = "ComWechatChannel" channel_emoji : str = "💻" diff --git a/efb_wechat_comwechat_slave/Constant.py b/efb_wechat_comwechat_slave/Constant.py new file mode 100644 index 0000000..6c49a89 --- /dev/null +++ b/efb_wechat_comwechat_slave/Constant.py @@ -0,0 +1,102 @@ +QUOTE_GROUP_MESSAGE=""" + %s + 0 + + + %s + + view + 57 + 0 + + + + + + + + + + 1 + %s + %s + %s + %s + %s + + + + + + + 0 + + + + + + + + + + 0 + + + + + 1 + Window wechat + + +""" +QUOTE_MESSAGE=""" + %s + 0 + + + %s + + view + 57 + 0 + + + + + + + + + + 1 + %s + %s + %s + %s + %s + + + + + + + 0 + + + + + + + + + + 0 + + + + + 1 + Window wechat + + +""" From 1dc7825aad7735f14e452326a0f7b8e1d7f18f5f Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 19:25:43 +0800 Subject: [PATCH 5/6] fix: set chatusr as wxid in group message --- efb_wechat_comwechat_slave/ComWechat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 79a6a3e..18e0089 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -797,7 +797,7 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message': displayname = msg.target.author.name content = escape(msg.target.vendor_specific.get("wx_xml", "")) if "@chatroom" in msg.author.chat.uid: - xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, msg.author.chat.uid, displayname, content) + xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) else: xml = QUOTE_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) return self.bot.SendXml(wxid = wxid , xml = xml, img_path = "") From bca050119e1e198623211ba5081470367d76ef02 Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Tue, 15 Jul 2025 19:30:49 +0800 Subject: [PATCH 6/6] feat: set content as proper format --- efb_wechat_comwechat_slave/ComWechat.py | 4 ++++ efb_wechat_comwechat_slave/Constant.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 18e0089..aefdca4 100644 --- a/efb_wechat_comwechat_slave/ComWechat.py +++ b/efb_wechat_comwechat_slave/ComWechat.py @@ -796,6 +796,10 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message': sender = msg.target.author.uid displayname = msg.target.author.name content = escape(msg.target.vendor_specific.get("wx_xml", "")) + if content: + content = "%s" % content + else: + content = "" if "@chatroom" in msg.author.chat.uid: xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) else: diff --git a/efb_wechat_comwechat_slave/Constant.py b/efb_wechat_comwechat_slave/Constant.py index 6c49a89..e32b025 100644 --- a/efb_wechat_comwechat_slave/Constant.py +++ b/efb_wechat_comwechat_slave/Constant.py @@ -22,7 +22,7 @@ %s %s %s - %s + %s @@ -73,7 +73,7 @@ %s %s %s - %s + %s