Esempio n. 1
0
def group_pic(msg):
    group = itchat.get_chatrooms(update=True, )
    from_user = ''
    for g in group:
        if g['NickName'] == '来123':  #从群中找到指定的群聊
            from_group = g['UserName']
            ChatRoom = itchat.update_chatroom(from_group, detailedMember=True)
            for menb in ChatRoom['MemberList']:
                if menb['NickName'] == "柒年":  #从群成员列表找到用户,只转发他的消息
                    from_user = menb['UserName']
                    for j in group:
                        if j['NickName'] == '来':  #把消息发到这个群
                            to_group = j['UserName']
                            if msg['ToUserName'] == from_group:
                                if msg['FromUserName'] == from_user:
                                    msg['Text'](msg['FileName'])
                                    if msg['Type'] == "Picture":
                                        itchat.send_image(
                                            fileDir=msg['FileName'],
                                            toUserName=to_group)
                                    if msg['Type'] == "Recording":
                                        itchat.send_file(
                                            fileDir=msg['FileName'],
                                            toUserName=to_group)
                                    if msg['Type'] == "Attachment":
                                        itchat.send_file(
                                            fileDir=msg['FileName'],
                                            toUserName=to_group)
                                    if msg['Type'] == "Video":
                                        itchat.send_video(
                                            fileDir=msg['FileName'],
                                            toUserName=to_group)
Esempio n. 2
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
        # 获取消息的id
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName="******")
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = "告诉你一个秘密~" + "\n" \
                        + old_msg.get('msg_from') + " 撤回了 " + old_msg.get('msg_type') + " 消息" + "\n" \
                        + old_msg.get('msg_time_rec') + "\n" \
                        + "撤回了什么 " + "\n" \
                        + r"" + old_msg.get('msg_content')
            # 如果是分享,存在链接
            if old_msg['msg_type'] == "Sharing": msg_body += "\n就是这个链接 " + old_msg.get('msg_share_url')
            # 将撤回的消息发送到文件助手
            itchat.send(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg('msg_type') == "Picture" \
                    or old_msg('msg_type') == "Recording" \
                    or old_msg('msg_type') == "Video" \
                    or old_msg('msg_type') == "Attachment":
                file = "@file@%s" % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])
            # 删除字典旧消息
            msg_dict.pop(old_msg_id)
Esempio n. 3
0
def backup_push(msg):
    # 发送信息到通知群
    groupUserName = itchat.search_chatrooms('uuuu')[0]['UserName']
    # 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                           msg['Content']).group(1)  # 在返回的content查找撤回的消息的id
    old_msg = msg_information.get(old_msg_id)  # 得到消息
    # print(old_msg)
    if len(old_msg_id) < 11:  # 如果发送的是表情包
        itchat.send_file(face_bug, toUserName=groupUserName)
    else:  # 发送撤回的提示给文件助手
        msg_body = old_msg.get('msg_from') + ":\n" + time.strftime(
            "%H:%M\n", time.localtime()) + "撤回" + old_msg.get(
                "msg_type") + "\n" + "\n" + old_msg.get('msg_content')
        # 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
        if old_msg['msg_type'] == "Sharing":
            msg_body += "\n" + old_msg.get('msg_share_url')

        # 将撤回消息发送到文件助手
        itchat.send_msg(msg_body, groupUserName)
        # 有文件的话也要将文件发送回去
        if old_msg["msg_type"] == "Picture" \
                or old_msg["msg_type"] == "Recording" \
                or old_msg["msg_type"] == "Video" \
                or old_msg["msg_type"] == "Attachment":
            file = '@fil@%s' % (old_msg['msg_content'])
            itchat.send(msg=file, toUserName=groupUserName)
            os.remove(old_msg['msg_content'])
        # 删除字典旧消息
        msg_information.pop(old_msg_id)
Esempio n. 4
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
        # 获取消息的id
        print("发现撤回消息")
        old_msg_id = re.search("<msgid>(.*?)</msgid>", msg['Content']).group(1)
        print(old_msg_id)
        old_msg = msg_dict.get(old_msg_id, {})
        print(old_msg_id)
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = "告诉你一个秘密~" + " " + old_msg.get(
                'msg_from'
            ) + " 撤回了 " + old_msg.get("msg_type") + " 消息" + " " + old_msg.get(
                'msg_time_rec') + " " + "撤回了什么 ⇣" + " " + r"" + old_msg.get(
                    'msg_content')
            # 如果是分享存在链接
            print(msg_body)
            if old_msg['msg_type'] == "Sharing":
                msg_body += " 就是这个链接➣ " + old_msg.get('msg_share_url')

            # 将撤回消息发送到文件助手
            itchat.send(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" or old_msg[
                    "msg_type"] == "Recording" or old_msg[
                        "msg_type"] == "Video" or old_msg[
                            "msg_type"] == "Attachment":
                file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])
            # 删除字典旧消息
            msg_dict.pop(old_msg_id)
