forked from jerrypnz/ItChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
40 lines (32 loc) · 1.32 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
import itchat
def simple_reply():
@itchat.msg_register
def simple_reply(msg):
if msg.get('Type', '') == 'Text':
return 'I received: %s'%msg.get('Content', '')
itchat.run()
def complex_reply():
@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])
@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video'])
def download_files(msg):
fileDir = '%s%s'%(msg['Type'], int(time.time()))
msg['Text'](fileDir)
itchat.send('%s received'%msg['Type'], msg['FromUserName'])
itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName'])
@itchat.msg_register('Friends')
def add_friend(msg):
itchat.add_friend(**msg['Text'])
itchat.get_contract()
itchat.send('Nice to meet you!', msg['RecommendInfo']['UserName'])
@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
if msg['isAt']:
itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])
itchat.run()
if __name__ == '__main__':
itchat.auto_login()
# simple_reply()
complex_reply()