def replay_revoke(msg): # No way to get around revoke actions rendered by itchat, # but it's OK 'cause msg sent by itchat is not in cache. if re.search(r"revokemsg", msg['Content']) is not None: old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1) for mid, un in ca.get(old_msg_id, []): itchat.revoke(mid, un)
def send_search_msg(session, search_result, curr_user): if 'reply' in session: itchat.revoke(session['reply'][0], session['reply'][1], curr_user) session = search_result ret_msg = ',\n'.join(['%d: %s' % e for e in enumerate(session.keys())]) ret_msg += '\n\nReply id to get link!\n回覆標號以獲取連結!' ret = itchat.send(ret_msg, curr_user) localID, msgID = ret['LocalID'], ret['MsgID'] session['reply'] = (localID, msgID) return session
def send_msg_helper(msg): clean_msg_cache() if re.search(r"type=\"revokemsg\"", msg['Content']) is not None: # 获取消息的id old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1) data = msg_dict.get(old_msg_id, None) if data: forward_msgs = data.get("forward_msgs") for item in forward_msgs: chatroom = item["chatroom"] recall_msg_id = item["msg"]["MsgID"] itchat.revoke(recall_msg_id, chatroom['UserName']) # 删除字典旧消息 msg_dict.pop(old_msg_id)
def msg_web_search(msg, session): print('Received:', msg['Content']) curr_user = msg['FromUserName'] if exist('bd', msg['Text']): search_result = search.text(msg['Text'].split(None, 1)[1]) session = send_search_msg(session, search_result, curr_user) elif exist('vd', msg['Text']): search_result = search.video(msg['Text'].split(None, 1)[1]) session = send_search_msg(session, search_result, curr_user) elif is_int(msg['Text']) and eval(msg['Text']) < len(session.keys()): key = list(session.keys())[eval(msg['Text'])] itchat.send('%s :%s\n%s\r\n' % (msg['Text'], key, session[key]), curr_user) elif exist('sc', msg['Text']): #only message with only 'sc' will trigger this if 'reply' in session: itchat.revoke(session['reply'][0], session['reply'][1], curr_user) session = dict() return session
def snap(msg, toUserName, delay=5): res = itchat.send(msg=msg, toUserName=toUserName) msgID = res['MsgID'] time.sleep(delay) revoke_res = itchat.revoke(msgID, toUserName) print(revoke_res)
def revoke(msg): global lastmsg, lastmsgid lastmsg = itchat.revoke(lastmsgid, lastid)