選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

67 行
1.7KB

  1. # encoding:utf-8
  2. import os
  3. import signal
  4. import sys
  5. from channel import channel_factory
  6. from common import const
  7. from config import load_config
  8. from plugins import *
  9. import threading
  10. def sigterm_handler_wrap(_signo):
  11. old_handler = signal.getsignal(_signo)
  12. def func(_signo, _stack_frame):
  13. logger.info("signal {} received, exiting...".format(_signo))
  14. conf().save_user_datas()
  15. if callable(old_handler): # check old_handler
  16. return old_handler(_signo, _stack_frame)
  17. sys.exit(0)
  18. signal.signal(_signo, func)
  19. def run():
  20. try:
  21. # load config
  22. load_config()
  23. # ctrl + c
  24. sigterm_handler_wrap(signal.SIGINT)
  25. # kill signal
  26. sigterm_handler_wrap(signal.SIGTERM)
  27. # create channel
  28. channel_name = conf().get("channel_type", "wx")
  29. if "--cmd" in sys.argv:
  30. channel_name = "terminal"
  31. if channel_name == "wxy":
  32. os.environ["WECHATY_LOG"] = "warn"
  33. # os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = '127.0.0.1:9001'
  34. channel = channel_factory.create_channel(channel_name)
  35. if channel_name in ["wx", "wxy", "terminal", "wechatmp", "wechatmp_service", "wechatcom_app", "wework", const.FEISHU]:
  36. PluginManager().load_plugins()
  37. if conf().get("use_linkai"):
  38. try:
  39. from common import linkai_client
  40. threading.Thread(target=linkai_client.start, args=(channel, )).start()
  41. except Exception as e:
  42. pass
  43. # startup channel
  44. channel.startup()
  45. except Exception as e:
  46. logger.error("App startup failed!")
  47. logger.exception(e)
  48. if __name__ == "__main__":
  49. run()