Skip to content

Commit

Permalink
changed the way how the bot detects it is run via docker, should now …
Browse files Browse the repository at this point in the history
…work more reliable and easier to test with
  • Loading branch information
Der-Eddy committed Jun 6, 2021
1 parent 0c2f3f3 commit f65dcd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ LABEL org.opencontainers.image.source https://github.com/der-eddy/discord_bot
#distroless creates automatically a nonroot user with uid 65532:65532
USER nonroot

CMD [ "main.py" ]
CMD [ "main.py", "docker"]
17 changes: 9 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from discord.ext import commands
import loadconfig

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

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

class ShinobuBot(commands.AutoShardedBot):
def __init__(self):
def __init__(self, docker):
intents = discord.Intents.default()
intents.presences = True
intents.members = True
self.docker = docker
super().__init__(command_prefix=loadconfig.__prefix__, description=description, intents=intents)

async def _randomGame(self):
Expand All @@ -47,11 +48,6 @@ async def on_ready(self):
else:
self.dev = False

if os.environ.get('PYTHONUNBUFFERED') == '1':
self.docker = True
else:
self.docker = False

log.info('Logged in as')
log.info(f'Bot-Name: {self.user.name} | ID: {self.user.id}')
log.info(f'Dev Mode: {self.dev} | Docker: {self.docker}')
Expand Down Expand Up @@ -177,5 +173,10 @@ async def on_command_error(self, error, ctx):
pass

if __name__ == '__main__':
bot = ShinobuBot()
sys.argv = ''.join(sys.argv[1:])
if sys.argv.lower() == 'docker':
docker = True
else:
docker = False
bot = ShinobuBot(docker)
bot.run(loadconfig.__token__)

0 comments on commit f65dcd4

Please sign in to comment.