From 96fe28b15c7ad0e097424f45bc450da52d2e3be9 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Thu, 12 Dec 2024 17:14:09 +0000 Subject: [PATCH] zomboid log timestamp format as environment variable --- README.md | 5 ++++- cogs/players.py | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b208d2..c19a037 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,12 @@ This should make the environment variables used be more clear and pronounced whe |`SPIFFO__DISCORD_CHANNEL_ID`|Snowflake ID of the channel where join alerts and other server related messages should appear.|✔|| |`SPIFFO__STEAM_API_KEY`|Web API key granted by steam, allows for the user's steam profile info to be shown in the join alerts.||| |`SPIFFO__ZOMBOID_FOLDER_PATH`|Absolute path to the 'Zomboid' folder that contains the `server-console.txt` file.|✔|| +|`SPIFFO__DATA_FOLDER_PATH`|Custom path of where the bot will create and store data.|✔|| |`SPIFFO__SERVER_NAME`|Name of the server instance, don't change unless you know what you are doing!||servertest| +|`SPIFFO__DEBUG`|Whether to run in debug mode, which will reveal debug logs.||False| +|`SPIFFO__ZOMBOID_LOG_TIMESTAMP_FORMAT`|The format used for timestamps in Zomboid's logs - do not change this!|✔|%d-%m-%y %H:%M:%S.%f| -## Why Did I Make This? +## Why Am I Making This? All existing bots are poorly coded, slow and/or lack certain features. diff --git a/cogs/players.py b/cogs/players.py index 8ed40c8..e86ad6c 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -17,6 +17,7 @@ from utils.models import Player ZOMBOID_FOLDER_PATH = Path(getenv("SPIFFO__ZOMBOID_FOLDER_PATH")) LOGS_FOLDER_PATH = ZOMBOID_FOLDER_PATH / "Logs" USER_LOG_FILE_PATH = next(LOGS_FOLDER_PATH.glob("*_user.txt"), None) +TIMESTAMP_FORMAT = getenv("SPIFFO__ZOMBOID_LOG_TIMESTAMP_FORMAT", "%d-%m-%y %H:%M:%S.%f") log = logging.getLogger(__name__) @@ -99,7 +100,7 @@ class PlayersCog(commands.Cog): cause=re_match.group("cause"), timestamp=datetime.strptime( re_match.group("timestamp"), - "%m-%d-%y %H:%M:%S.%f" + TIMESTAMP_FORMAT ) ) await player.save() @@ -129,7 +130,7 @@ class PlayersCog(commands.Cog): player, created = await Player.get_or_create(username=re_match.group("username")) await player.open_session( - timestamp=datetime.strptime(re_match.group("timestamp"), "%d-%m-%y %H:%M:%S.%f"), + timestamp=datetime.strptime(re_match.group("timestamp"), TIMESTAMP_FORMAT), coord_x=re_match.group("x"), coord_y=re_match.group("y"), coord_z=re_match.group("z") @@ -169,7 +170,7 @@ class PlayersCog(commands.Cog): player, created = await Player.get_or_create(username=re_match.group("username")) await player.close_session( - timestamp=datetime.strptime(re_match.group("timestamp"), "%d-%m-%y %H:%M:%S.%f"), + timestamp=datetime.strptime(re_match.group("timestamp"), TIMESTAMP_FORMAT), coord_x=re_match.group("x"), coord_y=re_match.group("y"), coord_z=re_match.group("z")