|
8 | 8 | import os
|
9 | 9 | import base64
|
10 | 10 | from pathlib import Path
|
| 11 | +from xml.sax.saxutils import escape |
11 | 12 |
|
12 | 13 | import re
|
13 | 14 | import json
|
|
32 | 33 | from .ChatMgr import ChatMgr
|
33 | 34 | from .CustomTypes import EFBGroupChat, EFBPrivateChat, EFBGroupMember, EFBSystemUser
|
34 | 35 | from .MsgDeco import qutoed_text
|
35 |
| -from .MsgProcess import MsgProcess |
| 36 | +from .MsgProcess import MsgProcess, MsgWrapper |
36 | 37 | from .Utils import download_file , load_config , load_temp_file_to_local , WC_EMOTICON_CONVERSION
|
| 38 | +from .Constant import QUOTE_MESSAGE, QUOTE_GROUP_MESSAGE |
37 | 39 |
|
38 | 40 | from rich.console import Console
|
39 | 41 | from rich import print as rprint
|
40 | 42 | from io import BytesIO
|
41 | 43 | from PIL import Image
|
42 | 44 | from pyqrcode import QRCode
|
43 | 45 |
|
44 |
| -QUOTE_MESSAGE = '<?xml version="1.0"?><msg><appmsg appid="" sdkver="0"><title>%s</title><des /><action /><type>57</type><showtype>0</showtype><soundtype>0</soundtype><mediatagname /><messageext /><messageaction /><content /><contentattr>0</contentattr><url /><lowurl /><dataurl /><lowdataurl /><songalbumurl /><songlyric /><appattach><totallen>0</totallen><attachid /><emoticonmd5 /><fileext /><aeskey /></appattach><extinfo /><sourceusername /><sourcedisplayname /><thumburl /><md5 /><statextstr /><refermsg><type>1</type><svrid>%s</svrid><fromusr>%s</fromusr><chatusr /></refermsg></appmsg><fromusername>%s</fromusername><scene>0</scene><appinfo><version>1</version><appname></appname></appinfo><commenturl></commenturl></msg>' |
45 |
| -QUOTE_GROUP_MESSAGE = '<?xml version="1.0"?><msg><appmsg appid="" sdkver="0"><title>%s</title><des /><action /><type>57</type><showtype>0</showtype><soundtype>0</soundtype><mediatagname /><messageext /><messageaction /><content /><contentattr>0</contentattr><url /><lowurl /><dataurl /><lowdataurl /><songalbumurl /><songlyric /><appattach><totallen>0</totallen><attachid /><emoticonmd5 /><fileext /><aeskey /></appattach><extinfo /><sourceusername /><sourcedisplayname /><thumburl /><md5 /><statextstr /><refermsg><type>1</type><svrid>%s</svrid><fromusr>%s</fromusr><chatusr>%s</chatusr></refermsg></appmsg><fromusername>%s</fromusername><scene>0</scene><appinfo><version>1</version><appname></appname></appinfo><commenturl></commenturl></msg>' |
46 |
| - |
47 | 46 | class ComWeChatChannel(SlaveChannel):
|
48 | 47 | channel_name : str = "ComWechatChannel"
|
49 | 48 | channel_emoji : str = "💻"
|
@@ -86,7 +85,8 @@ def __init__(self, instance_id: InstanceID = None):
|
86 | 85 |
|
87 | 86 | self.qrcode_timeout = self.config.get("qrcode_timeout", 10)
|
88 | 87 | self.login()
|
89 |
| - self.wxid = self.bot.GetSelfInfo()["data"]["wxId"] |
| 88 | + self.me = self.bot.GetSelfInfo()["data"] |
| 89 | + self.wxid = self.me["wxId"] |
90 | 90 | self.base_path = self.config["base_path"] if "base_path" in self.config else self.bot.get_base_path()
|
91 | 91 | self.dir = self.config["dir"]
|
92 | 92 | if not self.dir.endswith(os.path.sep):
|
@@ -501,7 +501,7 @@ def handle_msg(self , msg : Dict[str, Any] , author : 'ChatMember' , chat : 'Cha
|
501 | 501 | self.file_msg[msg["filepath"]] = ( msg , author , chat )
|
502 | 502 | return
|
503 | 503 |
|
504 |
| - self.send_efb_msgs(MsgProcess(msg, chat), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) |
| 504 | + self.send_efb_msgs(MsgWrapper(msg["message"], MsgProcess(msg, chat)), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) |
505 | 505 |
|
506 | 506 | def handle_file_msg(self):
|
507 | 507 | while True:
|
@@ -533,7 +533,7 @@ def handle_file_msg(self):
|
533 | 533 |
|
534 | 534 | if flag:
|
535 | 535 | del self.file_msg[path]
|
536 |
| - self.send_efb_msgs(MsgProcess(msg, chat), author=author, chat=chat, uid=msg['msgid']) |
| 536 | + self.send_efb_msgs(MsgWrapper(msg["message"], MsgProcess(msg, chat)), author=author, chat=chat, uid=MessageID(str(msg['msgid']))) |
537 | 537 |
|
538 | 538 | if len(self.delete_file):
|
539 | 539 | for k in list(self.delete_file.keys()):
|
@@ -794,10 +794,16 @@ def send_text(self, wxid: ChatID, msg: Message) -> 'Message':
|
794 | 794 | else:
|
795 | 795 | msgid = msg.target.uid
|
796 | 796 | sender = msg.target.author.uid
|
| 797 | + displayname = msg.target.author.name |
| 798 | + content = escape(msg.target.vendor_specific.get("wx_xml", "")) |
| 799 | + if content: |
| 800 | + content = "<content>%s</content>" % content |
| 801 | + else: |
| 802 | + content = "<content />" |
797 | 803 | if "@chatroom" in msg.author.chat.uid:
|
798 |
| - xml = QUOTE_GROUP_MESSAGE % (text, msgid, sender, msg.author.chat.uid, self.wxid) |
| 804 | + xml = QUOTE_GROUP_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) |
799 | 805 | else:
|
800 |
| - xml = QUOTE_MESSAGE % (text, msgid, sender, self.wxid) |
| 806 | + xml = QUOTE_MESSAGE % (self.wxid, text, msgid, sender, sender, displayname, content) |
801 | 807 | return self.bot.SendXml(wxid = wxid , xml = xml, img_path = "")
|
802 | 808 | return self.bot.SendText(wxid = wxid , msg = text)
|
803 | 809 |
|
|
0 commit comments