模拟微软小冰自动回复


源代码

import itchat
from itchat.content import TEXT, PICTURE, RECORDING
who_send=None

@itchat.msg_register(TEXT, isFriendChat=True)
def send_ice(msg):
    global who_send
    msg_text = msg['Text']
    who_send = msg['FromUserName']
    if who_send != GF:
        itchat.send(msg_text, xiaoice)

@itchat.msg_register(PICTURE, isFriendChat=True)
def send_ice(msg):
    global who_send
    msg['Text'](msg['FileName'])
    who_send = msg['FromUserName']
    if who_send != GF:
        itchat.send('@img@%s' % msg['FileName'], xiaoice)

@itchat.msg_register(RECORDING, isFriendChat=True)
def send_ice(msg):
    global who_send
    msg['Text'](msg['FileName'])
    who_send = msg['FromUserName']
    if who_send != GF:
        itchat.send('@fil@%s' % msg['FileName'], xiaoice)

@itchat.msg_register(TEXT, isGroupChat=True)
def send_ice(msg):
    global who_send
    msg_text = msg['Text']
    who_send = msg['FromUserName']
    if who_send == qun_301:
        itchat.send(msg_text, xiaoice)

@itchat.msg_register(PICTURE, isGroupChat=True)
def send_ice(msg):
    global who_send
    msg['Text'](msg['FileName'])
    who_send = msg['FromUserName']
    if who_send == qun_301:
        itchat.send('@img@%s' % msg['FileName'], xiaoice)

@itchat.msg_register(TEXT, isMpChat=True)
def get_ice(msg):
    if who_send != GF:
        ice_msg = msg['Text']
        itchat.send('微软小冰自动回复:' + ice_msg, who_send)

@itchat.msg_register(PICTURE, isMpChat=True)
def get_ice(msg):
    if who_send != GF:
        msg['Text'](msg['FileName'])
        # ice_msg = msg['Text']
        itchat.send('@img@%s' % msg['FileName'], who_send)

@itchat.msg_register(RECORDING, isMpChat=True)
def get_ice(msg):
    if who_send != GF:
        msg['Text'](msg['FileName'])
        # ice_msg = msg['Text']
        itchat.send('@fil@%s' % msg['FileName'], who_send)


itchat.auto_login()
xiaoice = itchat.search_mps(name='小冰')[0]['UserName']
GF = itchat.search_friends(name='Spring Day')[0]['UserName']
qun_301 = itchat.search_chatrooms(name='爸爸带你们上铂金')[0]['UserName']
itchat.run()

文章作者: lovelyfrog
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 lovelyfrog !
 上一篇
结合血液动力学参数分析脑梗发病几率 结合血液动力学参数分析脑梗发病几率
2017曦源项目 1.概述 我结合了病人的血液动力学参数,依据采集的333个数据(实际有效采用302个数据)建立了一个预测病人脑埂患病与否的模型(采用python的tensorflow包) 2.对采集数据的清洗 一共采集了333例病患的
2017-09-08
下一篇 
pillow入门 pillow入门
pillow入门 import numpy import PIL.Image as Image import PIL.ImageFont as ImageFont import PIL.ImageDraw as ImageDraw imp
2017-08-24
  目录