From e084a7ec9418e61d7e15f97675625a46c694746f Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sat, 11 Mar 2023 21:27:49 +0100 Subject: switch order of env files to be parsed The priority of the value to be picked is always the last file in the `env_file` tuple We want server values to always be picked up from .env.server, and if someone wants to override them for testing, they'll go into .env But the `env.server` shouldn't be manually tampered with --- bot/constants.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 3aacd0a16..006d0e4ce 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -11,14 +11,13 @@ will default to the values passed to the `default` kwarg. """ import os from enum import Enum -from typing import Optional from pydantic import BaseModel, BaseSettings, root_validator class EnvConfig(BaseSettings): class Config: - env_file = ".env", ".env.server", + env_file = ".env.server", ".env", env_file_encoding = 'utf-8' env_nested_delimiter = '__' -- cgit v1.2.3 From 1a7a8a271e37ecd628768412181c8d01133d8582 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sat, 11 Mar 2023 22:15:19 +0100 Subject: write emoji_trashcan to .env.server upon botstrap --- botstrap.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/botstrap.py b/botstrap.py index 28486bd36..55e1bb6c7 100644 --- a/botstrap.py +++ b/botstrap.py @@ -162,4 +162,8 @@ with DiscordClient() as discord_client: config_str += f"webhooks_{webhook_name}__id={webhook_id}\n" config_str += f"webhooks_{webhook_name}__channel={all_channels[webhook_name]}\n" - env_file_path.write_text(config_str) + config_str += "\n#Emojis\n" + config_str += "emojis_trashcan=🗑️" + + with env_file_path.open("ab") as file: + file.write(config_str.encode("utf-8")) -- cgit v1.2.3 From b4bb64fcfde32cf95708f66beb137f32e2abf5d7 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sun, 12 Mar 2023 18:13:10 +0100 Subject: change mode to "wb" --- botstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botstrap.py b/botstrap.py index 55e1bb6c7..90a954d9b 100644 --- a/botstrap.py +++ b/botstrap.py @@ -165,5 +165,5 @@ with DiscordClient() as discord_client: config_str += "\n#Emojis\n" config_str += "emojis_trashcan=🗑️" - with env_file_path.open("ab") as file: + with env_file_path.open("wb") as file: file.write(config_str.encode("utf-8")) -- cgit v1.2.3