Пример #1
0
def groupchat_reply(msg):
    sendBackUser = itchat.search_friends(name=sys.argv[1])
    UserID = sendBackUser[0]['UserName']
    if msg['MsgType'] == 1:
        print('Recieve a text message!')

        dealMsg(msg)

        textContent = msg['Text']
        if (msg['FromUserName'] != itchat.originInstance.storageClass.userName
            ) and (analyze(textContent, 0)):
            itchat.send(
                u'您在群聊“%s”中被“%s”被询问私人信息,请注意防范。聊天内容为:\n\n%s\n\n请及时撤回' %
                (msg['User']['NickName'], msg['ActualNickName'],
                 msg['Content']), UserID)
        elif (msg['FromUserName']
              == itchat.originInstance.storageClass.userName
              ) and ifPersonalInfo(textContent):
            itchat.send(
                u'您在群聊“%s”中向“%s”泄露了私人信息,请注意防范。聊天内容为:\
				\n\n%s\n\n请及时撤回' % (msg['User']['NickName'], msg['ActualNickName'],
                        msg['Content']), UserID)

    if msg['MsgType'] == 49:
        print('Recieve a notification!')
        titleContent = msg['FileName']
        snippetContent = msg['Content']
        if analyzeJunk(titleContent) or re.findall(snippetContent):
            print('annoying notification detected!')
            itchat.send(
                u'您在群聊“%s”中收到“%s”的一条垃圾推送,其标题为:\n\n%s\n\n请 \
			注意钱包安全\ue409' %
                (msg['User']['NickName'], msg['ActualNickName'], titleContent),
                UserID)
Пример #2
0
def text_reply(msg):
    sendBackUser = itchat.search_friends(name=sys.argv[1])
    UserID = sendBackUser[0]['UserName']

    if (msg['FromUserName'] == UserID):
        print(msg['Content'] == u'我要检查未读消息')
        if msg['Content'] == u'我要检查未读消息':
            print("Check group message")
            textList = checkGroupMsg()
            for text in textList:
                itchat.send(text, itchat.originInstance.storageClass.userName)
            groupDict.clear()
            return

        print('Master received a message from slave')
        return  # if the message is from the slave, we believe it is safe
    if msg['MsgType'] == 1:
        print('Master Recieved a text message!')
        textContent = msg['Text']
        if (msg['FromUserName'] != itchat.originInstance.storageClass.userName
            ) and (analyze(textContent, 0)):
            itchat.send(
                u'您可能在和“%s”的聊天中被询问私人信息,请注意防范 聊天内容为:\n\n%s' %
                (msg['User']['NickName'], msg['Text']), UserID)
        elif (msg['FromUserName']
              == itchat.originInstance.storageClass.userName) and (
                  ifPersonalInfo(textContent)):
            itchat.send(
                u'您可能在和“%s”的聊天中泄露了私人信息,请注意防范 聊天内容为:\n\n%s\n\n请及时撤回' %
                (msg['User']['NickName'], msg['Text']), UserID)
    if msg['MsgType'] == 49:
        print('Master recieved a notification!')
        titleContent = msg['FileName']
        snippetContent = msg['Content']
        if analyzeJunk(titleContent) or re.findall(snippetContent):
            print('Master received an annoying notification!')
            itchat.send(
                u'您在和“%s”的聊天中收到一条垃圾推送,其标题为:\n\n%s\n\n请 \
			注意钱包安全\ue409' % (msg['User']['NickName'], titleContent), UserID)