Esempio n. 5
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
        # 获取消息的id
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(
                                   1)  # 在返回的content查找撤回的消息的id
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = "快来看啊,有人撤回消息啦!" + "\n" \
                       + old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 消息" + "\n" \
                       + old_msg.get('msg_time_rec') + "\n" \
                       + "撤回了什么 ⇣" + "\n" \
                       + r"" + old_msg.get('msg_content')
            # 如果是分享存在链接
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')
            itchat.send(msg_body, toUserName='******')  # 将撤回消息发送到文件助手
            if old_msg["msg_type"] in ("Picture", "Recording", "Video",
                                       "Attachment"):
                file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])
            msg_dict.pop(old_msg_id)  # 删除字典旧消息
def information(msg):
    # 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content']:
        # 在返回的content查找撤回的消息的id
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
        # 获取到消息原文
        old_msg = msg_information.get(old_msg_id)
        # 如果发送的是表情包
        if len(old_msg_id)<11:
            # 发送撤回的提示给文件助手
            itchat.send_file(face_bug,toUserName='******')
        # 把暂时存储的信息可以删除掉,也可以选择不删除
        # os.remove(face_bug)
        else:
            msg_body = old_msg.get('group_name') + old_msg.get('msg_from') +"\n" + old_msg.get('msg_time_rec') \
                + "撤回了:" + "\n" + r"" + old_msg.get('msg_content')
            
            # 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n链接是:" + old_msg.get('msg_share_url')
            print msg_body
            # 将撤回消息发给文件助手
            itchat.send_msg(msg_body, toUserName='******')
            
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" \
                or old_msg["msg_type"] == "Recording" \
                or old_msg["msg_type"] == "Video" \
                or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                # 把暂时存储的信息可以删除掉,也可以选择不删除
                os.remove(old_msg['msg_content'])
            # 删除字典旧消息
    msg_information.pop(old_msg_id)
Esempio n. 7
0
    def send_wechat_file(self, mandatory_order=False):
        clock = time.localtime()
        if mandatory_order:
            pass
        elif clock[3] * 100 + clock[4] < 1503 or self.is_send_file or clock[3] * 100 + clock[4] > 1559:
            return
        elif self.next_reset_time - time.time() > 3600 * 7:
            return   # 在重置时间的7小时之内 既交易日当天的上午9点到下午4点之间发送自动文件
        message = time.strftime("%Y-%m-%d", time.localtime(self.next_reset_time))
        message += ' 今日缠论交易信号\n'
        file_list = list()
        for key_name in self.send_file_name.keys():
            fn = self.send_file_name[key_name]
            if not os.path.exists(fn):        # 判断文件是否存在
                message += key_name + ' not exist\n'
            elif os.path.getsize(fn) == 0:
                message += key_name + ' is empty\n'
            else:
                new_filename = create_file(fn)
                file_list.append(new_filename)

        itchat.send(message, toUserName='******')
        for receiver in self.wechat_file_receiver:
            user_id = self.wechat_id[receiver]
            ReturnValue = itchat.send(message, toUserName=user_id)
            if len(ReturnValue['MsgID']) == 0:
                print('请求失败')
                print(ReturnValue['BaseResponse'])
            for fn in file_list:
                itchat.send_file(fn, toUserName=user_id)
        self.is_send_file = True
        self.is_change = True
        print(message)
        print('send file over')
