小修复
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from typing import List, Tuple, Type, Any
|
from typing import Dict, List, Optional, Tuple, Type, Any
|
||||||
from src.plugin_system import (
|
from src.plugin_system import (
|
||||||
BasePlugin,
|
BasePlugin,
|
||||||
register_plugin,
|
register_plugin,
|
||||||
@@ -15,6 +15,10 @@ from src.plugin_system import (
|
|||||||
from src.plugin_system.base.base_command import BaseCommand
|
from src.plugin_system.base.base_command import BaseCommand
|
||||||
from src.plugin_system.apis import send_api
|
from src.plugin_system.apis import send_api
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
from src.common.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GetGroupListCommand(BaseCommand):
|
class GetGroupListCommand(BaseCommand):
|
||||||
"""获取群列表命令"""
|
"""获取群列表命令"""
|
||||||
@@ -26,40 +30,28 @@ class GetGroupListCommand(BaseCommand):
|
|||||||
command_examples = ["/get_groups"]
|
command_examples = ["/get_groups"]
|
||||||
intercept_message = True
|
intercept_message = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def execute(self) -> Tuple[bool, str, bool]:
|
async def execute(self) -> Tuple[bool, str, bool]:
|
||||||
try:
|
try:
|
||||||
# 获取聊天流ID
|
|
||||||
stream_id = self.message.chat_stream.stream_id
|
|
||||||
|
|
||||||
# 调用适配器命令API
|
# 调用适配器命令API
|
||||||
|
domain = "user.qzone.qq.com"
|
||||||
response = await send_api.adapter_command_to_stream(
|
response = await send_api.adapter_command_to_stream(
|
||||||
action="get_group_list",
|
action="get_cookies",
|
||||||
params={},
|
platform="qq",
|
||||||
stream_id=stream_id
|
params={"domain": domain},
|
||||||
|
timeout=40.0,
|
||||||
|
storage_message=False
|
||||||
)
|
)
|
||||||
|
text = str(response)
|
||||||
if response["status"] == "ok":
|
await self.send_text(text)
|
||||||
group_list = response.get("data", [])
|
return True, "获取群列表成功", True
|
||||||
|
|
||||||
if group_list:
|
|
||||||
# 格式化群列表信息
|
|
||||||
group_info = "\\n".join([
|
|
||||||
f"群号: {group['group_id']}, 群名: {group['group_name']}"
|
|
||||||
for group in group_list
|
|
||||||
])
|
|
||||||
await self.send_text(f"机器人加入的群列表:\\n{group_info}")
|
|
||||||
else:
|
|
||||||
await self.send_text("机器人未加入任何群")
|
|
||||||
|
|
||||||
return True, "获取群列表成功", True
|
|
||||||
else:
|
|
||||||
await self.send_text(f"获取群列表失败: {response['message']}")
|
|
||||||
return False, "获取群列表失败", True
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"执行获取群列表命令时出错: {e}")
|
await self.send_text(f"获取群列表失败: {str(e)}")
|
||||||
await self.send_text("命令执行失败")
|
return False, "获取群列表失败", True
|
||||||
return False, "命令执行失败", True
|
|
||||||
|
|
||||||
class CompareNumbersTool(BaseTool):
|
class CompareNumbersTool(BaseTool):
|
||||||
"""比较两个数大小的工具"""
|
"""比较两个数大小的工具"""
|
||||||
|
|||||||
@@ -157,6 +157,10 @@ class ChatBot:
|
|||||||
if message.message_segment.type == "adapter_response":
|
if message.message_segment.type == "adapter_response":
|
||||||
await self.handle_adapter_response(message)
|
await self.handle_adapter_response(message)
|
||||||
return True
|
return True
|
||||||
|
elif message.message_segment.type == "adapter_command":
|
||||||
|
# 适配器命令消息不需要进一步处理
|
||||||
|
logger.debug("收到适配器命令消息,跳过后续处理")
|
||||||
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ class MessageStorage:
|
|||||||
"""更新消息ID"""
|
"""更新消息ID"""
|
||||||
try:
|
try:
|
||||||
mmc_message_id = message.message_info.message_id # 修复:正确访问message_id
|
mmc_message_id = message.message_info.message_id # 修复:正确访问message_id
|
||||||
|
qq_message_id = None # 初始化变量
|
||||||
|
|
||||||
if message.message_segment.type == "notify":
|
if message.message_segment.type == "notify":
|
||||||
qq_message_id = message.message_segment.data.get("id")
|
qq_message_id = message.message_segment.data.get("id")
|
||||||
elif message.message_segment.type == "text":
|
elif message.message_segment.type == "text":
|
||||||
@@ -125,9 +127,14 @@ class MessageStorage:
|
|||||||
logger.info(f"更新消息ID完成,消息ID为{qq_message_id}")
|
logger.info(f"更新消息ID完成,消息ID为{qq_message_id}")
|
||||||
elif message.message_segment.type == "adapter_response":
|
elif message.message_segment.type == "adapter_response":
|
||||||
logger.debug("适配器响应消息,不需要更新ID")
|
logger.debug("适配器响应消息,不需要更新ID")
|
||||||
|
return
|
||||||
|
elif message.message_segment.type == "adapter_command":
|
||||||
|
logger.debug("适配器命令消息,不需要更新ID")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
logger.info(f"更新消息ID错误,seg类型为{message.message_segment.type}")
|
logger.info(f"更新消息ID错误,seg类型为{message.message_segment.type}")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not qq_message_id:
|
if not qq_message_id:
|
||||||
logger.info("消息不存在message_id,无法更新")
|
logger.info("消息不存在message_id,无法更新")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ async def custom_to_stream(
|
|||||||
async def adapter_command_to_stream(
|
async def adapter_command_to_stream(
|
||||||
action: str,
|
action: str,
|
||||||
params: dict,
|
params: dict,
|
||||||
|
platform: str,
|
||||||
stream_id: Optional[str] = None,
|
stream_id: Optional[str] = None,
|
||||||
timeout: float = 30.0,
|
timeout: float = 30.0,
|
||||||
storage_message: bool = False
|
storage_message: bool = False
|
||||||
@@ -452,12 +453,12 @@ async def adapter_command_to_stream(
|
|||||||
temp_user_info = UserInfo(
|
temp_user_info = UserInfo(
|
||||||
user_id="system",
|
user_id="system",
|
||||||
user_nickname="System",
|
user_nickname="System",
|
||||||
platform="adapter_command"
|
platform=platform
|
||||||
)
|
)
|
||||||
|
|
||||||
temp_chat_stream = ChatStream(
|
temp_chat_stream = ChatStream(
|
||||||
stream_id=stream_id,
|
stream_id=stream_id,
|
||||||
platform="adapter_command",
|
platform=platform,
|
||||||
user_info=temp_user_info,
|
user_info=temp_user_info,
|
||||||
group_info=None
|
group_info=None
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
@@ -513,7 +514,7 @@ class PluginManager:
|
|||||||
plugin_instance.on_unload()
|
plugin_instance.on_unload()
|
||||||
|
|
||||||
# 从组件注册表中移除插件的所有组件
|
# 从组件注册表中移除插件的所有组件
|
||||||
component_registry.unregister_plugin(plugin_name)
|
asyncio.run(component_registry.unregister_plugin(plugin_name))
|
||||||
|
|
||||||
# 从已加载插件中移除
|
# 从已加载插件中移除
|
||||||
del self.loaded_plugins[plugin_name]
|
del self.loaded_plugins[plugin_name]
|
||||||
|
|||||||
Reference in New Issue
Block a user