Exemplo n.º 1
0
 def wechat_run_as_thread(self):
     # todo kill itchat
     picDir = str(codelab_adapter_dir / "servers" /
                  "adapter_QR.png")  # fix 打包软件打开本地图片的权限问题
     statusStorageDir = str(codelab_adapter_dir / "servers" /
                            'adapter_itchat.pkl')
     itchat.msg_register([TEXT])(self.text_reply)
     itchat.msg_register(TEXT, isGroupChat=True)(self.group_text_reply)
     itchat.auto_login(True,
                       picDir=picDir,
                       statusStorageDir=statusStorageDir)
     itchat.run(True)  # todo 提示有些账号无法登录
Exemplo n.º 2
0
 def __init__(self):
     self.debug = False
     self.silent = False
     self.response_sig = threading.Semaphore(1)
     self.replying = False
     self.collection = []
     self.wait_time = load_conf.load_wx_wait()
     self.s_for_wait = self.wait_time
     self.wait_unit = load_conf.load_wx_wait_unit()
     self.batch_size = load_conf.load_wx_batch()
     # trick, but useful
     self.collection_func = lambda msg: self.text_collection(msg)
     itchat.msg_register(itchat.content.TEXT)(self.collection_func)
Exemplo n.º 3
0
 def bind(self):
     all_type_list = [i for i in MessageType.__members__]
     itchat.msg_register(all_type_list,
                         isFriendChat=True)(self._handle_friends)
     itchat.msg_register(all_type_list,
                         isGroupChat=True)(self._handle_group)
     itchat.msg_register(all_type_list, isMpChat=True)(self._handle_mp)
Exemplo n.º 4
0
def get_response(msg):
    apiUrl = 'http://www.tuling123.com/openapi/api'
    data = {
        'key': KEY,
        'info': msg,
        'userid': 'Monkey',
    }
    while True:
        try:
            r = requests.post(apiUrl, data=data).json()
            return r.get('text')
        except:
            return


# 注册方法
itchat.msg_register(itchat.content.TEXT)


def tuling_reply(msg):
    # 为了保证在图灵K出现问题的时候仍旧可以回复,这里设置一个默认回复
    defaultReply = 'I received: ' + msg['Text']
    # 如果图灵Key出现问题,那么reply将会是None
    reply = get_response(msg['Text'])
    # a or b的意思是,如果a有内容,那么返回a,否则返回b
    return reply or defaultReply


# 为了让修改程序不用多次扫码,使用热启动
itchat.auto_login(hotReload=True)
itchat.run()
Exemplo n.º 5
0
 def run(self):
     itchat.msg_register([TEXT], isGroupChat=True)(self.reply_chatroom_msg)
     itchat.msg_register([TEXT])(self.reply_member_msg)
     itchat.run()
Exemplo n.º 6
0
import itchat
from itchat.content import TEXT

text_handler = itchat.msg_register(TEXT)


def login(cb):
    itchat.auto_login(exitCallback=cb)


run = itchat.run


def send_msg(msg, name):
    itchat.send_msg(msg, toUserName=name)


def send_img(path, name):
    itchat.send_image(path, toUserName=name)

Exemplo n.º 7
0
import itchat


def text_collection(msg):
    pass


itchat.msg_register("text")(text_collection)

if __name__ == "__main__":
    itchat.auto_login()
    itchat.run()
Exemplo n.º 8
0
    # 加载音乐
    pygame.mixer_music.load('audio.mp3')
    # 播放,pygame播放音乐会失真
    pygame.mixer_music.play()
    # 播放5秒
    time.sleep(5)
    # 停止播放
    pygame.mixer_music.stop()


# 定义函数播放音乐,用os模块打开播放
def voice_play():
    os.system('audio.mp3')


# 接收所有好友信息,用一个装饰器来表示,收到的信息保存在'Note'内
itchat.msg_register('NOTE', isGroupChat=False)


def get_messages(note):
    print(note)
    if '收到红包' in note['TEXT']:
        print('快抢红包')
        # 下面三种提醒,可以随意一种使用
        box_pop()
        voice_pop()
        voice_play()


itchat.run()