Esempio n. 8
0
def monitor(msg):
    if '撤回了一条消息' in msg['Content']:
        recall_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                                  msg['Content']).group(1)
        recall_msg = msg_info.get(recall_msg_id)
        print('[Recall]: %s' % recall_msg)
        # 表情包
        if len(recall_msg_id) < 11:
            itchat.send_file(face_package, toUserName='******')
        else:
            msg_prime = '---' + recall_msg.get('msg_from') + '撤回了一条消息---\n' \
               '消息类型:' + recall_msg.get('msg_type') + '\n' \
               '时间:' + recall_msg.get('msg_time_receive') + '\n' \
               '内容:' + recall_msg.get('msg_content')
            if recall_msg['msg_type'] == 'Sharing':
                msg_prime += '\n链接:' + recall_msg.get('msg_link')
            itchat.send_msg(msg_prime, toUserName='******')
            if recall_msg['msg_type'] == 'Attachment' or recall_msg[
                    'msg_type'] == "Video" or recall_msg[
                        'msg_type'] == 'Picture' or recall_msg[
                            'msg_type'] == 'Recording':
                file = '@fil@%s' % (recall_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(recall_msg['msg_content'])
            msg_info.pop(recall_msg_id)
Esempio n. 9
0
def download_files(msg):
    msg.download(msg.fileName)
    itchat.send(
        '@%s@%s' %
        ('img' if msg['Type'] == 'Picture' else 'fil', msg['FileName']),
        msg['FromUserName'])
    with open('temp.png', 'wb') as f:
        f1 = open(msg.fileName, 'rb')
        f.write(f1.read())
        f1.close()
    f = open('ocr.txt', 'w')
    f.close()
    ocrtxt()
    f2 = open('ocr1.txt', 'a')
    f = open('ocr.txt', 'r')
    f2.write(f.read())  #ocr1.txt保存识别后的资料
    f2.close()
    f.close()
    itchat.send_file('ocr.txt', 'filehelper')  #发送回手机当下识别的文本内容
    with open('cntext.txt', 'w') as f2:
        f = open('ocr1.txt', 'r')
        f2.write(f.read())  #ocr1.txt写入中文保存为cntext.txt,其他语种保持:news.txt
        f.close()
    with open('title.txt', 'w') as f:
        f.write(" ")
    return '%s received' % msg['Type']
Esempio n. 10
0
File: Main.py Progetto: 10o0/Wechat
def SaveMsg(msg):
    mytime = time.localtime()
    msg_time_touser = "******" % (
        mytime.tm_year.__str__(), mytime.tm_mon.__str__(),
        mytime.tm_mday.__str__(), mytime.tm_hour.__str__(),
        mytime.tm_min.__str__(), mytime.tm_sec.__str__())

    # 创建可下载消息内容的存放文件夹,并将暂存在当前目录的文件移动到该文件中
    if not os.path.exists("." + os.sep + "Revocation" + os.sep):
        os.mkdir("." + os.sep + "Revocation" + os.sep)

    msg_id, old_msg = GetOldMsg(msg)
    if old_msg:
        msg_send = GetSendMsg(old_msg, msg_time_touser)
        itchat.send(msg_send, toUserName='******')  # 将撤回消息的通知以及细节发送到文件助手
        itchat.send(
            '@%s@%s' %
            ('img' if old_msg['msg_type'] == 'Picture' else 'fil',
             "." + os.sep + "Revocation" + os.sep + old_msg["msg_content"]),
            'filehelper')
        #发送小视频,文件
        if (old_msg['msg_type'] == 'Attachment'):
            itchat.send_file(
                "." + os.sep + "Revocation" + os.sep + old_msg['msg_content'],
                'filehelper')
        if (old_msg['msg_type'] == 'Video'):
            itchat.send_video(
                "." + os.sep + "Revocation" + os.sep + old_msg["msg_content"],
                'filehelper')
        msg_dict.pop(msg_id)
Esempio n. 11
0
def save_recall(msg):
    # itchat.send_msg("recall...", toUserName='******')
    #这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content'] or 'recalled a message' in msg['Content']:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(1)  #在返回的content查找撤回的消息的id
        old_msg = querydb(str(old_msg_id))
        # old_msg = msg_information.get(old_msg_id)    #得到消息
        log('Recalled message detected...\n  --From ' + old_msg.msg_from +
            '\n  --To' + old_msg.msg_to)
        if len(old_msg_id) < 11:  #如果发送的是表情包
            itchat.send_file(old_msg.msg, toUserName='******')
        else:  #发送撤回的提示给文件助手
            msg_body = "Warning:" + "\n" \
                       + old_msg.msg_time_rec + "\n" \
                       + old_msg.msg_from + " (to " + old_msg.msg_to + ") has recalled a " \
                       + old_msg.msg_type + " message" + "\n" \
                       + r"" + old_msg.msg
            # + "Here is it ⇣" + "\n" \
            #如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg.msg_type == "Sharing":
                msg_body += "\nlink➣ \n" + old_msg.url

            # 将撤回消息发送到文件助手
            itchat.send_msg(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg.msg_type == "Picture" \
                    or old_msg.msg_type == "Recording" \
                    or old_msg.msg_type == "Video" \
                    or old_msg.msg_type == "Attachment":
                file = '@fil@%s' % (export_root + old_msg.msg)
                itchat.send(msg=file, toUserName='******')
Esempio n. 12
0
def information(msg):
    # 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content']:
        print(msg['MsgId'])
        # 测试中(问题未处理)
        # old_msg_id = re.search(r'&lt;msgid&gt;(.*?)&lt;/msgid&gt;', msg['Content']).group(1)  # 在返回的content查找撤回的消息的id
        old_msg_id = msg['MsgId']
        old_msg = msg_information.get(old_msg_id)  # 得到消息
        print(old_msg)

        if len(old_msg_id) < 11:  # 如果发送的是表情包
            itchat.send_file(face_bug, toUserName='******')
        else:  # 发送撤回的提示给文件助手
            msg_body = "[" \
                       + old_msg.get['msg_from'] + " 撤回了 ]\n" \
                       + old_msg.get["msg_type"] + " 消息:" + "\n" \
                       + old_msg.get['msg_time_rec'] + "\n" + str(old_msg['msg_content'])
            # 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')

            # 将撤回消息发送到文件助手
            itchat.send_msg(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" \
                    or old_msg["msg_type"] == "Recording" \
                    or old_msg["msg_type"] == "Video" \
                    or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(old_msg['msg_content'])
            # 删除字典旧消息
            msg_information.pop(old_msg_id)
Esempio n. 13
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"<![CDATA[.*撤回了一条消息]]>", msg['Content']) is not None:
        old_msg_id = re.search("<msgid>(.*?)</msgid>", msg['Content']).group(1)
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = "告诉你一个秘密~\n用户【{0}】 撤回了 {1} 消息\n【时间】:\n{2}\n【内容】:\n{3}".format(
                old_msg.get('msg_from'), old_msg.get("msg_type"),
                old_msg.get('msg_time_rec'), old_msg.get('msg_content'))

            if old_msg['msg_type'] == "Sharing":
                msg_body += " 【链接】➣ " + old_msg.get('msg_share_url')

            itchat.send(msg_body, toUserName='******')

            if old_msg["msg_type"] == "Picture" or old_msg[
                    "msg_type"] == "Recording" or old_msg[
                        "msg_type"] == "Video" or old_msg[
                            "msg_type"] == "Attachment":
                file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])

            msg_dict.pop(old_msg_id)
