Ejemplo n.º 1
0
def send_alarm_msg():
    """ 发送定时提醒 """
    print('\n启动定时自动提醒...')
    conf = get_yaml()
    for gf in conf.get('girlfriend_infos'):
        dictum = get_dictum_info(gf.get('dictum_channel'))
        weather = get_weather_info(gf.get('city_name'))
        diff_time = get_diff_time(gf.get('start_date'))
        sweet_words = gf.get('sweet_words')
        send_msg = '\n'.join(x for x in [weather, dictum, diff_time, sweet_words] if x)
        print(send_msg)

        if not send_msg or not is_online(): continue
        # 给微信好友发信息
        wechat_name = gf.get('wechat_name')
        if wechat_name:
            if wechat_name.lower() in FILEHELPER_MARK:
                itchat.send(send_msg, toUserName=FILEHELPER)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(wechat_name, send_msg))
            else:
                wechat_users = itchat.search_friends(name=wechat_name)
                if not wechat_users: continue
                wechat_users[0].send(send_msg)
                print('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(wechat_name, send_msg))

        # 给群聊里发信息
        group_name = gf.get('group_name')
        if group_name:
            group = get_group(group_name)
            if group:
                group.send(send_msg)
                print('定时给群聊『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(group_name, send_msg))

    print('自动提醒消息发送完成...\n')
Ejemplo n.º 2
0
def text_reply(msg):
    """ 监听用户消息,用于自动回复 """
    try:
        # print_logging(json.dumps(msg, ensure_ascii=False))

        uuid = msg.fromUserName  # 获取发送者的用户id
        # 如果用户id是自动回复列表的人员或者文件传输助手,则进行下一步的操作
        if uuid in reply_user_name_uuid_list or msg['ToUserName'] == FILEHELPER:
            receive_text = msg.text  # 好友发送来的消息内容
            # 通过图灵 api 获取要回复的内容。
            if receive_text.find('情话') >= 0:
                reply_text = get_dictum_info(3)
                print('情话' + reply_text)
            elif receive_text.find('笑话') >= 0:
                reply_text = get_dictum_info(5)
                print('笑话' + reply_text)
            elif receive_text.find('格言') >= 0:
                reply_text = get_dictum_info(2)
                print('格言' + reply_text)
            # else:
            #     reply_text = get_bot_info(receive_text, uuid)
            time.sleep(1)  # 休眠一秒,保安全,想更快的,可以直接用。
            if reply_text:  # 如内容不为空,回复消息
                if msg['ToUserName'] == FILEHELPER:
                    reply_text = '机器人自动回复:{}'.format(reply_text)
                    itchat.send(reply_text, toUserName=FILEHELPER)
                    print_logging('\n我发出信息:{}\n回复{}:'.format(
                        receive_text, reply_text))
                else:
                    msg.user.send(reply_text)
                    print_logging('\n{}发来信息:{}\n回复{}:{}'.format(
                        msg.user.nickName, receive_text, msg.user.nickName,
                        reply_text))
            else:
                if msg['ToUserName'] == FILEHELPER:
                    print_logging('我发来信息:{} 自动回复失败'.format(receive_text))
                else:
                    print_logging('{}发来信息:{} 自动回复失败'.format(
                        msg.user.nickName, receive_text))
    except Exception as e:
        print_logging(str(e))
Ejemplo n.º 3
0
def hook_up_girls(is_random=True):
    """ 自动勾搭完成开始 """
    print_logging('\n自动勾搭开始...')
    conf = get_yaml()
    for gf in conf.get('hookup_girls'):
        # dictum = get_dictum_info(gf.get('dictum_channel'))
        if is_random:
            dictum = get_dictum_info(gf.get('dictum_channel'))
        else:
            dictum = get_dictum_info(random.randint(2, 5))
        sweet_words = gf.get('sweet_words')
        send_msg = '\n'.join(x for x in [dictum, sweet_words] if x)
        # print_logging(send_msg)

        if not send_msg or not is_online(): continue
        # 给微信好友发信息
        wechat_name = gf.get('wechat_name')
        if wechat_name:
            if wechat_name.lower() in FILEHELPER_MARK:
                itchat.send(send_msg, toUserName=FILEHELPER)
                print_logging('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))
            else:
                wechat_users = itchat.search_friends(name=wechat_name)
                if not wechat_users: continue
                wechat_users[0].send(send_msg)
                print_logging('定时给『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
                    wechat_name, send_msg))

        # 给群聊里发信息
        group_name = gf.get('group_name')
        if not group_name: continue
        groups = itchat.search_chatrooms(name=group_name)
        if not groups: continue
        groups[0].send(send_msg)
        print_logging('定时给群聊『{}』发送的内容是:\n{}\n发送成功...\n\n'.format(
            group_name, send_msg))

    print_logging('自动勾搭完成.\n')
Ejemplo n.º 4
0
def get_alarm_msg():
    conf = get_yaml()
    for gf in conf['girlfriend_infos']:
        dictum = get_dictum_info()
        weather = get_weather_info(gf['city_name'])
        diff_time = get_diff_time(gf['start_date'])
        sweet_words = gf['sweet_words']
        send_msg = '\n'.join(
            x for x in [dictum, weather, diff_time, sweet_words] if x)
        # print(send_msg)
        if send_msg and is_online():
            authors = itchat.search_friends(nickName=gf['wechat_name'])
            if authors:
                authors[0].send(send_msg)
                print('\n定时给『{}』发送的内容是:\n{}\n发送成功...\n'.format(
                    gf['wechat_name'], send_msg))
Ejemplo n.º 5
0
def get_alarm_msg():
    """ 定时提醒内容 """
    conf = get_yaml()
    for gf in conf.get('girlfriend_infos'):
        dictum = get_dictum_info(gf.get('dictum_channel'))
        weather = get_weather_info(gf.get('city_name'))
        diff_time = get_diff_time(gf.get('start_date'))
        sweet_words = gf.get('sweet_words')
        send_msg = '\n'.join(x for x in [dictum, weather, diff_time, sweet_words] if x)
        print(send_msg)
        if send_msg and is_online():
            wechat_name = gf.get('wechat_name')
            authors = itchat.search_friends(nickName=wechat_name)
            if authors:
                authors[0].send(send_msg)
                print('\n定时给『{}』发送的内容是:\n{}\n发送成功...\n'.format(wechat_name, send_msg))
            else:
                print('定时提醒发送失败,微信名 {} 失效。'.format(wechat_name))