Move former config.py (user-customized config) to custom_config.py file

This commit is contained in:
Simone Baracchi 2019-03-31 21:46:57 +02:00
parent ec05b1ac38
commit 41fad56d23
6 changed files with 43 additions and 15 deletions

1
.gitignore vendored
View File

@ -105,3 +105,4 @@ venv.bak/
games.db
*.swp
custom_config.py

View File

@ -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=<Telegram-token> -e RPGBOT_ADMINS=<my-id,another-id> 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
```

View File

@ -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' )

View File

@ -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'

2
db.py
View File

@ -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

View File

@ -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)"