Esempio n. 14
0
def monitor(msg):
    if '撤回了一条消息' in msg['Content']:
        # 获取消息的id
        old_msg_id = re.search("<msgid>(.*?)</msgid>", msg['Content']).group(1)
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            print(old_msg.get('msg_from'), old_msg.get("msg_type"), old_msg.get("msg_time_rec"),
                  old_msg.get("msg_content"))
            msg_body = "告诉你一个秘密~" " 您的好友" + old_msg.get('msg_from')['NickName'] + " 撤回了 " + old_msg.get("msg_type") \
                       + " 消息," + "撤回时间:" + old_msg.get('msg_time_rec') + "," + "撤回了内容是:" + " " + r"" + \
                       old_msg.get('msg_content')
            # 如果是分享存在链接
            if old_msg['msg_type'] == "Sharing":
                msg_body += " 就是这个链接➣ " + old_msg.get('msg_share_url')

            # 将撤回消息发送到文件助手
            itchat.send(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" or old_msg["msg_type"] == "Recording" or old_msg[
                "msg_type"] == "Video" or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])
            # 删除字典旧消息
            msg_dict.pop(old_msg_id)
Esempio n. 15
0
    def SendRevokeMsg(self, msg):
        """
        把撤回的消息发送到文件助手
        """
        msg_id = self.IsRevokeMsg(msg)  #获取撤回消息的ID
        msg_content = self.msg_store.get(msg_id, None)  #获取撤回消息的内容

        mytime = time.localtime()
        msg_time = "%s/%s/%s %s:%s:%s" % (
            mytime.tm_year.__str__(), mytime.tm_mon.__str__(), mytime.tm_mday.__str__(), 
            mytime.tm_hour.__str__(),mytime.tm_min.__str__(), mytime.tm_sec.__str__())

        if (msg_id != None) and (msg_content != None):
            sendMsg = ""
            if msg_content['msg_group']:
                sendMsg += "群聊%s中"%(msg_content['msg_group'])
            sendMsg += "'%s'"%(msg_content['msg_from'])
            sendMsg += "在%s撤回了一条消息:\n"%(msg_time)
            if msg_content['msg_type'] == 'Sharing':
                sendMsg += "%s%s" % (msg_content['msg_url'], "\n\n")
            sendMsg += "%s"%(msg_content['msg_content'])

            itchat.send(sendMsg, toUserName = '******')
            if msg_content['msg_type'] == 'Picture':
                itchat.send_image(".\\Cache\\" + msg_content['msg_content'], toUserName = '******')
            elif msg_content['msg_type'] == 'Video':
                itchat.send_video(".\\Cache\\" + msg_content['msg_content'], toUserName = '******')
            elif (msg_content['msg_type'] == 'Attachment') or \
                (msg_content['msg_type'] == 'Recording'):
                itchat.send_file(".\\Cache\\" + msg_content['msg_content'], toUserName = '******')

            self.msg_store.pop(msg_id)
            if os.path.exists(".\\Cache\\" + msg_content['msg_content']):
                os.remove(".\\Cache\\" + msg_content['msg_content'])
