Example #1
0
def create_mappings():
    timestamp = int(time.time())
    current_date = ts2datetime(timestamp)
    qq_number = 123  # 无效
    group_message_mappings(qq_number, current_date)
    index_name = flow_text_index_name_pre + current_date
    weibo_xnr_flow_text_mappings(index_name)
Example #2
0
def sendMessage(bot, group, content):
    bot.Update('group')
    gl = bot.List('group', group)
    print gl[0].qq
    if gl:
        qq_item = {
            'xnr_qq_number': bot.session.qq,
            'xnr_nickname': bot.session.nick,
            'timestamp': int(round(time.time())),
            'speaker_qq_number': bot.session.qq,
            'text': content,
            'speaker_nickname': bot.session.nick,
            'qq_group_number': gl[0].qq,
            'qq_group_nickname': group
        }
        qq_json = json.dumps(qq_item)
        print qq_json

        conMD5 = string_md5(content)

        nowDate = datetime.datetime.now().strftime('%Y-%m-%d')
        index_name = sent_group_message_index_name_pre + str(nowDate)
        index_id = bot.conf.qq + '_' + gl[0].qq + '_' + str(
            int(round(time.time()))) + '_' + conMD5
        # 将发送的信息存入es
        if not es.indices.exists(index=index_name):
            group_message_mappings(bot.session.qq, nowDate)

        es.index(index=index_name,
                 doc_type=group_message_index_type,
                 id=index_id,
                 body=qq_item)

        bot.SendTo(gl[0], content)
        return 1
    else:
        print 'you no own this group', group
        return 0
Example #3
0
def onQQMessage(bot, contact, member, content):
    # 当收到 QQ 消息时被调用
    # bot     : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节
    # contact : QContact 对象,消息的发送者
    # member  : QContact 对象,仅当本消息为 群或讨论组 消息时有效,代表实际发消息的成员
    # content : str 对象,消息内容
    INFO('test groups %s', bot.List('group'))
    INFO('bot.conf %s', bot.conf)
    print '========================================================================recive qq message start'
    print 'contact.============.', contact
    print contact.qq, contact.nick
    print '-----------------------------------------------------------------------------'

    if contact.ctype == 'group':
        INFO('群的 QQ.. %s', contact.qq)  # #NULL
        INFO('群的昵称.. %s', contact.nick)  # 嘿哼哈
        INFO('成员的 QQ.. %s', member.qq)  # #NULL
        INFO('成员的昵称.. %s', member.nick)  # /石沫沫
        INFO('最后发言时间.. %s', member.last_speak_time)  # -1
        INFO('消息.. %s', content)  # test内容

        last_speak_time = int(time.time())
        print 'last_speak_time..', last_speak_time
        if content == '':
            INFO('您发了一张图片或假消息... %s', content)
        else:
            sen_value, sen_words = sensitive_check(
                content
            )  # sen_words包含sensitive_words_string:北京&达赖和sensitive_words_dict
            if sen_value != 0:
                sen_flag = 1  #该条信息是敏感信息
            else:
                sen_flag = 0
            # qq_item = {
            #     'xnr_qq_number': bot.session.qq,
            #     'xnr_nickname': bot.session.nick,
            #     'timestamp': member.last_speak_time,
            #     'speaker_qq_number': member.qq,
            #     'text': content,
            #     'sensitive_flag':sen_flag,
            #     'sensitive_value': sen_value,
            #     'sensitive_words_string': sen_words['sensitive_words_string'],
            #     'speaker_nickname': member.nick,
            #     'qq_group_number': contact.qq,
            #     'qq_group_nickname': contact.nick
            # }
            qq_item = {
                'xnr_qq_number': bot.session.qq,
                'xnr_nickname': bot.session.nick,
                'timestamp': last_speak_time,
                'speaker_qq_number': '',
                'text': content,
                'sensitive_flag': sen_flag,
                'sensitive_value': sen_value,
                'sensitive_words_string': sen_words['sensitive_words_string'],
                'speaker_nickname': member.nick,
                'qq_group_number': '',
                'qq_group_nickname': contact.nick
            }
            qq_json = json.dumps(qq_item)
            print 'qq_json=====:', qq_json
            # 判断该qq群是否在redis的群set中
            #qq_number  = qq_item['xnr_qq_number']
            #qq_group_number = qq_item['qq_group_number']

            # r_qq_group_set = r_qq_group_set_pre + qq_number
            # qq_group_set = r.smembers(r_qq_group_set)
            #test
            #qq_group_set = set(['531811289'])

            #if qq_group_number in qq_group_set:

            conMD5 = string_md5(content)

            nowDate = datetime.datetime.now().strftime('%Y-%m-%d')
            index_name = group_message_index_name_pre + str(nowDate)
            print 'INDEX NAME-=-------------=-=-'
            print index_name
            #index_id = bot.conf.qq + '_' + contact.qq + '_' + str(member.last_speak_time) + '_' + conMD5
            # 让系统随机分配 _id
            if not es.indices.exists(index=index_name):
                print 'get mapping'
                print group_message_mappings(bot.session.qq, nowDate)
            print 'qq_item.....', qq_item
            print es.index(index=index_name,
                           doc_type=group_message_index_type,
                           body=qq_item)