fix: update .env file handling to raise error if not found and templates are unavailable

This commit is contained in:
晴猫
2026-03-15 09:26:39 +09:00
parent 321ac31a6b
commit 4599b4054e

24
bot.py
View File

@@ -28,17 +28,19 @@ template_env_path = Path(__file__).parent / "template" / "template.env"
if env_path.exists():
load_dotenv(str(env_path), override=True)
else:
try:
if template_env_path.exists():
shutil.copyfile(template_env_path, env_path)
print(t("startup.env_created"))
load_dotenv(str(env_path), override=True)
else:
print(t("startup.env_template_missing"))
raise FileNotFoundError(t("startup.env_file_missing"))
except Exception as e:
print(t("startup.env_auto_create_failed", error=e))
raise
print("[WIP] no .env file found, and templates is not ready yet.")
raise
# try:
# if template_env_path.exists():
# shutil.copyfile(template_env_path, env_path)
# print(t("startup.env_created"))
# load_dotenv(str(env_path), override=True)
# else:
# print(t("startup.env_template_missing"))
# raise FileNotFoundError(t("startup.env_file_missing"))
# except Exception as e:
# print(t("startup.env_auto_create_failed", error=e))
# raise
set_locale(os.getenv("MAIBOT_LOCALE", "zh-CN"))