Skip to content

Commit f65dcd4

Browse files
committed
changed the way how the bot detects it is run via docker, should now work more reliable and easier to test with
1 parent 0c2f3f3 commit f65dcd4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ LABEL org.opencontainers.image.source https://github.com/der-eddy/discord_bot
2828
#distroless creates automatically a nonroot user with uid 65532:65532
2929
USER nonroot
3030

31-
CMD [ "main.py" ]
31+
CMD [ "main.py", "docker"]

main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from discord.ext import commands
1616
import loadconfig
1717

18-
__version__ = '1.5.3'
18+
__version__ = '1.5.4'
1919
description = '''Der-Eddys anime discord bot, developed with discord.py\n
2020
A full list of all commands are available here: https://github.com/Der-Eddy/discord_bot#commands-list'''
2121

@@ -26,10 +26,11 @@ def _currenttime():
2626
return datetime.datetime.now(timezone(loadconfig.__timezone__)).strftime('%H:%M:%S')
2727

2828
class ShinobuBot(commands.AutoShardedBot):
29-
def __init__(self):
29+
def __init__(self, docker):
3030
intents = discord.Intents.default()
3131
intents.presences = True
3232
intents.members = True
33+
self.docker = docker
3334
super().__init__(command_prefix=loadconfig.__prefix__, description=description, intents=intents)
3435

3536
async def _randomGame(self):
@@ -47,11 +48,6 @@ async def on_ready(self):
4748
else:
4849
self.dev = False
4950

50-
if os.environ.get('PYTHONUNBUFFERED') == '1':
51-
self.docker = True
52-
else:
53-
self.docker = False
54-
5551
log.info('Logged in as')
5652
log.info(f'Bot-Name: {self.user.name} | ID: {self.user.id}')
5753
log.info(f'Dev Mode: {self.dev} | Docker: {self.docker}')
@@ -177,5 +173,10 @@ async def on_command_error(self, error, ctx):
177173
pass
178174

179175
if __name__ == '__main__':
180-
bot = ShinobuBot()
176+
sys.argv = ''.join(sys.argv[1:])
177+
if sys.argv.lower() == 'docker':
178+
docker = True
179+
else:
180+
docker = False
181+
bot = ShinobuBot(docker)
181182
bot.run(loadconfig.__token__)

0 commit comments

Comments
 (0)