refactor: 修改框架路径获取方式,规范化路径拼接

This commit is contained in:
Raven95676
2025-05-06 11:54:14 +08:00
parent f06be6ed21
commit c111da4681
38 changed files with 624 additions and 334 deletions
+4 -1
View File
@@ -1,3 +1,4 @@
import os
import aiohttp
import datetime
import builtins
@@ -13,6 +14,7 @@ from astrbot.core.platform.astr_message_event import MessageSesion
from astrbot.core.platform.message_type import MessageType
from astrbot.core.provider.sources.dify_source import ProviderDify
from astrbot.core.utils.io import download_dashboard, get_dashboard_version
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
from astrbot.core.star.star_handler import star_handlers_registry, StarHandlerMetadata
from astrbot.core.star.star import star_map
from astrbot.core.star.star_manager import PluginManager
@@ -1159,7 +1161,8 @@ UID: {user_id} 此 ID 可用于设置管理员。
@filter.command("gewe_code")
async def gewe_code(self, event: AstrMessageEvent, code: str):
"""保存 gewechat 验证码"""
with open("data/temp/gewe_code", "w", encoding="utf-8") as f:
code_path = os.path.join(get_astrbot_data_path(), "temp","gewe_code")
with open(code_path, "w", encoding="utf-8") as f:
f.write(code)
yield event.plain_result("验证码已保存。")
+4 -2
View File
@@ -15,6 +15,7 @@ from astrbot.api.event import filter
from astrbot.api.provider import ProviderRequest
from astrbot.api.message_components import Image, File
from astrbot.core.utils.io import download_image_by_url, download_file
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
PROMPT = """
## Task
@@ -90,7 +91,7 @@ DEFAULT_CONFIG = {
},
"docker_host_astrbot_abs_path": "",
}
PATH = "data/config/python_interpreter.json"
PATH = os.path.join(get_astrbot_data_path(), "config", "python_interpreter.json")
@star.register(
@@ -212,7 +213,8 @@ class Main(star.Star):
if isinstance(comp, File):
if comp.file.startswith("http"):
name = comp.name if comp.name else uuid.uuid4().hex[:8]
path = f"data/temp/{name}"
temp_dir = os.path.join(get_astrbot_data_path(), "temp")
path = os.path.join(temp_dir, name)
await download_file(comp.file, path)
else:
path = comp.file
+7 -4
View File
@@ -8,6 +8,7 @@ from astrbot.api.event import filter
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from astrbot.api.event import AstrMessageEvent, MessageEventResult
from astrbot.api import llm_tool, logger
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
@star.register(
@@ -29,10 +30,11 @@ class Main(star.Star):
self.scheduler = AsyncIOScheduler(timezone=self.timezone)
# set and load config
if not os.path.exists("data/astrbot-reminder.json"):
with open("data/astrbot-reminder.json", "w", encoding="utf-8") as f:
reminder_file = os.path.join(get_astrbot_data_path(), "astrbot-reminder.json")
if not os.path.exists(reminder_file):
with open(reminder_file, "w", encoding="utf-8") as f:
f.write("{}")
with open("data/astrbot-reminder.json", "r", encoding="utf-8") as f:
with open(reminder_file, "r", encoding="utf-8") as f:
self.reminder_data = json.load(f)
self._init_scheduler()
@@ -82,7 +84,8 @@ class Main(star.Star):
async def _save_data(self):
"""Save the reminder data."""
with open("data/astrbot-reminder.json", "w", encoding="utf-8") as f:
reminder_file = os.path.join(get_astrbot_data_path(), "astrbot-reminder.json")
with open(reminder_file, "w", encoding="utf-8") as f:
json.dump(self.reminder_data, f, ensure_ascii=False)
def _parse_cron_expr(self, cron_expr: str):