fix: update .env file handling to raise error if not found and templates are unavailable
This commit is contained in:
24
bot.py
24
bot.py
@@ -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"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user