def wechat_friend_msg(self, msg): mobj = EFBMsg(self) txt = ("Friend request: {NickName}\n" "From: {Province}, {City}\n" "QQ: {QQNum}\n" "ID: {Alias}\n" "Signature: {Signature}\n" "Gender: {Sex}") tdict = msg['Text'].copy() tdict.update(msg['Text']['userInfo']) txt = txt.format(**tdict) mobj.text = txt mobj.type = MsgType.Command mobj.attributes = { "commands": [{ "name": "Send friend request", "callable": "add_friend", "args": [], "kwargs": { "userName": msg['Text']['userInfo']['UserName'], "status": 3, "ticket": msg['Ticket'] } }] } return mobj
def exit_callback(self): if self.stop_polling: return msg = EFBMsg(self) msg.source = MsgSource.System msg.origin = { 'name': '%s System' % self.channel_name, 'alias': '%s System' % self.channel_name, 'uid': -1 } msg.text = "WeChat server logged out the user." msg.type = MsgType.Text on_log_out = self._flag("on_log_out", "command") on_log_out = on_log_out if on_log_out in ("command", "idle", "reauth") else "command" if on_log_out == "command": msg.type = MsgType.Command msg.attributes = { "commands": [{ "name": "Log in", "callable": "reauth", "args": [], "kwargs": { "command": True } }] } elif on_log_out == "reauth": if self._flag("qr_reload", "master_qr_code") == "console_qr_code": msg.text += "\nPlease visit your console or log for QR code and further instructions." self.reauth() self.queue.put(msg)
def linkMsg(self, msg, isGroupChat=False): self.logger.info("---\nNew Link msg, %s", msg) # initiate object mobj = EFBMsg(self) # parse XML itchat.utils.emoji_formatter(msg, 'Content') xmldata = msg['Content'] data = xmltodict.parse(xmldata) # set attributes mobj.attributes = { "title": data['msg']['appmsg']['title'], "description": data['msg']['appmsg']['des'], "image": data['msg']['appmsg']['thumburl'], "url": data['msg']['appmsg']['url'] } if mobj.attributes['url'] is None: txt = mobj.attributes['title'] or '' txt += mobj.attributes['description'] or '' msg['Text'] = txt return self.textMsg(msg, isGroupChat) # format text mobj.text = "" if self._flag("extra_links_on_message", False): extra_link = data.get('msg', {}).get('appmsg', {}).get('mmreader', {}).get('category', {}).get('item', []) if type(extra_link) is list and len(extra_link): for i in extra_link: mobj.text += "🔗 %s\n%s\n%s\n🖼 %s\n\n" % ( i['title'], i['digest'], i['url'], i['cover']) mobj.type = MsgType.Link return mobj
def wechat_card_msg(self, msg): mobj = EFBMsg(self) txt = ("Name card: {NickName}\n" "From: {Province}, {City}\n" "QQ: {QQNum}\n" "ID: {Alias}\n" "Signature: {Signature}\n" "Gender: {Sex}") txt = txt.format(**msg['Text']) mobj.text = txt mobj.type = MsgType.Command mobj.attributes = { "commands": [ { "name": "Send friend request", "callable": "add_friend", "args": [], "kwargs": { "userName": msg['Text']['UserName'], "status": 2, "ticket": "" } } ] } return mobj
def wechat_location_msg(self, msg): mobj = EFBMsg(self) mobj.text = msg['Content'].split('\n')[0][:-1] loc = re.search("=-?([0-9.]+),-?([0-9.]+)", msg['Url']).groups() mobj.attributes = {"longitude": float(loc[1]), "latitude": float(loc[0])} mobj.type = MsgType.Location return mobj
def wechat_raw_link_msg(self, msg, title, description, image, url): mobj = EFBMsg(self) if url: mobj.type = MsgType.Link mobj.attributes = { "title": title, "description": description, "image": image, "url": url } else: mobj.type = MsgType.Text mobj.text = "%s\n%s" % (title, description) if image: mobj.text += "\n\n%s" % image return mobj
def linkMsg(self, msg, isGroupChat=False): self.logger.info("---\nNew Link msg, %s", msg) # initiate object mobj = EFBMsg(self) # parse XML itchat.utils.emoji_formatter(msg, 'Content') xmldata = msg['Content'] data = xmltodict.parse(xmldata) # set attributes mobj.attributes = { "title": data['msg']['appmsg']['title'], "description": data['msg']['appmsg']['des'], "image": None, "url": data['msg']['appmsg']['url'] } # format text mobj.text = "🔗 %s\n%s\n\n%s" % (mobj.attributes['title'], mobj.attributes['description'], mobj.attributes['url']) mobj.type = MsgType.Link return mobj
def friendMsg(self, msg, isGroupChat=False): mobj = EFBMsg(self) txt = ("Friend request: {NickName}\n" "From: {Province}, {City}\n" "QQ: {QQNum}\n" "ID: {Alias}\n" "Signature: {Signature}\n" "Gender: {Sex}") txt = txt.format(**{**msg['Text'], **msg['Text']['userInfo']}) mobj.text = txt mobj.type = MsgType.Command mobj.attributes = { "commands": [{ "name": "Send friend request", "callable": "add_friend", "args": [], "kwargs": { "userName": msg['Text']['userInfo']['UserName'], "status": 3, "ticket": msg['Ticket'] } }] } return mobj