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():
|
if env_path.exists():
|
||||||
load_dotenv(str(env_path), override=True)
|
load_dotenv(str(env_path), override=True)
|
||||||
else:
|
else:
|
||||||
try:
|
print("[WIP] no .env file found, and templates is not ready yet.")
|
||||||
if template_env_path.exists():
|
raise
|
||||||
shutil.copyfile(template_env_path, env_path)
|
# try:
|
||||||
print(t("startup.env_created"))
|
# if template_env_path.exists():
|
||||||
load_dotenv(str(env_path), override=True)
|
# shutil.copyfile(template_env_path, env_path)
|
||||||
else:
|
# print(t("startup.env_created"))
|
||||||
print(t("startup.env_template_missing"))
|
# load_dotenv(str(env_path), override=True)
|
||||||
raise FileNotFoundError(t("startup.env_file_missing"))
|
# else:
|
||||||
except Exception as e:
|
# print(t("startup.env_template_missing"))
|
||||||
print(t("startup.env_auto_create_failed", error=e))
|
# raise FileNotFoundError(t("startup.env_file_missing"))
|
||||||
raise
|
# except Exception as e:
|
||||||
|
# print(t("startup.env_auto_create_failed", error=e))
|
||||||
|
# raise
|
||||||
|
|
||||||
set_locale(os.getenv("MAIBOT_LOCALE", "zh-CN"))
|
set_locale(os.getenv("MAIBOT_LOCALE", "zh-CN"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user