Skip to content

Commit 5e2da8c

Browse files
committed
fix(get_astrbot_data_path): fallback 到 get_astrbot_data_path 方法
1 parent e503e7a commit 5e2da8c

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

_conf_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@
376376
"type": "string",
377377
"description": "报告储存目录",
378378
"default": "",
379-
"hint": "HTML报告文件的保存目录,用于存储生成的 HTML 文件和原始 JSON 数据。留空则自动使用插件数据目录下的 self_hosted_html_reports 目录。"
379+
"hint": "HTML报告文件的保存目录,用于存储生成的 HTML 文件和原始 JSON 数据。留空则自动使用插件数据目录(astrbot_path/data/plugin_data/astrbot_plugin_qq_group_daily_analysis/)下的 self_hosted_html_reports 目录。"
380380
},
381381
"html_filename_format": {
382382
"type": "string",

main.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,28 @@ def __init__(self, context: Context, config: AstrBotConfig):
8080
super().__init__(context)
8181
self.config = config
8282

83+
from pathlib import Path
84+
85+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
86+
8387
# 1. 基础设施层
8488
self.config_manager = ConfigManager(config)
8589
self.bot_manager = BotManager(self.config_manager)
8690
self.bot_manager.set_context(context)
8791
self.bot_manager.set_plugin_instance(self)
8892
self.history_manager = HistoryManager(self)
89-
self.report_generator = ReportGenerator(
90-
self.config_manager, StarTools.get_data_dir()
91-
)
93+
94+
try:
95+
plugin_data_dir = StarTools.get_data_dir()
96+
except Exception:
97+
# 回退逻辑:手动构造满足规范的路径
98+
plugin_data_dir = (
99+
Path(get_astrbot_data_path())
100+
/ "plugin_data"
101+
/ "astrbot_plugin_qq_group_daily_analysis"
102+
)
103+
104+
self.report_generator = ReportGenerator(self.config_manager, plugin_data_dir)
92105

93106
# Telegram 注册表 (持久层)
94107
self.telegram_group_registry = TelegramGroupRegistry(self)

src/infrastructure/analysis/analyzers/base_analyzer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,21 @@ def _save_debug_data(self, prompt: str, session_id: str):
279279
session_id: 会话ID
280280
"""
281281
try:
282+
from pathlib import Path
283+
282284
from astrbot.api.star import StarTools
285+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
286+
287+
try:
288+
data_path = StarTools.get_data_dir() / "debug_data"
289+
except Exception:
290+
data_path = (
291+
Path(get_astrbot_data_path())
292+
/ "plugin_data"
293+
/ "astrbot_plugin_qq_group_daily_analysis"
294+
/ "debug_data"
295+
)
283296

284-
data_path = StarTools.get_data_dir() / "debug_data"
285297
data_path.mkdir(parents=True, exist_ok=True)
286298

287299
file_name = f"{session_id}_{self.get_data_type()}.txt"

src/infrastructure/config/config_manager.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,23 @@ def get_keep_original_persona(self) -> bool:
224224

225225
def get_pdf_output_dir(self) -> str:
226226
"""获取PDF输出目录"""
227+
from pathlib import Path
228+
229+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
230+
227231
try:
228232
default_path = StarTools.get_data_dir() / "reports"
229233
val = self._get_group("pdf").get("pdf_output_dir")
230234
return val if val else str(default_path)
231235
except Exception:
232236
val = self._get_group("pdf").get("pdf_output_dir")
233-
return (
234-
val
235-
if val
236-
else "data/plugins/astrbot_plugin_qq_group_daily_analysis/reports"
237+
fallback_path = (
238+
Path(get_astrbot_data_path())
239+
/ "plugin_data"
240+
/ "astrbot_plugin_qq_group_daily_analysis"
241+
/ "reports"
237242
)
243+
return val if val else str(fallback_path)
238244

239245
def get_bot_self_ids(self) -> list:
240246
"""获取机器人自身的 ID 列表 (兼容 bot_qq_ids)"""
@@ -252,17 +258,23 @@ def get_pdf_filename_format(self) -> str:
252258

253259
def get_html_output_dir(self) -> str:
254260
"""获取HTML输出目录"""
261+
from pathlib import Path
262+
263+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
264+
255265
try:
256266
default_path = StarTools.get_data_dir() / "self_hosted_html_reports"
257267
val = self._get_group("html").get("html_output_dir")
258268
return val if val else str(default_path)
259269
except Exception:
260270
val = self._get_group("html").get("html_output_dir")
261-
return (
262-
val
263-
if val
264-
else "data/plugins/astrbot_plugin_qq_group_daily_analysis/self_hosted_html_reports"
271+
fallback_path = (
272+
Path(get_astrbot_data_path())
273+
/ "plugin_data"
274+
/ "astrbot_plugin_qq_group_daily_analysis"
275+
/ "self_hosted_html_reports"
265276
)
277+
return val if val else str(fallback_path)
266278

267279
def get_html_base_url(self) -> str:
268280
"""获取HTML外链Base URL"""

0 commit comments

Comments
 (0)