Skip to content

Commit

Permalink
Feat: Make testing_role_name optional and required only in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LifeAdventurer committed Oct 2, 2024
1 parent 60ad838 commit e2afea7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()


def load_config(file_path: str) -> dict:
def load_config(file_path: str, debug: bool) -> dict:
"""Loads configuration from a JSON file and validates required fields.
Args:
file_path: Path to the JSON configuration file.
debug: Whether to enable debug mode.
Returns:
dict: The configuration dictionary.
Expand All @@ -48,10 +49,13 @@ def load_config(file_path: str) -> dict:
required_keys = {
"token": str,
"typist_role_name": str,
"testing_role_name": str,
"contests_held": int,
}

# If debug mode is enabled, add testing_role_name to the required keys
if debug:
required_keys["testing_role_name"] = str

# Validate that the required keys are present and of the correct type
for key, expected_type in required_keys.items():
if key not in config:
Expand Down Expand Up @@ -114,7 +118,7 @@ async def run(self) -> None:
args = parse_args()

# Load configuration from JSON file
config = load_config(CONFIG_JSON_FILE_PATH)
config = load_config(CONFIG_JSON_FILE_PATH, debug=args.debug)

# Initialize and run the bot
bot_instance = BotSetup(config["token"], debug=args.debug)
Expand Down

0 comments on commit e2afea7

Please sign in to comment.