- test.py: 2198972886 → your_admin_qq - README.md: jianf/qqrebot 链接 → 通用描述 - README.md: 示例配置 2198972886 → your_admin_qq
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""
|
||
测试框架 — 模拟 qqrebot 环境测试 openclaw_bridge 插件
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
import logging
|
||
from pathlib import Path
|
||
|
||
logging.basicConfig(
|
||
level=logging.INFO,
|
||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||
)
|
||
|
||
# 模拟 qqrebot 插件加载路径
|
||
sys.path.insert(0, str(Path(__file__).parent))
|
||
|
||
from src.modules.plugin_modules import MessageContext
|
||
from src.process import OpenClawBridge
|
||
|
||
|
||
class OpenclawBridgeTest:
|
||
def __init__(self):
|
||
self.test_simulate_chat()
|
||
|
||
def test_simulate_chat(self):
|
||
"""模拟接收到 QQ 消息"""
|
||
print("=" * 60)
|
||
print("OpenClawBridge 插件测试")
|
||
print("=" * 60)
|
||
|
||
# 模拟群聊消息上下文
|
||
mock_ctx = MessageContext(
|
||
uid="your_admin_qq",
|
||
gid="12345678",
|
||
raw_message="你好",
|
||
id="123456789",
|
||
)
|
||
|
||
# 实例化插件(会加载配置并尝试连接 Gateway)
|
||
plugin = OpenClawBridge(mock_ctx)
|
||
|
||
print(f"\n配置状态:")
|
||
print(f" gateway_url: {plugin.gateway_url}")
|
||
print(f" allowed_sender: {plugin.allowed_sender}")
|
||
print(f" model: {plugin.model}")
|
||
print(f" agent_id: {plugin.agent_id}")
|
||
|
||
if not plugin.gateway_token or plugin.gateway_token == "your_gateway_token_here":
|
||
print("\n⚠️ 配置未修改,请先编辑 config/openclawbridge/config.toml")
|
||
print(" 填入正确的 gateway_token 后再运行测试\n")
|
||
|
||
print("\n执行 after_save...")
|
||
result = plugin.after_save()
|
||
print(f"返回: {result}")
|
||
print("=" * 60)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
OpenclawBridgeTest()
|