Пример #3
0
def handle_receive_msg(msg):
    global face_bug
    # 接受消息的时间
    msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # groupid = msg['FromUserName']
    # chatroom = itchat.search_chatrooms(userName=groupid)
    msg_Actual_from = msg['ActualNickName']
    # msg_Actual_from = msg['User']
    # msg_from = msg_Actual_from['Self']['NickName']
    msg_from = msg_Actual_from
    msg_time = msg['CreateTime']  # 信息发送的时间
    msg_id = msg['MsgId']  # 每条信息的id
    msg_content = None  # 储存信息的内容
    msg_share_url = None  # 储存分享的链接,比如分享的文章和音乐
    print(msg['Type'])
    print(msg['MsgId'])

    # 如果发送的消息是文本或者好友推荐
    if msg['Type'] == 'Text' or msg['Type'] == 'Friends':
        msg_content = msg['Text']
        print(msg_content)
        if (msg['FromUserName'] != itchat.originInstance.storageClass.userName) and (analyze(msg_content, 0)):
            # print(msg_from)
            itchat.send(u'您可能在和“%s”的聊天中被询问私人信息,请注意防范 聊天内容为:\n\n%s' %
                        (msg_from, msg['Text']), toUserName='******')
        elif (msg['FromUserName'] == itchat.originInstance.storageClass.userName) and (ifPersonalInfo(msg_content)):
            itchat.send(u'您可能在和“%s”的聊天中泄露了私人信息,请注意防范 聊天内容为:\n\n%s\n\n请及时撤回' %
                        (msg_from, msg['Text']), toUserName='******')
    # 如果发送的消息是附件、视屏、图片、语音
    elif msg['Type'] == "Attachment" or msg['Type'] == "Video" \
            or msg['Type'] == 'Picture' \
            or msg['Type'] == 'Recording':
        msg_content = msg['FileName']  # 内容就是他们的文件名
        msg['Text'](str(msg_content))  # 下载文件
        # print msg_content
    elif msg['Type'] == 'Card':  # 如果消息是推荐的名片
        # 内容就是推荐人的昵称和性别
        msg_content = msg['RecommendInfo']['NickName'] + '的名片'
        if msg['RecommendInfo']['Sex'] == 1:
            msg_content += '性别为男'
        else:
            msg_content += '性别为女'
        print(msg_content)
    elif msg['Type'] == 'Map':  # 如果消息为分享的位置信息
        x, y, location = re.search(
            "<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*",
            msg['OriContent']).group(1, 2, 3)
        if location is None:
            # 内容为详细的地址
            msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()
        else:
            msg_content = r"" + location
    elif msg['Type'] == 'Sharing':
        # 如果消息为分享的音乐或者文章,详细的内容为文章的标题或者是分享的名字
        msg_content = msg['Text']
        msg_share_url = msg['Url']  # 记录分享的url
        print(msg_share_url)
    face_bug = msg_content

    ##将信息存储在字典中,每一个msg_id对应一条信息
    msg_information.update(
        {
            msg_id: {
                "msg_from": msg_from, "msg_time": msg_time, "msg_time_rec": msg_time_rec,
                "msg_type": msg["Type"],
                "msg_content": msg_content, "msg_share_url": msg_share_url
            }
        }
    )
Пример #4
0
def handle_receive_msg(msg):
    global face_bug
    # 接受消息的时间
    msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # 在好友列表中查询发送信息的好友昵称
    msg_from = itchat.search_friends(userName=msg['FromUserName'])['NickName']
    msg_time = msg['CreateTime']  # 信息发送的时间
    msg_id = msg['MsgId']  # 每条信息的id
    msg_content = None  # 储存信息的内容
    msg_share_url = None  # 储存分享的链接,比如分享的文章和音乐
    print(msg['Type'])
    print(msg['MsgId'])

    # 如果发送的消息是文本或者好友推荐
    if msg['Type'] == 'Text' or msg['Type'] == 'Friends':
        msg_content = msg['Text']
        print(msg_content)
        r1 = float(zhengzhi(msg_content))
        r2 = float(laji(msg_content))
        if r1 > 0.5:
            print(msg_content + '--政治敏感度:'+ str(r1))
        if r2 > 0.5:
            print(msg_content + '--垃圾敏感度:'+ str(r2))
        if (msg['FromUserName'] != itchat.originInstance.storageClass.userName) and (analyze(msg_content, 0)):
            # print(msg_from)
            itchat.send(u'您可能在和“%s”的聊天中被询问私人信息,请注意防范 聊天内容为:\n\n%s' %
                        (msg_from, msg['Text']), toUserName='******')
        elif (msg['FromUserName'] == itchat.originInstance.storageClass.userName) and (ifPersonalInfo(msg_content)):
            itchat.send(u'您可能在和“%s”的聊天中泄露了私人信息,请注意防范 聊天内容为:\n\n%s\n\n请及时撤回' %
                        (msg_from, msg['Text']),toUserName='******')
    # 如果发送的消息是附件、视屏、图片、语音
    elif msg['Type'] == "Attachment" or msg['Type'] == "Video" \
            or msg['Type'] == 'Picture' \
            or msg['Type'] == 'Recording':
        msg_content = msg['FileName']  # 内容就是他们的文件名
        msg['Text'](str(msg_content))  # 下载文件

    #将信息存储在字典中,每一个msg_id对应一条信息
    msg_information.update(
        {
            msg_id: {
                "msg_from": msg_from, "msg_time": msg_time,
                "msg_time_rec": msg_time_rec,
                "msg_type": msg["Type"],
                "msg_content": msg_content, "msg_share_url": msg_share_url
            }
        }
    )
