From 9f882ab1bed17c233b81b4b7a977e121a9292e56 Mon Sep 17 00:00:00 2001 From: Benjamin Schmid Date: Sat, 28 Mar 2020 21:57:24 +0100 Subject: [PATCH] setup Docker --- .gitignore | 3 ++ Dockerfile | 10 +++++++ docker-compose.yml | 8 +++++ requirements.txt | 2 ++ .../werewolve-bot-old.py | 0 werewolve-bot.py => src/werewolve-bot.py | 29 ++++++++++--------- 6 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 requirements.txt rename werewolve-bot-old.py => src/werewolve-bot-old.py (100%) rename werewolve-bot.py => src/werewolve-bot.py (98%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e21ea3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +secrets.env +.env +venv diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf18c47 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.8-alpine3.10 + +WORKDIR /app +RUN apk add build-base + +COPY requirements.txt ./ +RUN pip install -r requirements.txt +COPY src/ ./src/ + +CMD ["python3", "src/werewolve-bot.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..14bcf73 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3.7" +services: + + werewolf: + build: . + image: werwewolf + env_file: secrets.env + restart: always diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a41d83f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +discord.py +python-dotenv diff --git a/werewolve-bot-old.py b/src/werewolve-bot-old.py similarity index 100% rename from werewolve-bot-old.py rename to src/werewolve-bot-old.py diff --git a/werewolve-bot.py b/src/werewolve-bot.py similarity index 98% rename from werewolve-bot.py rename to src/werewolve-bot.py index 64ff977..e32c6b1 100644 --- a/werewolve-bot.py +++ b/src/werewolve-bot.py @@ -7,11 +7,14 @@ from dotenv import load_dotenv load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') +if TOKEN is None: + print("Missing discord token!") + exit(1) class Role: - + def __init__(self, game): self.game = game self.copy = self @@ -52,7 +55,7 @@ class Doppelganger(Role): class Werewolf(Role): order = 2 - + def setPlayer(self, player): super().setPlayer(player) self.game.werewolf_list.append(player) @@ -65,7 +68,7 @@ class Werewolf(Role): await self.player.send("Which card in the middle do you want to look at?") self.choice = await self.player.get_choice(["left", "middle", "right"]) - await self.player.send("A card in the middle is: " + self.game.middle_card[self.choice].name()) + await self.player.send("A card in the middle is: " + self.game.middle_card[self.choice].name()) class Minion(Role): @@ -141,7 +144,7 @@ class Drunk(Role): async def phase1(self): await self.player.send("Which card from the middle do you want to take?") self.choice = await self.player.get_choice(["left", "middle", "right"]) - + async def phase5(self): self.player.day_role, self.game.middle_card[self.choice] = self.game.middle_card[self.choice], self.player.day_role #receive conformation @@ -321,7 +324,7 @@ class one_night: await self.send("The day has started") async def vote(self, options): - + # vote await self.receive('$vote') await self.send("Vote in DM") @@ -338,7 +341,7 @@ class one_night: p.vote.tally += 1 def who_dead(self, options): - + maxi = max(o.tally for o in options) dead = [p for p in self.player_list if p.tally >= maxi] for d in dead: @@ -370,7 +373,7 @@ class one_night: else: if tanner_dead: tanner_won = True - + if werewolf_dead: village_won = True @@ -422,7 +425,7 @@ class one_night: self.distribute_roles() await self.start_night() await self.send_role() - + await self.night_phases() await self.start_day() @@ -440,7 +443,7 @@ class one_night: finally: self.end() await self.send("Game ended") - + bot = discord.Client() @@ -477,9 +480,9 @@ async def on_message(message): if message.content.startswith('$werewolf'): - + # start (only one instance running) - + if werewolf_game.running: await message.channel.send("Sorry! A game is already running") return @@ -488,9 +491,9 @@ async def on_message(message): werewolf_game.set_channel(message.channel) - await werewolf_game.game() + await werewolf_game.game() return werewolf_game = one_night(bot) -bot.run(TOKEN) \ No newline at end of file +bot.run(TOKEN)