From b3bae047d5f2579c4b83dddd72dfdecd4b6c77e3 Mon Sep 17 00:00:00 2001 From: Jeff Laflamme Date: Thu, 27 Jun 2024 12:03:28 +0700 Subject: [PATCH] Added fortune file via ENV VAR and in data dir. Added missing config and data dir in previous commit --- README.md | 2 ++ command_handlers.py | 5 +++-- config.ini.sample => config/config.ini.sample | 0 fortunes.txt => data/fortunes.txt | 0 4 files changed, 5 insertions(+), 2 deletions(-) rename config.ini.sample => config/config.ini.sample (100%) rename fortunes.txt => data/fortunes.txt (100%) diff --git a/README.md b/README.md index 9ef5830..66ecdec 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,8 @@ Be sure you've followed the Python virtual environment steps above and activated The docker entrypoint.sh will automatically copy config.ini.sample to config.ini if you want to edit config, make sure you add the config directory as a docker volume. +Environment Variables: FORTUNE_FILE, DB_FILE, CONFIG_FILE + ```sh docker run -it --name tc2bbsmesh -v tc2bbsmesh-config:/app/config/ -v tc2bbsmesh-data:/app/data/ --device=/dev/ttyACM0 tc2-bbs-mesh ``` diff --git a/command_handlers.py b/command_handlers.py index 9a96241..f6cb351 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -1,4 +1,5 @@ import logging +import os import random import time @@ -89,7 +90,7 @@ def handle_stats_command(sender_id, interface): def handle_fortune_command(sender_id, interface): try: - with open('fortunes.txt', 'r') as file: + with open(os.getenv('FORTUNE_FILE','data/fortunes.txt'), 'r') as file: fortunes = file.readlines() if not fortunes: send_message("No fortunes available.", sender_id, interface) @@ -389,4 +390,4 @@ def handle_channel_directory_steps(sender_id, message, step, state, interface): channel_name = state['channel_name'] add_channel(channel_name, channel_url) send_message(f"Your channel '{channel_name}' has been added to the directory.", sender_id, interface) - handle_channel_directory_command(sender_id, interface) \ No newline at end of file + handle_channel_directory_command(sender_id, interface) diff --git a/config.ini.sample b/config/config.ini.sample similarity index 100% rename from config.ini.sample rename to config/config.ini.sample diff --git a/fortunes.txt b/data/fortunes.txt similarity index 100% rename from fortunes.txt rename to data/fortunes.txt