Esempio n. 16
0
def msg_receive(msg):
    print(json.dumps(msg))
    if msg['FromUserName'].startswith("@@"):
        print(
            'receive msg :\n', "from group %s - %s : %s" %
            (msg['User']['NickName'], msg['ActualNickName'], msg.text))
        if (dfa(msg.text)):
            itchat.add_friend(msg.actualUserName, verifyContent='嘿嘿')
            s = "中国共产党同全国各民族工人、农民、知识分子团结在一起,同各民主党派、无党派人士、各民族的爱国力量团结在一起,进一步发展和壮大由全体社会主义劳动者、社会主义事业的建设者、拥护社会主义的爱国者、拥护祖国统一和致力于中华民族伟大复兴的爱国者组成的最广泛的爱国统一战线。"
            return "%s  ! %s" % (msg.actualNickName, s)
        if '加我好友' in msg.text:
            itchat.add_friend(msg.actualNickName, verifyContent='hello')
            itchat.send_msg('asdf', toUserName=msg.actualNickName)
        if msg.isAt:
            # someone @me
            msg.user.send(u'@%s\u2005 : 我收到了 --> %s 不要急...' %
                          (msg.actualNickName, msg.text))
        return
    res = reply(msg.text)
    print('receive msg :\n',
          "from friends %s : %s" % (msg['User']['NickName'], msg.text))
    if isinstance(res, dict):
        ty = res['type']
        if ty == 'img':
            itchat.send_image(res['path'], msg['FromUserName'])
        elif ty == 'file':
            itchat.send_file(res['path'], msg['FromUserName'])
    elif isinstance(res, str):
        if res == 'no_msg':
            pass
        else:
            return res
Esempio n. 17
0
def to_laopo(_type, msg, kivy, _path=None):
    if msg.User.UserName[0:2] != '@@':
        return
    try:
        _group_name = msg.User.NickName
    except:
        _group_name = ""

    if _group_name in [
            '盛世名门群主楼长群', '名门团队', '吃花生🥜', '宏城汇新希望群(物业交流)', '盛世名门业主代表沟通交流群',
            '宏城汇商场事宜沟通群', '商场围闭沟通群', '测试群'
    ]:
        _user_name = msg.ActualNickName

        if _type == TEXT:
            itchat.send('[' + _group_name + ']' + _user_name + ':\n' +
                        msg.text,
                        toUserName=kivy.laopo_username)
        elif _type == PICTURE:
            itchat.send('[' + _group_name + ']' + _user_name + ':',
                        toUserName=kivy.laopo_username)
            itchat.send_image(_path, toUserName=kivy.laopo_username)
        elif _type in [ATTACHMENT, RECORDING]:
            itchat.send('[' + _group_name + ']' + _user_name + ':',
                        toUserName=kivy.laopo_username)
            itchat.send_file(_path, toUserName=kivy.laopo_username)
        elif _type in [VIDEO]:
            itchat.send('[' + _group_name + ']' + _user_name + ':',
                        toUserName=kivy.laopo_username)
            itchat.send_video(_path, toUserName=kivy.laopo_username)

    pass
Esempio n. 18
0
        def text_reply_xiaoice(msg):
            print('text_reply_xiaoice:', msg['Type'], msg['Content'], msg)
            if msg['FromUserName'] == self.xiaoice_id:
                now = time.time()
                double_replay = False
                if (now - self.last_replay <= 6 and msg['Type']
                        == 'Recording') or now - self.last_replay <= 2:
                    double_replay = True

                self.last_replay = now
                if len(self.chat_queue) > 0 or double_replay:
                    if double_replay:
                        item = self.last_chat
                    else:
                        item = self.chat_queue.pop(0)

                    self.last_chat = item

                    if item['target'] in self.regist_groups:
                        if msg['Type'] == 'Picture':
                            path = u"./imgs/%s" % msg['FileName']
                            msg['Text'](path)
                            itchat.send_image(path, item['target'])
                        elif msg['Type'] == 'Recording':
                            path = u"./records/%s" % msg['FileName']
                            msg['Text'](path)
                            itchat.send_file(path, item['target'])
                        else:
                            itchat.send(msg['Content'], item['target'])

                    if not double_replay:
                        self.send_to_xiaoice()
def file_reply(msg):
    is_group = False
    target = msg['User']['UserName']
    msg.download('./FileCache/' + msg.fileName)
    if is_group:
        sender_name = msg['ActualNickName'] if msg[
            'ActualNickName'] != '' else msg['User']['Self']['NickName']
        # 消息来自于哪个群聊
        group_name = msg['User']['NickName']
        sender_name = '{} {}'.format(group_name, sender_name)
    else:
        sender_name = msg['User']['NickName'] if 'NickName' in msg[
            'User'] else 'filehelper'
    if msg['Type'] == 'Picture':
        itchat.send_msg('{} send picture: '.format(sender_name), target)
        itchat.send_image('./FileCache/' + msg.fileName, target)
    elif msg['Type'] == 'Recording':
        msg.user.send('%s : %s' % (msg.type, msg.text))
        itchat.send_msg('{} send recording: '.format(sender_name), target)
        itchat.send_file('./FileCache/' + msg.fileName, target)
    elif msg['Type'] == 'Video':
        itchat.send_msg('{} send recording: '.format(sender_name), target)
        itchat.send_video('./FileCache/' + msg.fileName, target)
    else:
        itchat.send_msg('{} send file: '.format(sender_name), target)
        itchat.send_file('./FileCache/' + msg.fileName, target)
