You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
преди 2 години
преди 2 години
12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. wechat channel
  3. """
  4. import itchat
  5. import json
  6. from itchat.content import *
  7. from channel.channel import Channel
  8. @itchat.msg_register([TEXT])
  9. def handler_receive_msg(msg):
  10. WechatChannel().handle(msg)
  11. class WechatChannel(Channel):
  12. def __init__(self):
  13. pass
  14. def startup(self):
  15. # login by scan QRCode
  16. itchat.auto_login()
  17. # start message listener
  18. itchat.run()
  19. def handle(self, msg):
  20. print("handle: ", msg)
  21. print(json.dumps(msg, ensure_ascii=False))
  22. from_user_id = msg['FromUserName']
  23. other_user_id = msg['User']['UserName']
  24. if from_user_id == other_user_id:
  25. self.send(super().build_reply_content(msg['Text']), from_user_id)
  26. def send(self, msg, receiver):
  27. # time.sleep(random.randint(1, 3))
  28. print(msg, receiver)
  29. itchat.send(msg + " [bot]", toUserName=receiver)