Skip to content

Commit 9daa1a6

Browse files
authored
Merge pull request #9 from f11y11/auto_updates
Multiple fixes, logging consistency and removal of auto updates
2 parents 5fda50a + 529e1ef commit 9daa1a6

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

bot/bot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
case_insensitive=True,
2121
intents=intents,
2222
help_command=None,
23-
allowed_mentions=am,
24-
owner_ids=[893843824894435370])
23+
allowed_mentions=am)
2524

2625

2726
@bot.event

config.yml-template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ logging:
2828
# true or false determining if logs should be printed to stderr
2929
console: false
3030

31-
auto_updates: false
32-
3331
# set to true for faster loading of player avatars that can be outdated at times
3432
# set to false for non-cached, up-to-date player avatars
3533
cache_avatars: true

main.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import logging
22
import os
33
import asyncio
4-
import subprocess
5-
import sys
64

75
from dotenv import load_dotenv
86
from bot.bot import main, config
97

8+
logging_data = config.get('logging')
9+
load_dotenv()
1010

11-
if logging_data := config.get('logging'):
11+
if __name__ == '__main__':
1212
if logging_level := logging_data.get('level'):
1313
if logging_level and logging_level not in (
1414
'error',
@@ -18,30 +18,19 @@
1818
):
1919
logging_level = 'info'
2020

21-
if logging_filename := logging_data.get('filename'):
22-
if not logging_filename.endswith('.log'):
23-
logging_filename = logging_filename + '.log'
24-
25-
logging_console: bool = logging_data.get('console', False)
26-
27-
logging.basicConfig(level=getattr(logging, logging_level.upper()), filename=logging_filename)
28-
if logging_console:
29-
logging.getLogger().addHandler(logging.StreamHandler())
21+
if logging_filename := logging_data.get('filename'):
22+
if not logging_filename.endswith('.log'):
23+
logging_filename = logging_filename + '.log'
3024

31-
if not logging_console and not logging_filename:
32-
print('''
33-
You have enabled logging but set left both console and filename blank.
34-
Nothing will be printed to the console or written to a file.
35-
''')
25+
if logging_data.get('console', False):
26+
logging.getLogger().addHandler(logging.StreamHandler())
27+
elif not logging_filename:
28+
print('''
29+
You have enabled logging but set left both console and filename blank.
30+
Nothing will be printed to the console or written to a file.
31+
''')
3632

37-
load_dotenv()
38-
39-
if __name__ == '__main__':
40-
if config.get('auto_updates', False):
41-
pull = str(subprocess.check_output(['git', 'pull']), 'UTF-8')
42-
if 'up to date' not in pull:
43-
logging.info('Auto-update has installed the latest version. Restarting...')
44-
os.execv(sys.executable, ['python'] + sys.argv)
33+
logging.basicConfig(level=getattr(logging, logging_level.upper()), filename=logging_filename)
4534

4635
if TOKEN := os.environ.get('TOKEN'):
4736
logging.info('Starting bot')

0 commit comments

Comments
 (0)