Esempio n. 20
0
def revoke_msg(msg):
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(1)
        old_msg = rec_msg_dict.get(old_msg_id, {})
        # 先发送一条文字信息
        itchat.send_msg(str(
            old_msg.get('msg_from_user') + "撤回了一条信息:" +
            old_msg.get('msg_content')),
                        toUserName="******")
        # 判断文msg_content是否存在,不存在说明可能是
        if os.path.exists(os.path.join(rec_tmp_dir,
                                       old_msg.get('msg_content'))):
            if old_msg.get('msg_type') == 'Picture':
                itchat.send_image(os.path.join(rec_tmp_dir,
                                               old_msg.get('msg_content')),
                                  toUserName="******")
            elif old_msg.get('msg_type') == 'Video':
                itchat.send_video(os.path.join(rec_tmp_dir,
                                               old_msg.get('msg_content')),
                                  toUserName="******")
            elif old_msg.get('msg_type') == 'Attachment' \
                    or old_msg.get('msg_type') == 'Recording':
                itchat.send_file(os.path.join(rec_tmp_dir,
                                              old_msg.get('msg_content')),
                                 toUserName="******")
    print(msg)
Esempio n. 21
0
def AIreply(msg):
    print("收到")
    if msg['Type'] == 'Picture':
        msg['Text'](msg['FileName'])
        itchat.send_image(msg['FileName'], toUserName=userId)
        os.remove(msg['FileName'])
    elif msg['Type'] == 'Video':
        msg['Text'](msg['FileName'])
        itchat.send_video(msg['FileName'], toUserName=userId)
        os.remove(msg['FileName'])
    elif msg['Type'] == 'Recording':
        msg['Text'](msg['FileName'])  #保存为mp3
        itchat.send_file(msg['FileName'], toUserName=userId)
        os.remove(msg['FileName'])
    elif msg['Type'] == 'Text':
        if ('http' in msg['Text']):
            dealLink(msg)
        itchat.send_msg(msg['Text'], toUserName=userId)
    elif msg['Type'] == 'Sharing':
        print("音乐")
        message = re.findall('<url>.*</url>', msg['Content'])[0][5:-6]
        if (message[0:4] == "http"):
            itchat.send(message, toUserName=userId)
    else:
        pass
Esempio n. 22
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) \
            is not None:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", \
                                msg['Content']).group(1)
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rec_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = "有人撤回消息" + "\n" \
                + old_msg.get('msg_from') + " 撤回了 " \
                + old_msg.get('msg_type') + " 消息" + "\n" \
                + old_msg.get('msg_time_rec') + "\n" \
                + r"" + old_msg.get('msg_content')
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n就是这个连接->" + old_msg.get('msg_share_url')
            itchat.send(msg_body, toUserName='******')
            if old_msg["msg_type"] == "Picture" \
                    or old_msg["msg_type"] == "Recording" \
                    or old_msg["msg_type"] == "Video" \
                    or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (rec_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rec_tmp_dir + old_msg['msg_content'])
            msg_dict.pop(old_msg_id)
Esempio n. 23
0
def file_reply(msg):
    global private_users, admin_users
    get_config_users()
    sender_name = msg['User']['NickName'] if 'NickName' in msg['User'] else 'filehelper'
    msg.download('./filecache/' + msg.fileName)
    logger.logger.info('[file_reply] Files recieved from:{}'.format(sender_name))
    for user in private_users:
        if user in sender_name:
            receiver = 'admin_users'
            break
        else:
            receiver = 'filehelper'
    if receiver == 'filehelper':
        logger.logger.info('[file_reply] Files forward to:{}'.format(receiver))
        if msg.type == 'PICTURE':
            itchat.send_image('./filecache/' + msg.fileName, receiver)
        elif msg.type == 'VIDEO':
            itchat.send_video('./filecache/' + msg.fileName, receiver)
        else:
            itchat.send_file('./filecache/' + msg.fileName, receiver)
    elif receiver == 'admin_users':
        logger.logger.info('[file_reply] Files forward to:{}'.format(receiver))
        for admin_user in admin_users:
            if msg.type == 'PICTURE':
                itchat.send_image('./filecache/' + msg.fileName, admin_users[admin_user])
            elif msg.type == 'VIDEO':
                itchat.send_video('./filecache/' + msg.fileName, admin_users[admin_user])
            else:
                itchat.send_file('./filecache/' + msg.fileName, admin_users[admin_user])
Esempio n. 24
0
def send_msg_helper(msg):
    global face_bug
    if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(1)
        old_msg = msg_dict.get(old_msg_id, {})
        if len(old_msg_id) < 11:
            itchat.send_file(rev_tmp_dir + face_bug, toUserName='******')
            os.remove(rev_tmp_dir + face_bug)
        else:
            msg_body = old_msg.get('msg_from') + "撤回了" + old_msg.get('msg_type') \
                       + "消息\n" \
                       + old_msg.get('msg_time_rev') + "\n" \
                       + old_msg.get('msg_content')
            if old_msg.get('group_name') is not None:
                msg_body = old_msg.get('group_name') + ">" + msg_body
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n" + old_msg.get('msg_share_url')
            # 将撤回的消息发给文件助手
            itchat.send(msg_body, toUserName='******')
            if old_msg['msg_type'] == PICTURE or old_msg['msg_type'] == RECORDING or old_msg['msg_type'] == VIDEO \
                    or old_msg['msg_type'] == ATTACHMENT:
                file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(rev_tmp_dir + old_msg['msg_content'])
            msg_dict.pop(old_msg_id)