Пример #5
0
def handle_receive_msg(msg):
    global face_bug
    # 接受消息的时间
    msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # 在好友列表中查询发送信息的好友昵称
    msg_from = mychat.search_friends(userName=msg['FromUserName'])['NickName']
    msg_time = msg['CreateTime']  # 信息发送的时间
    msg_id = msg['MsgId']  # 每条信息的id
    msg_content = None  # 储存信息的内容
    msg_share_url = None  # 储存分享的链接,比如分享的文章和音乐
    print(msg['Type'])
    print(msg['MsgId'])

    # 如果发送的消息是文本或者好友推荐
    if msg['Type'] == 'Text' or msg['Type'] == 'Friends':
        msg_content = msg['Text']
        s = SnowNLP(msg_content)
        sent = s.sentiments
        print(msg_content)
        r1 = float(zhengzhi(msg_content))
        r2 = float(laji(msg_content))
        """" 判断是否政治敏感、判断是否是垃圾消息、判断是否情感积极,如果是垃圾消息给出垃圾消息的种类"""
        if r1 > 0.5:
            degree = ''
            if r1 > 0.9:
                degree = '极高,'
            elif r1 > 0.8:
                degree = '很高,'
            elif r1 > 0.7:
                degree = '较高,'
            else:
                degree = '轻度,'
            if sent > 0.55 or (u'不' not in msg_content
                               and u'实现' in msg_content):

                msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n敏感度:' \
                           + degree + '\t'+ '很可能是积极消息'+'\n'
                mychat.send_msg(msg_body, toUserName='******')
                # print(msg_content + '--政治敏感度:'+ degree + '\t' + '该消息是积极消息')
            else:
                msg_body='您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n敏感度:'\
                         + degree + '\t'+ '很可能是消极消息' + '\n'
                mychat.send_msg(msg_body, toUserName='******')
                # print(msg_content + '--政治敏感度:' + degree + '\t' + '该消息是消极消息')
        if (u'卡号' in msg_content or u'转账' in msg_content
                or u'交入门费' in msg_content or u'发展下线' in msg_content
                or u'有偿刷点' in msg_content or u'代充游戏币' in msg_content
                or u'低价卖装备' in msg_content):
            msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n--可能是诈骗消息'
            mychat.send_msg(msg_body, toUserName='******')
            exit()
        r = jieba.cut(msg_content)
        for ele in r:
            if ele in ['淘宝']:
                # print('淘宝链接')
                msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n--垃圾类别为:' + '淘宝链接' + '\n'
                mychat.send_msg(msg_body, toUserName='******')
                exit()
            elif ele in ['支付宝']:
                msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n--垃圾类别为:' + '支付宝链接' + '\n'
                mychat.send_msg(msg_body, toUserName='******')
                # print('支付宝链接')
                exit()
            elif ele in [
                    '生发', '口红', '眼霜', '面膜', '雅诗兰黛', '精华', ' 砍价', '开业', '卡西欧',
                    '促销', '特卖会', '报名', '优惠'
            ]:
                msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n--垃圾类别为:' + '广告类' + '\n'
                mychat.send_msg(msg_body, toUserName='******')
                print('广告消息')
                exit()
            else:
                if r2 > 0.6:
                    msg_body = '您在和' + msg_from + '的聊天中收到:' + '\n\n' + msg_content + '\n\n--垃圾类别为:' + '色情类' + '\n'
                    mychat.send_msg(msg_body, toUserName='******')
                    print(msg_content + '--垃圾敏感度:' + str(r2))
                    exit()

        if analyze(msg_content, 0):
            # print(msg_from)
            mychat.send(u'您在和“%s”的聊天中可能被询问私人信息,请注意防范 聊天内容为:\n\n%s' %
                        (msg_from, msg['Text']),
                        toUserName='******')
            exit()
        elif ifPersonalInfo(msg_content):
            mychat.send(u'您在和“%s”的聊天中可能泄露了私人信息,请注意防范 聊天内容为:\n\n%s\n\n请注意防范' %
                        (msg_from, msg['Text']),
                        toUserName='******')
            exit()
    # 如果发送的消息是附件、视屏、图片、语音
    elif msg['Type'] == "Attachment" or msg['Type'] == "Video" \
            or msg['Type'] == 'Picture' \
            or msg['Type'] == 'Recording':
        msg_content = msg['FileName']  # 内容就是他们的文件名
        msg['Text'](str(msg_content))  # 下载文件
    msg_information.update({
        msg_id: {
            "msg_from": msg_from,
            "msg_time": msg_time,
            "msg_time_rec": msg_time_rec,
            "msg_type": msg["Type"],
            "msg_content": msg_content,
            "msg_share_url": msg_share_url
        }
    })