<commit_before># ! /usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import unicode_literals

import json
import itchat
import requests
import platform
# 登录和初始化


def main():
    itchat.auto_login(enableCmdQR=True + (platform.system() == 'Linux'))
    itchat.run()


def checkapi():
    try:
        inf = open('api.inf', 'r')
        api = inf.readline().replace('\n','')
        inf.close()
    except:
        print('请前往 http://www.tuling123.com 申请机器人API，并填写在相同目录下的“api.inf”文件首行！')
        input()

# 图灵机器人回复部分


def talk(info, userid=None):
    url = 'http://www.tuling123.com/openapi/api'
    inf = open('api.inf', 'r')
    api = inf.readline()
    inf.close()
    param = json.dumps(
        {"key": api, "info": info, "userid": userid})
    callback = requests.post(url, data=param)
    result = eval(callback.text)
    code = result['code']
    if code == 100000:
        recontent = result['text']
    elif code == 200000:
        recontent = result['text'] + result['url']
    elif code == 302000:
        recontent = result['text'] + result['list'][0]['info'] + \
            result['list'][0]['detailurl']
    elif code == 308000:
        recontent = result['text'] + result['list'][0]['info'] + \
            result['list'][0]['detailurl']
    else:
        recontent = '这货还没学会怎么回复这句话'
    return recontent

# userid通过用户名的md5产生


def md5(str):
    import hashlib
    md = hashlib.md5()
    md.update(str.encode('utf-8'))
    return md.hexdigest()

# 注册微信消息


@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s悄悄对您说：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.MAP)
def map_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您分享了地点：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.CARD)
def card_reply(msg):
    reply = '谢谢你的推荐，我们会成为好朋友的！'
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您推荐了%s' % (NickName, msg['Text']['NickName']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.NOTE)
def note_reply(msg):
    print(msg)


@itchat.msg_register(itchat.content.SHARING)
def sharing_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您分享了链接：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.PICTURE)
def pic_reply(msg):
    msg['Text']('./images/' + msg['FileName'])
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s给您发送了一个表情/图片，已经存入images目录，文件名：%s' % (NickName, msg['FileName']))
    print('AI帮您回复%s默认表情default.gif' % NickName)
    print('------------------------------------------------------------------------------')
    return '@img@./images/default.gif'


@itchat.msg_register(itchat.content.RECORDING)
def rec_reply(msg):
    # 是否开启语音识别，需要安装ffmpeg和pydub
    enable_voice_rec = True
    msg['Text']('./records/' + msg['FileName'])
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])

    if enable_voice_rec:
        msg['Text']('./records/' + msg['FileName'])
        from beta import wav2text
        wav2text.transcode('./records/' + msg['FileName'])
        filename = msg['FileName'].replace('mp3','wav')
        text = wav2text.wav_to_text('./records/' + filename)
        reply = talk(text, md5(msg['FromUserName']))       
        print('------------------------------------------------------------------------------')
        print('%s给您发送了一条语音，已经存入records目录，文件名：%s' % (NickName, msg['FileName']))
        print('智能识别该消息内容为：%s' % text)
        print('AI帮您回复%s：%s' % (NickName, reply))
        print('------------------------------------------------------------------------------')
        return reply
    else:
        print('------------------------------------------------------------------------------')
        print('%s给您发送了一条语音，已经存入records目录，文件名：%s' % (NickName, msg['FileName']))<commit_msg>Change the default setting<commit_after># ! /usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import unicode_literals

import json
import itchat
import requests
import platform
# 登录和初始化


def main():
    itchat.auto_login(enableCmdQR=True + (platform.system() == 'Linux'))
    itchat.run()


def checkapi():
    try:
        inf = open('api.inf', 'r')
        api = inf.readline().replace('\n','')
        inf.close()
    except:
        print('请前往 http://www.tuling123.com 申请机器人API，并填写在相同目录下的“api.inf”文件首行！')
        input()

# 图灵机器人回复部分


def talk(info, userid=None):
    url = 'http://www.tuling123.com/openapi/api'
    inf = open('api.inf', 'r')
    api = inf.readline()
    inf.close()
    param = json.dumps(
        {"key": api, "info": info, "userid": userid})
    callback = requests.post(url, data=param)
    result = eval(callback.text)
    code = result['code']
    if code == 100000:
        recontent = result['text']
    elif code == 200000:
        recontent = result['text'] + result['url']
    elif code == 302000:
        recontent = result['text'] + result['list'][0]['info'] + \
            result['list'][0]['detailurl']
    elif code == 308000:
        recontent = result['text'] + result['list'][0]['info'] + \
            result['list'][0]['detailurl']
    else:
        recontent = '这货还没学会怎么回复这句话'
    return recontent

# userid通过用户名的md5产生


def md5(str):
    import hashlib
    md = hashlib.md5()
    md.update(str.encode('utf-8'))
    return md.hexdigest()

# 注册微信消息


@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s悄悄对您说：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.MAP)
def map_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您分享了地点：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.CARD)
def card_reply(msg):
    reply = '谢谢你的推荐，我们会成为好朋友的！'
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您推荐了%s' % (NickName, msg['Text']['NickName']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.NOTE)
def note_reply(msg):
    print(msg)


@itchat.msg_register(itchat.content.SHARING)
def sharing_reply(msg):
    reply = talk(msg['Text'], md5(msg['FromUserName']))
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s向您分享了链接：%s' % (NickName, msg['Text']))
    print('AI帮您回复%s：%s' % (NickName, reply))
    print('------------------------------------------------------------------------------')
    return reply


@itchat.msg_register(itchat.content.PICTURE)
def pic_reply(msg):
    msg['Text']('./images/' + msg['FileName'])
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])
    print('------------------------------------------------------------------------------')
    print('%s给您发送了一个表情/图片，已经存入images目录，文件名：%s' % (NickName, msg['FileName']))
    print('AI帮您回复%s默认表情default.gif' % NickName)
    print('------------------------------------------------------------------------------')
    return '@img@./images/default.gif'


@itchat.msg_register(itchat.content.RECORDING)
def rec_reply(msg):
    # 是否开启语音识别，需要安装ffmpeg和pydub
    enable_voice_rec = False
    msg['Text']('./records/' + msg['FileName'])
    User = itchat.search_friends(userName=msg['FromUserName'])
    if User['RemarkName'] == '':
        NickName = User['NickName']
    else:
        NickName = '%s(%s)' % (User['NickName'], User['RemarkName'])

    if enable_voice_rec:
        msg['Text']('./records/' + msg['FileName'])
        from beta import wav2text
        wav2text.transcode('./records/' + msg['FileName'])
        filename = msg['FileName'].replace('mp3','wav')
        text = wav2text.wav_to_text('./records/' + filename)
        reply = talk(text, md5(msg['FromUserName']))       
        print('------------------------------------------------------------------------------')
        print('%s给您发送了一条语音，已经存入records目录，文件名：%s' % (NickName, msg['FileName']))
        print('智能识别该消息内容为：%s' % text)
        print('AI帮您回复%s：%s' % (NickName, reply))
        print('------------------------------------------------------------------------------')
        return reply
    else:
        print('------------------------------------------------------------------------------')
        print('%s给您发送了一条语音，已经存入records目录，文件名：%s' % (NickName, msg['FileName']))
{'fraction_non_alphanumeric': 0.32722772277227724, 'fraction_numerical': 0.0077557755775577554, 'mean_word_length': 1.8070866141732282, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2908200', 'n_tokens_mistral': 3924, 'n_tokens_neox': 3955, 'n_words': 592}