Esempio n. 25
0
def send_msg_helper(msg):
    global face_bug
    print("-->"+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())+"--撤回消息:"+str(msg))
    if re.search(r"<!\[CDATA\[.*撤回了一条消息\]\]>",msg["Content"]) is not None:
        #获取消息的id
        old_msg_id=re.search("<msgid>(.*?)</msgid>",msg['Content']).group(1)
        old_msg=msg_dict.get(old_msg_id,{})
        if len(old_msg_id)<11:
            itchat.send_file(rev_tmp_dir+face_bug,toUserName='******')
            os.remove(rev_tmp_dir+face_bug)
        else:
            msg_body="告诉你一个秘密~"+""+old_msg.get("msg_from")+" 撤回了 "+old_msg.get("msg_type")+" 消息 "+" "+old_msg.get("msg_time_rec")+" "+"撤回了什么 ⇣"+" "+r""+old_msg.get("msg_content")
            #如果是分享存在的连接
            if old_msg['msg_type']=='Sharing':
                msg_body+= " 就是这个链接➣ " + old_msg.get('msg_share_url')
            
            #将撤回消息发送到文件助手
            itchat.send(msg_body,toUserName='******')
            #有文件的话也要讲文件发送回去
            if old_msg['msg_type']=='Picture' or old_msg['msg_type']=='Recording' or old_msg['msg_type']=='Video' or old_msg['msg_type']=='Attachment':
                file='@file@%s'%(rev_tmp_dir+old_msg['msg_content'])
                itchat.send(msg=file,toUserName='******')
                os.remove(rev_tmp_dir+old_msg['msg_content'])
            #删除字典就消息
            msg_dict.pop(old_msg_id)
Esempio n. 26
0
def information(msg):
    # 如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '已回收一條訊息' in msg['Content']:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(
                                   1)  # 在返回的content查找撤回的消息的id
        print(old_msg_id + 'old_msg_id')
        old_msg = msg_information.get(old_msg_id)  # 获取到消息原文,类型:字典
        if len(old_msg_id) < 11:  # 如果发送的是表情包
            itchat.send_file(face_bug, toUserName='******')

        else:  # 发送撤回的提示给文件助手
            msg_body = old_msg['group_name'] + old_msg['msg_from'] + "\n" + old_msg['msg_time_rec'] \
                       + "撤回了:" + "\n" + r"" + old_msg['msg_content']

            # 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n链接是:" + old_msg.get('msg_share_url')
            # print(msg_body)
            itchat.send_msg(msg_body, toUserName='******')  # 将撤回消息发给文件助手

            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" \
                    or old_msg["msg_type"] == "Recording" \
                    or old_msg["msg_type"] == "Video" \
                    or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(old_msg['msg_content'])
            msg_information.pop(old_msg_id)  # 删除字典旧消息
Esempio n. 27
0
def text_reply_group(msg):
    # print(msg)
    # print(msg.ActualNickName)
    UID = msg["FromUserName"]
    userName = msg.ActualNickName
    if msg.ActualNickName in ["Potter", "皮皮皮"] or msg.ActualNickName == "":
        userName = "******"
        SendUserName = msg.ToUserName
    else:
        SendUserName = msg.FromUserName
    print(msg.text, UID, userName)
    backs = pipiBot.phraseString(msg.text, userName, UID)
    print(backs)

    if isStartWith(msg.text, "!music"):
        print("in music")
        r = itchat.send('一首成都送给你', toUserName=SendUserName)
        r = itchat.send_file('chengdu2.mp3', toUserName=SendUserName)
        print(r)

    if isStartWith(msg.text, "!pipinight"):
        print("in story")
        r = itchat.send('皮皮虾祝你好梦 \n睡前故事准备中', toUserName=SendUserName)
        r = itchat.send_file(getNightStoryFilePath(), toUserName=SendUserName)
        print(r)

    for back in backs:
        itchat.send(back, toUserName=SendUserName)
