mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
fix: 正确注册命令
This commit is contained in:
@@ -10,11 +10,10 @@ import os
|
||||
from typing import Any, Optional
|
||||
|
||||
from astrbot.api import AstrBotConfig, logger
|
||||
from astrbot.api.event import filter
|
||||
from astrbot.api.event import AstrMessageEvent, filter
|
||||
from astrbot.api.event.filter import PermissionType
|
||||
from astrbot.api.star import Context, Star
|
||||
from astrbot.core.message.components import File
|
||||
from astrbot.core.platform.astr_message_event import AstrMessageEvent
|
||||
from astrbot.core.star.filter.permission import PermissionType
|
||||
|
||||
from .src.application.analysis_orchestrator import AnalysisOrchestrator, AnalysisConfig
|
||||
from .src.infrastructure.platform.factory import PlatformAdapterFactory
|
||||
@@ -206,8 +205,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
except Exception as e:
|
||||
logger.error(f"插件资源清理失败: {e}")
|
||||
|
||||
@filter.command("群分析")
|
||||
@filter.command("group_analysis")
|
||||
@filter.command("群分析", alias={"group_analysis"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def analyze_group_daily(
|
||||
self, event: AstrMessageEvent, days: int | None = None
|
||||
@@ -374,8 +372,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
f"❌ 分析失败: {str(e)}。请检查网络连接和LLM配置,或联系管理员"
|
||||
)
|
||||
|
||||
@filter.command("设置格式")
|
||||
@filter.command("set_format")
|
||||
@filter.command("设置格式", alias={"set_format"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def set_output_format(self, event: AstrMessageEvent, format_type: str = ""):
|
||||
"""
|
||||
@@ -417,8 +414,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
self.config_manager.set_output_format(format_type)
|
||||
yield event.plain_result(f"✅ 输出格式已设置为: {format_type}")
|
||||
|
||||
@filter.command("设置模板")
|
||||
@filter.command("set_template")
|
||||
@filter.command("设置模板", alias={"set_template"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def set_report_template(
|
||||
self, event: AstrMessageEvent, template_input: str = ""
|
||||
@@ -482,8 +478,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
self.config_manager.set_report_template(template_name)
|
||||
yield event.plain_result(f"✅ 报告模板已设置为: {template_name}")
|
||||
|
||||
@filter.command("查看模板")
|
||||
@filter.command("view_templates")
|
||||
@filter.command("查看模板", alias={"view_templates"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def view_templates(self, event: AstrMessageEvent):
|
||||
"""
|
||||
@@ -557,8 +552,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
# 使用 Nodes 包装成一个合并转发消息
|
||||
yield event.chain_result([Nodes(node_list)])
|
||||
|
||||
@filter.command("安装PDF")
|
||||
@filter.command("install_pdf")
|
||||
@filter.command("安装PDF", alias={"install_pdf"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def install_pdf_deps(self, event: AstrMessageEvent):
|
||||
"""
|
||||
@@ -575,8 +569,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
logger.error(f"安装 PDF 依赖失败: {e}", exc_info=True)
|
||||
yield event.plain_result(f"❌ 安装过程中出现错误: {str(e)}")
|
||||
|
||||
@filter.command("分析设置")
|
||||
@filter.command("analysis_settings")
|
||||
@filter.command("分析设置", alias={"analysis_settings"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def analysis_settings(self, event: AstrMessageEvent, action: str = "status"):
|
||||
"""
|
||||
|
||||
@@ -155,8 +155,35 @@ class AnalysisOrchestrator:
|
||||
返回:
|
||||
原始消息字典列表(通用格式,由适配器决定具体格式)
|
||||
"""
|
||||
# unified_messages = await self.fetch_messages(group_id, days, max_count)
|
||||
#
|
||||
# # 如果适配器实现了 convert_to_raw_format,则使用它
|
||||
# if hasattr(self.adapter, "convert_to_raw_format"):
|
||||
# return self.adapter.convert_to_raw_format(unified_messages)
|
||||
#
|
||||
# # 默认回退逻辑:手动转换
|
||||
# # 这可能不完美,但能保证基本的向后兼容性
|
||||
# return [
|
||||
# {
|
||||
# "message_id": msg.message_id,
|
||||
# "group_id": msg.group_id,
|
||||
# "sender": {
|
||||
# "user_id": msg.sender_id,
|
||||
# "nickname": msg.sender_name,
|
||||
# "card": msg.sender_card
|
||||
# },
|
||||
# "time": msg.timestamp,
|
||||
# "message": msg.text_content, # 简化处理
|
||||
# "raw_message": msg.text_content
|
||||
# }
|
||||
# for msg in unified_messages
|
||||
# ]
|
||||
|
||||
# 暂时直接使用适配器获取 raw 格式,如果适配器支持
|
||||
# 这是为了确保现有逻辑完全兼容,因为 convert_to_raw_format 可能有损
|
||||
# 但我们希望尽可能使用新的 fetch_messages
|
||||
|
||||
unified_messages = await self.fetch_messages(group_id, days, max_count)
|
||||
# 使用适配器的原生格式转换,而非硬编码 OneBot 格式
|
||||
return self.adapter.convert_to_raw_format(unified_messages)
|
||||
|
||||
async def get_group_info(self, group_id: str):
|
||||
|
||||
@@ -48,6 +48,9 @@ class PlatformAdapterFactory:
|
||||
try:
|
||||
return adapter_class(bot_instance, config)
|
||||
except Exception:
|
||||
# 记录异常,但不崩溃
|
||||
import logging
|
||||
logging.getLogger(__name__).error(f"Error creating adapter for {platform_name}", exc_info=True)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
@@ -73,6 +76,7 @@ def _register_adapters():
|
||||
try:
|
||||
from .adapters.discord_adapter import DiscordAdapter
|
||||
PlatformAdapterFactory.register("discord", DiscordAdapter)
|
||||
PlatformAdapterFactory.register("discord_bot", DiscordAdapter) # Add alias
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user