mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
fix(path): pass plugin name to StarTools.get_data_dir() to avoid inspect.stack() crash (#193)
* fix: pass plugin name to StarTools.get_data_dir to avoid inspect-stack crash * refactor: reuse plugin name constant for data dir --------- Co-authored-by: Rat0323 <rat0323@users.noreply.github.com> Co-authored-by: Rat0323 <261020116+Rat0323@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,7 @@ from .src.infrastructure.platform.template_preview import (
|
|||||||
)
|
)
|
||||||
from .src.infrastructure.reporting.generators import ReportGenerator
|
from .src.infrastructure.reporting.generators import ReportGenerator
|
||||||
from .src.infrastructure.scheduler.auto_scheduler import AutoScheduler
|
from .src.infrastructure.scheduler.auto_scheduler import AutoScheduler
|
||||||
|
from .src.shared.constants import PLUGIN_NAME
|
||||||
from .src.shared.trace_context import TraceContext, TraceLogFilter
|
from .src.shared.trace_context import TraceContext, TraceLogFilter
|
||||||
from .src.utils.logger import logger
|
from .src.utils.logger import logger
|
||||||
from .src.utils.resilience import GlobalRateLimiter
|
from .src.utils.resilience import GlobalRateLimiter
|
||||||
@@ -77,10 +78,6 @@ class GroupDailyAnalysis(Star):
|
|||||||
super().__init__(context)
|
super().__init__(context)
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
|
||||||
|
|
||||||
# 1. 基础设施层
|
# 1. 基础设施层
|
||||||
self.config_manager = ConfigManager(config)
|
self.config_manager = ConfigManager(config)
|
||||||
self.bot_manager = BotManager(self.config_manager)
|
self.bot_manager = BotManager(self.config_manager)
|
||||||
@@ -88,15 +85,7 @@ class GroupDailyAnalysis(Star):
|
|||||||
self.bot_manager.set_plugin_instance(self)
|
self.bot_manager.set_plugin_instance(self)
|
||||||
self.history_manager = HistoryManager(self)
|
self.history_manager = HistoryManager(self)
|
||||||
|
|
||||||
try:
|
plugin_data_dir = StarTools.get_data_dir(PLUGIN_NAME)
|
||||||
plugin_data_dir = StarTools.get_data_dir()
|
|
||||||
except Exception:
|
|
||||||
# 回退逻辑:手动构造满足规范的路径
|
|
||||||
plugin_data_dir = (
|
|
||||||
Path(get_astrbot_data_path())
|
|
||||||
/ "plugin_data"
|
|
||||||
/ "astrbot_plugin_qq_group_daily_analysis"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.report_generator = ReportGenerator(self.config_manager, plugin_data_dir)
|
self.report_generator = ReportGenerator(self.config_manager, plugin_data_dir)
|
||||||
|
|
||||||
@@ -640,23 +629,12 @@ class GroupDailyAnalysis(Star):
|
|||||||
|
|
||||||
# 若用户配置为空,使用默认目录
|
# 若用户配置为空,使用默认目录
|
||||||
if not html_output_dir:
|
if not html_output_dir:
|
||||||
try:
|
from astrbot.api.star import StarTools
|
||||||
from astrbot.api.star import StarTools
|
|
||||||
|
|
||||||
html_output_dir = os.path.join(
|
html_output_dir = os.path.join(
|
||||||
StarTools.get_data_dir(), "self_hosted_html_reports"
|
StarTools.get_data_dir(PLUGIN_NAME),
|
||||||
)
|
"self_hosted_html_reports",
|
||||||
except Exception:
|
)
|
||||||
from astrbot.core.utils.astrbot_path import (
|
|
||||||
get_astrbot_data_path,
|
|
||||||
)
|
|
||||||
|
|
||||||
html_output_dir = os.path.join(
|
|
||||||
get_astrbot_data_path(),
|
|
||||||
"plugin_data",
|
|
||||||
"astrbot_plugin_qq_group_daily_analysis",
|
|
||||||
"self_hosted_html_reports",
|
|
||||||
)
|
|
||||||
|
|
||||||
# 计算相对路径并转换为URL
|
# 计算相对路径并转换为URL
|
||||||
rel_path = os.path.relpath(html_path, html_output_dir)
|
rel_path = os.path.relpath(html_path, html_output_dir)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections.abc import Sized
|
|||||||
from typing import Generic, TypeVar
|
from typing import Generic, TypeVar
|
||||||
|
|
||||||
from ....domain.models.data_models import TokenUsage
|
from ....domain.models.data_models import TokenUsage
|
||||||
|
from ....shared.constants import PLUGIN_NAME
|
||||||
from ....utils.logger import logger
|
from ....utils.logger import logger
|
||||||
from ..utils.json_utils import parse_json_response
|
from ..utils.json_utils import parse_json_response
|
||||||
from ..utils.llm_utils import (
|
from ..utils.llm_utils import (
|
||||||
@@ -280,20 +281,9 @@ class BaseAnalyzer(ABC, Generic[TDataObject, TInputData]):
|
|||||||
session_id: 会话ID
|
session_id: 会话ID
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from astrbot.api.star import StarTools
|
from astrbot.api.star import StarTools
|
||||||
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
|
||||||
|
|
||||||
try:
|
data_path = StarTools.get_data_dir(PLUGIN_NAME) / "debug_data"
|
||||||
data_path = StarTools.get_data_dir() / "debug_data"
|
|
||||||
except Exception:
|
|
||||||
data_path = (
|
|
||||||
Path(get_astrbot_data_path())
|
|
||||||
/ "plugin_data"
|
|
||||||
/ "astrbot_plugin_qq_group_daily_analysis"
|
|
||||||
/ "debug_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
data_path.mkdir(parents=True, exist_ok=True)
|
data_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from ...domain.models.data_models import (
|
|||||||
UserTitle,
|
UserTitle,
|
||||||
)
|
)
|
||||||
from ...domain.repositories.analysis_repository import IAnalysisProvider
|
from ...domain.repositories.analysis_repository import IAnalysisProvider
|
||||||
|
from ...shared.constants import PLUGIN_NAME
|
||||||
from ...utils.logger import logger
|
from ...utils.logger import logger
|
||||||
from .analyzers.chat_quality_analyzer import ChatQualityAnalyzer
|
from .analyzers.chat_quality_analyzer import ChatQualityAnalyzer
|
||||||
from .analyzers.golden_quote_analyzer import GoldenQuoteAnalyzer
|
from .analyzers.golden_quote_analyzer import GoldenQuoteAnalyzer
|
||||||
@@ -464,7 +465,7 @@ class LLMAnalyzer(IAnalysisProvider):
|
|||||||
|
|
||||||
from astrbot.api.star import StarTools
|
from astrbot.api.star import StarTools
|
||||||
|
|
||||||
debug_dir = StarTools.get_data_dir() / "debug_data"
|
debug_dir = StarTools.get_data_dir(PLUGIN_NAME) / "debug_data"
|
||||||
debug_dir.mkdir(parents=True, exist_ok=True)
|
debug_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
msg_file_path = debug_dir / f"{session_id}_messages.json"
|
msg_file_path = debug_dir / f"{session_id}_messages.json"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
from astrbot.api import AstrBotConfig
|
from astrbot.api import AstrBotConfig
|
||||||
from astrbot.api.star import StarTools
|
from astrbot.api.star import StarTools
|
||||||
|
|
||||||
|
from ...shared.constants import PLUGIN_NAME
|
||||||
from ...utils.logger import logger
|
from ...utils.logger import logger
|
||||||
from ..utils.template_utils import upgrade_str_format_template
|
from ..utils.template_utils import upgrade_str_format_template
|
||||||
|
|
||||||
@@ -297,23 +298,10 @@ class ConfigManager:
|
|||||||
|
|
||||||
def get_html_output_dir(self) -> str:
|
def get_html_output_dir(self) -> str:
|
||||||
"""获取HTML输出目录"""
|
"""获取HTML输出目录"""
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
default_path = StarTools.get_data_dir(PLUGIN_NAME) / "self_hosted_html_reports"
|
||||||
|
val = self._get_group("html").get("html_output_dir")
|
||||||
try:
|
return val if val else str(default_path)
|
||||||
default_path = StarTools.get_data_dir() / "self_hosted_html_reports"
|
|
||||||
val = self._get_group("html").get("html_output_dir")
|
|
||||||
return val if val else str(default_path)
|
|
||||||
except Exception:
|
|
||||||
val = self._get_group("html").get("html_output_dir")
|
|
||||||
fallback_path = (
|
|
||||||
Path(get_astrbot_data_path())
|
|
||||||
/ "plugin_data"
|
|
||||||
/ "astrbot_plugin_qq_group_daily_analysis"
|
|
||||||
/ "self_hosted_html_reports"
|
|
||||||
)
|
|
||||||
return val if val else str(fallback_path)
|
|
||||||
|
|
||||||
def get_html_base_url(self) -> str:
|
def get_html_base_url(self) -> str:
|
||||||
"""获取HTML外链Base URL"""
|
"""获取HTML外链Base URL"""
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from collections.abc import Callable
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from ...shared.constants import PLUGIN_NAME
|
||||||
from ...shared.trace_context import TraceContext
|
from ...shared.trace_context import TraceContext
|
||||||
from ...utils.logger import logger
|
from ...utils.logger import logger
|
||||||
|
|
||||||
@@ -149,23 +150,12 @@ class ReportDispatcher:
|
|||||||
|
|
||||||
# 若用户配置为空,使用默认目录
|
# 若用户配置为空,使用默认目录
|
||||||
if not html_output_dir:
|
if not html_output_dir:
|
||||||
try:
|
from astrbot.api.star import StarTools
|
||||||
from astrbot.api.star import StarTools
|
|
||||||
|
|
||||||
html_output_dir = os.path.join(
|
html_output_dir = os.path.join(
|
||||||
StarTools.get_data_dir(), "self_hosted_html_reports"
|
StarTools.get_data_dir(PLUGIN_NAME),
|
||||||
)
|
"self_hosted_html_reports",
|
||||||
except Exception:
|
)
|
||||||
from astrbot.core.utils.astrbot_path import (
|
|
||||||
get_astrbot_data_path,
|
|
||||||
)
|
|
||||||
|
|
||||||
html_output_dir = os.path.join(
|
|
||||||
get_astrbot_data_path(),
|
|
||||||
"plugin_data",
|
|
||||||
"astrbot_plugin_qq_group_daily_analysis",
|
|
||||||
"self_hosted_html_reports",
|
|
||||||
)
|
|
||||||
|
|
||||||
# 计算相对路径并转换为URL
|
# 计算相对路径并转换为URL
|
||||||
rel_path = os.path.relpath(html_path, html_output_dir)
|
rel_path = os.path.relpath(html_path, html_output_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user