Skip to content

Commit

Permalink
feat(client): 添加log_messages启用消息日志打印
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Apr 17, 2024
1 parent 42bfcb4 commit 6dc7f5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion botoy/_internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from botoy import Botoy
| `set_url` | 设置 opq websockets 连接地址 |
| `load_plugins` | 加载插件,必须显式调用该方法才会加载插件(插件仅仅是分文件/分模块提供接收函数) |
| `print_receivers` | 打印所有接收函数信息 |
| `log_messages` | 启用消息日志打印 |
| `attach` | 装饰并注册接收函数,直接使用实例对象本身 `@bot` |
| `connect` | 连接 opq 服务端 |
| `disconnect` | 断开连接 |
Expand Down

0 comments on commit 6dc7f5e

Please sign in to comment.