主要更改
- 更新用户、群、公众号的oop操作
- 在注册方法的返回值中增加User键值,存放发送者的类
- 将注册方法的返回值改为可以通过__getattr__访问
- 另,所有新操作不影响旧的字典的使用方式
oop操作
import itchat
user = itchat.get_friends()[0]
user.send('hi')
同样,群和公众号也是这样访问。
注册方法返回值增加User
import itchat
@itchat.msg_register(itchat.content.TEXT)
def _(msg):
msg['User'].send('hi')
itchat.auto_login(True)
itchat.run()
返回值通过__getattr__访问
import itchat
@itchat.msg_register(itchat.content.TEXT)
def _(msg):
msg.user.send('hi')
itchat.auto_login(True)
itchat.run()
发送文件类
import itchat
itchat.auto_login(True)
with open('t.pdf', 'rb') as f:
r = itchat.send_file('test.pdf', 'filehelper', file_=f)
# equals to:
# r = itchat.send_file('t.pdf', 'filehelper')
print(r)
with open('t.png', 'rb') as f:
r = itchat.send_image(f, 'filehelper')
# equals to:
# r = itchat.send_image('t.png', 'filehelper')
print(r)
with open('t.mp4', 'rb') as f:
r = itchat.send_video(f, 'filehelper')
# equals to:
# r = itchat.send_video('t.mp4', 'filehelper')
print(r)
itchat.run()