__init__.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from .core import Core
  2. from .config import VERSION, ASYNC_COMPONENTS
  3. from .log import set_logging
  4. if ASYNC_COMPONENTS:
  5. from .async_components import load_components
  6. else:
  7. from .components import load_components
  8. __version__ = VERSION
  9. instanceList = []
  10. def load_async_itchat() -> Core:
  11. """load async-based itchat instance
  12. Returns:
  13. Core: the abstract interface of itchat
  14. """
  15. from .async_components import load_components
  16. load_components(Core)
  17. return Core()
  18. def load_sync_itchat() -> Core:
  19. """load sync-based itchat instance
  20. Returns:
  21. Core: the abstract interface of itchat
  22. """
  23. from .components import load_components
  24. load_components(Core)
  25. return Core()
  26. if ASYNC_COMPONENTS:
  27. instance = load_async_itchat()
  28. else:
  29. instance = load_sync_itchat()
  30. instanceList = [instance]
  31. # I really want to use sys.modules[__name__] = originInstance
  32. # but it makes auto-fill a real mess, so forgive me for my following **
  33. # actually it toke me less than 30 seconds, god bless Uganda
  34. # components.login
  35. login = instance.login
  36. get_QRuuid = instance.get_QRuuid
  37. get_QR = instance.get_QR
  38. check_login = instance.check_login
  39. web_init = instance.web_init
  40. show_mobile_login = instance.show_mobile_login
  41. start_receiving = instance.start_receiving
  42. get_msg = instance.get_msg
  43. logout = instance.logout
  44. # components.contact
  45. update_chatroom = instance.update_chatroom
  46. update_friend = instance.update_friend
  47. get_contact = instance.get_contact
  48. get_friends = instance.get_friends
  49. get_chatrooms = instance.get_chatrooms
  50. get_mps = instance.get_mps
  51. set_alias = instance.set_alias
  52. set_pinned = instance.set_pinned
  53. accept_friend = instance.accept_friend
  54. get_head_img = instance.get_head_img
  55. create_chatroom = instance.create_chatroom
  56. set_chatroom_name = instance.set_chatroom_name
  57. delete_member_from_chatroom = instance.delete_member_from_chatroom
  58. add_member_into_chatroom = instance.add_member_into_chatroom
  59. # components.messages
  60. send_raw_msg = instance.send_raw_msg
  61. send_msg = instance.send_msg
  62. upload_file = instance.upload_file
  63. send_file = instance.send_file
  64. send_image = instance.send_image
  65. send_video = instance.send_video
  66. send = instance.send
  67. revoke = instance.revoke
  68. # components.hotreload
  69. dump_login_status = instance.dump_login_status
  70. load_login_status = instance.load_login_status
  71. # components.register
  72. auto_login = instance.auto_login
  73. configured_reply = instance.configured_reply
  74. msg_register = instance.msg_register
  75. run = instance.run
  76. # other functions
  77. search_friends = instance.search_friends
  78. search_chatrooms = instance.search_chatrooms
  79. search_mps = instance.search_mps
  80. set_logging = set_logging