Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

56 lines
2.3KB

  1. from bridge.context import Context, ContextType
  2. from bridge.reply import Reply, ReplyType
  3. from common.log import logger
  4. from linkai import LinkAIClient, PushMsg
  5. from config import conf, pconf, plugin_config
  6. from plugins import PluginManager
  7. chat_client: LinkAIClient
  8. class ChatClient(LinkAIClient):
  9. def __init__(self, api_key, host, channel):
  10. super().__init__(api_key, host)
  11. self.channel = channel
  12. self.client_type = channel.channel_type
  13. def on_message(self, push_msg: PushMsg):
  14. session_id = push_msg.session_id
  15. msg_content = push_msg.msg_content
  16. logger.info(f"receive msg push, session_id={session_id}, msg_content={msg_content}")
  17. context = Context()
  18. context.type = ContextType.TEXT
  19. context["receiver"] = session_id
  20. context["isgroup"] = push_msg.is_group
  21. self.channel.send(Reply(ReplyType.TEXT, content=msg_content), context)
  22. def on_config(self, config: dict):
  23. if not self.client_id:
  24. return
  25. logger.info(f"从控制台加载配置: {config}")
  26. local_config = conf()
  27. for key in local_config.keys():
  28. if config.get(key) is not None:
  29. local_config[key] = config.get(key)
  30. if config.get("reply_voice_mode"):
  31. if config.get("reply_voice_mode") == "voice_reply_voice":
  32. local_config["voice_reply_voice"] = True
  33. elif config.get("reply_voice_mode") == "always_reply_voice":
  34. local_config["always_reply_voice"] = True
  35. # if config.get("admin_password") and plugin_config["Godcmd"]:
  36. # plugin_config["Godcmd"]["password"] = config.get("admin_password")
  37. # PluginManager().instances["Godcmd"].reload()
  38. # if config.get("group_app_map") and pconf("linkai"):
  39. # local_group_map = {}
  40. # for mapping in config.get("group_app_map"):
  41. # local_group_map[mapping.get("group_name")] = mapping.get("app_code")
  42. # pconf("linkai")["group_app_map"] = local_group_map
  43. # PluginManager().instances["linkai"].reload()
  44. def start(channel):
  45. global chat_client
  46. chat_client = ChatClient(api_key=conf().get("linkai_api_key"),
  47. host="link-ai.chat", channel=channel)
  48. chat_client.start()