diff --git a/botoy/_internal/client.py b/botoy/_internal/client.py index 5ee5e23..a11c5a7 100644 --- a/botoy/_internal/client.py +++ b/botoy/_internal/client.py @@ -50,10 +50,14 @@ def __init__(self): self.loaded_plugins = False self.pool = WorkerPool() self.connection_urls = self._get_ws_urls(jconfig.url) + self._log_messages = False def set_url(self, url: str): self.connection_urls = self._get_ws_urls(url) + def log_messages(self): + self._log_messages = True + def load_plugins(self): """加载插件""" if self.loaded_plugins: @@ -116,7 +120,10 @@ async def _packet_handler(self, pkt, _available_names: Optional[List[str]] = Non # 当前的实现,副作用:增加一项要求: 接收函数有 name 并且 name 唯一 # TODO: 在mark_recv中处理好name # 由botoy注册的框架名自动添加 BOTOY前缀如:"name" => "BOTOY name" - token = current_ctx.set(Context(pkt)) + _ctx = Context(pkt) + if self._log_messages: + logger.info(_ctx) + token = current_ctx.set(_ctx) if _available_names is not None: _available_names = [i[6:] for i in _available_names] await asyncio.gather( diff --git a/docs/client.md b/docs/client.md index 67b21b5..b59b5a3 100644 --- a/docs/client.md +++ b/docs/client.md @@ -21,6 +21,7 @@ from botoy import Botoy | `set_url` | 设置 opq websockets 连接地址 | | `load_plugins` | 加载插件,必须显式调用该方法才会加载插件(插件仅仅是分文件/分模块提供接收函数) | | `print_receivers` | 打印所有接收函数信息 | +| `log_messages` | 启用消息日志打印 | | `attach` | 装饰并注册接收函数,直接使用实例对象本身 `@bot` | | `connect` | 连接 opq 服务端 | | `disconnect` | 断开连接 |