Esempio n. 28
0
def information(msg):
    #这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content']:
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                               msg['Content']).group(1)  #在返回的content查找撤回的消息的id
        old_msg = msg_information.get(old_msg_id)  #得到消息
        print(old_msg)
        if len(old_msg_id) < 11:  #如果发送的是表情包
            itchat.send_file(face_bug, toUserName='******')
        else:  #发送撤回的提示给文件助手
            msg_body = "告诉你一个秘密~" + "\n" \
                       + old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 消息" + "\n" \
                       + old_msg.get('msg_time_rec') + "\n" \
                       + "撤回了什么 ⇣" + "\n" \
                       + r"" + old_msg.get('msg_content')
            #如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')

            # 将撤回消息发送到文件助手
            itchat.send_msg(msg_body, toUserName='******')
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" \
                    or old_msg["msg_type"] == "Recording" \
                    or old_msg["msg_type"] == "Video" \
                    or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (old_msg['msg_content'])
                itchat.send(msg=file, toUserName='******')
                os.remove(old_msg['msg_content'])
            # 删除字典旧消息
            msg_information.pop(old_msg_id)
def handle_recall_friendchat(msg):
    if '撤回了一条消息' in msg['Content']:
        old_msg_id = re.search(r'\<msgid\>(.*?)\<\/msgid\>',
                               msg['Content']).group(1)
        old_msg = msg_info[old_msg_id]
        print(old_msg_id)
        print(old_msg)

        itchat.send_msg('%s撤回了一条%s消息[%s],内容为:%s' %
                        (old_msg['msg_from'], old_msg['msg_type'],
                         old_msg['msg_recv_time'], old_msg['msg_content']),
                        toUserName='******')

        # 分享链接还需要发送地址
        if old_msg['msg_type'] == ' Sharing':
            itchat.send_msg('->%s' % old_msg['msg_url'],
                            toUserName='******')

        # 多媒体内容还需要发送文件
        if old_msg['msg_type'] == 'Recording' or old_msg[
                'msg_type'] == 'Attachment':
            itchat.send_file(rev_tmp_dir + old_msg['msg_content'],
                             toUserName='******')  # 发送自动下载的语音或附件

        if old_msg['msg_type'] == 'Picture':
            itchat.send_image(rev_tmp_dir + old_msg['msg_content'],
                              toUserName='******')  # 发送自动下载的照片

        if old_msg['msg_type'] == 'Video':
            itchat.send_video(rev_tmp_dir + old_msg['msg_content'],
                              toUserName='******')  # 发送自动下载的视频

        msg_info.pop(old_msg_id)
Esempio n. 30
0
 def monitorMsg(msg):
     if u'撤回了一条消息' in msg['Content']:
         callBack_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>",
                                     msg['Content']).group(1)
         callBack_msg = MSGINFO.get(callBack_msg_id)
         if len(callBack_msg_id) < 11:
             itchat.send_file(FACEPACKAGE, toUserName='******')
         else:
             prompt = u'+++' + callBack_msg.get('msg_from') + u'撤回了一条消息+++\n' \
                                                              u'--消息类型:' + callBack_msg.get('msg_type') + '\n' \
                                                                                                          u'--接收时间:' + callBack_msg.get(
                 'msg_receive_time') + '\n' \
                                       u'--消息内容:' + callBack_msg.get('msg_content')
             if callBack_msg['msg_type'] == 'Sharing':
                 prompt += u'\n链接:' + callBack_msg.get('msg_link')
             itchat.send_msg(str(prompt), toUserName='******')
             if callBack_msg['msg_type'] == 'Attachment' or callBack_msg[
                     'msg_type'] == "Video" or callBack_msg[
                         'msg_type'] == 'Picture' or callBack_msg[
                             'msg_type'] == 'Recording':
                 file = '@fil@%s' % (callBack_msg['msg_content'])
                 itchat.send(msg=file, toUserName='******')
                 os.remove(callBack_msg['msg_content'])
             self.getMsgSignal.emit('当前一条消息被撤回,已发送至文件助手')
             MSGINFO.pop(callBack_msg_id)
Esempio n. 31
0
def information(msg):
    #这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content']:
        old_msg_id = re.search(r"\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)  #在返回的content查找撤回的消息的id
        old_msg = msg_information.get(old_msg_id)  #得到消息
        #print (old_msg)

    if len(old_msg_id)<11: #如果发送的是表情包
        itchat.send_file(face_bug,toUserName='******')
    else: #发送撤回的提示给文件助手
        msg_body = "告诉你一个秘密~" + "\n" \
            + old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 消息" + "\n" \
            + old_msg.get('msg_time_rec') + "\n" \
            + "撤回了什么 ⇣" + "\n" \
            + r"" + old_msg.get('msg_content')
      #如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
    if old_msg['msg_type'] == "Sharing":
        msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')
 
    # 将撤回消息发送到文件助手
    itchat.send_msg(msg_body, toUserName='******')
    # 有文件的话也要将文件发送回去
    if old_msg["msg_type"] == "Picture" \
          or old_msg["msg_type"] == "Recording" \
          or old_msg["msg_type"] == "Video" \
          or old_msg["msg_type"] == "Attachment":
        file = '@fil@%s' % (old_msg['msg_content'])
        itchat.send(msg=file, toUserName='******')
        os.remove(old_msg['msg_content'])
    
    # 删除字典旧消息
    msg_information.pop(old_msg_id)