Skip to content

Add support for environment variables for Docker and automation compatibility #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
wos-discord-bot:
image: python:3.12.4-alpine
container_name: wos-discord-bot
environment:
- BOT_TOKEN=pasteHereYourDiscordBotToken
- AUTO_UPDATE=false # set to true, if you want to automatically update after restarting container
volumes:
- ./:/app
working_dir: /app
command: python main.py
restart: unless-stopped
35 changes: 26 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,25 @@ async def check_and_update_files():
if main_py_updated:
print(Fore.YELLOW + "\nNOTE: This update includes changes to main.py. Bot will restart after update." + Style.RESET_ALL)

response = input("\nDo you want to update now? (y/n): ").lower()
auto_update_env = os.getenv('AUTO_UPDATE')
if auto_update_env is not None:
auto_update = auto_update_env.lower() == 'true'
print(f"AUTO_UPDATE is set to {'true' if auto_update else 'false'}.")
else:
auto_update = None

if auto_update is True:
print("Auto-update enabled. Proceeding with update...")
response = 'y'
elif auto_update is False:
print("Auto-update disabled. Skipping update.")
response = 'n'
else:
response = input("\nDo you want to update now? (y/n): ").lower()

if response == 'y':
needs_restart = False

for file_name, new_version in updates_needed:
if file_name.strip() != 'main.py':
file_url = f"{source_url}/{file_name}"
Expand Down Expand Up @@ -241,14 +256,16 @@ async def on_command_error(self, ctx, error):

init(autoreset=True)

bot_token = os.getenv('BOT_TOKEN')
token_file = 'bot_token.txt'
if not os.path.exists(token_file):
bot_token = input("Enter the bot token: ")
with open(token_file, 'w') as f:
f.write(bot_token)
else:
with open(token_file, 'r') as f:
bot_token = f.read().strip()
if not bot_token:
if not os.path.exists(token_file):
bot_token = input("Enter the bot token: ")
with open(token_file, 'w') as f:
f.write(bot_token)
else:
with open(token_file, 'r') as f:
bot_token = f.read().strip()

if not os.path.exists('db'):
os.makedirs('db')
Expand Down