From 41fad56d233b0fb4155bce9a85bfbef5c077aefa Mon Sep 17 00:00:00 2001 From: Simone Baracchi Date: Sun, 31 Mar 2019 21:46:57 +0200 Subject: [PATCH] Move former config.py (user-customized config) to custom_config.py file --- .gitignore | 1 + README.md | 11 +++++-- config.py | 33 ++++++++++++++----- config.example.py => custom_config.example.py | 5 +++ db.py | 2 +- install.sh | 6 ++-- 6 files changed, 43 insertions(+), 15 deletions(-) rename config.example.py => custom_config.example.py (57%) diff --git a/.gitignore b/.gitignore index 2cb4e08..382b0bd 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ venv.bak/ games.db *.swp +custom_config.py diff --git a/README.md b/README.md index 25868e1..abddd9c 100644 --- a/README.md +++ b/README.md @@ -93,14 +93,21 @@ Delete an item (or another a character sheet entry). ## Run in docker Build docker container: - ``` docker build . -t rpgbot ``` Run container: +``` + docker run -t -v /your-preferred-path/data:/data -e RPGBOT_TOKEN= -e RPGBOT_ADMINS= rpgbot +``` + +## Run without docker + +Configure `custom_config.py` manually or through `install.py` and then run: ``` - docker run -t -v /your-preferred-path/data:/data -e RPGBOT_TOKEN=Your:Token -e RPGBOT_ADMINS=my-id,another-id rpgbot +# python3 main.py ``` + diff --git a/config.py b/config.py index 30faddb..9e2ad90 100644 --- a/config.py +++ b/config.py @@ -1,14 +1,29 @@ -# Example config file import os -admins = os.environ.get('RPGBOT_ADMINS', '') -if admins is None: - raise Exception('No Admins Provided') +admins = None +bot_token = None +db_file = None +log_file = None -admins = admins.split(',') +try: + # Import config from custom_config if present + import custom_config + admins = custom_config.admins + bot_token = custom_config.bot_token + db_file = custom_config.db_file + log_file = custom_config.log_file +except: + # Import config from env vars + admins = os.environ.get('RPGBOT_ADMINS', '') + if admins is None: + raise Exception('No Admins Provided') -bot_token = os.environ.get('RPGBOT_TOKEN') -if bot_token is None: - raise Exception('No Token Provided') + admins = admins.split(',') -sqlite_path = os.environ.get('RPGBOT_SQLITE_PATH', '/data/games.db' ) + bot_token = os.environ.get('RPGBOT_TOKEN') + if bot_token is None: + raise Exception('No Token Provided') + + db_file = os.environ.get('RPGBOT_DB_FILE', '/data/games.db' ) + + log_file = os.environ.get('RPGBOT_LOG', '/data/service.log' ) diff --git a/config.example.py b/custom_config.example.py similarity index 57% rename from config.example.py rename to custom_config.example.py index 35e51b7..32be38a 100644 --- a/config.example.py +++ b/custom_config.example.py @@ -6,3 +6,8 @@ bot_token = 'MY-TG-BOT-TOKEN' # Telegram admin id admins = [ADMIN-ID] +# db file name +db_file = 'games.db' + +# log file name +log_file = 'service.log' diff --git a/db.py b/db.py index a6849ea..2c1a09a 100644 --- a/db.py +++ b/db.py @@ -1,7 +1,7 @@ import sqlite3 import config -db_name = config.sqlite_path +db_name = config.db_file db_version = 1 ROLE_PLAYER = 10 ROLE_MASTER = 20 diff --git a/install.sh b/install.sh index 83ca0d9..07ef7df 100755 --- a/install.sh +++ b/install.sh @@ -17,9 +17,9 @@ rm tempconfig.py echo "Enter your Telegram ID. This will be the default admin user." read -r SENDER_ID -cp config.example.py config.py -sed -i s"/MY-TG-BOT-TOKEN/$TG_BOT_TOKEN/" config.py -sed -i s"/MY-SENDER-ID-LIST/$SENDER_ID/" config.py +cp custom_config.example.py custom_config.py +sed -i s"/MY-TG-BOT-TOKEN/$TG_BOT_TOKEN/" custom_config.py +sed -i s"/MY-SENDER-ID-LIST/$SENDER_ID/" custom_config.py printf "\n\n--------------------------------\n\n" echo "Do you want to configure the daemon with systemctl? (y/n)"