diff --git a/efb_wechat_comwechat_slave/ComWechat.py b/efb_wechat_comwechat_slave/ComWechat.py index 5102e57..aefdca4 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 @@ -32,8 +33,9 @@ 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 .Constant import QUOTE_MESSAGE, QUOTE_GROUP_MESSAGE from rich.console import Console from rich import print as rprint @@ -41,9 +43,6 @@ from PIL import Image from pyqrcode import QRCode -QUOTE_MESSAGE = '%s5700001%s%s%s01' -QUOTE_GROUP_MESSAGE = '%s5700001%s%s%s%s01' - class ComWeChatChannel(SlaveChannel): channel_name : str = "ComWechatChannel" channel_emoji : str = "💻" @@ -86,7 +85,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): @@ -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()): @@ -794,10 +794,16 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message': else: msgid = msg.target.uid 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 % (text, msgid, sender, msg.author.chat.uid, self.wxid) + xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) else: - xml = QUOTE_MESSAGE % (text, msgid, sender, self.wxid) + 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) diff --git a/efb_wechat_comwechat_slave/Constant.py b/efb_wechat_comwechat_slave/Constant.py new file mode 100644 index 0000000..e32b025 --- /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 + + +""" 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":