setup Docker

This commit is contained in:
Benjamin Schmid 2020-03-28 21:57:24 +01:00
parent 475a41abcc
commit 9f882ab1be
6 changed files with 39 additions and 13 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
secrets.env
.env
venv

10
Dockerfile Normal file
View File

@ -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"]

8
docker-compose.yml Normal file
View File

@ -0,0 +1,8 @@
version: "3.7"
services:
werewolf:
build: .
image: werwewolf
env_file: secrets.env
restart: always

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
discord.py
python-dotenv

View File

@ -7,11 +7,14 @@ from dotenv import load_dotenv
load_dotenv() load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN') TOKEN = os.getenv('DISCORD_TOKEN')
if TOKEN is None:
print("Missing discord token!")
exit(1)
class Role: class Role:
def __init__(self, game): def __init__(self, game):
self.game = game self.game = game
self.copy = self self.copy = self
@ -52,7 +55,7 @@ class Doppelganger(Role):
class Werewolf(Role): class Werewolf(Role):
order = 2 order = 2
def setPlayer(self, player): def setPlayer(self, player):
super().setPlayer(player) super().setPlayer(player)
self.game.werewolf_list.append(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?") 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"]) 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): class Minion(Role):
@ -141,7 +144,7 @@ class Drunk(Role):
async def phase1(self): async def phase1(self):
await self.player.send("Which card from the middle do you want to take?") await self.player.send("Which card from the middle do you want to take?")
self.choice = await self.player.get_choice(["left", "middle", "right"]) self.choice = await self.player.get_choice(["left", "middle", "right"])
async def phase5(self): async def phase5(self):
self.player.day_role, self.game.middle_card[self.choice] = self.game.middle_card[self.choice], self.player.day_role self.player.day_role, self.game.middle_card[self.choice] = self.game.middle_card[self.choice], self.player.day_role
#receive conformation #receive conformation
@ -321,7 +324,7 @@ class one_night:
await self.send("The day has started") await self.send("The day has started")
async def vote(self, options): async def vote(self, options):
# vote # vote
await self.receive('$vote') await self.receive('$vote')
await self.send("Vote in DM") await self.send("Vote in DM")
@ -338,7 +341,7 @@ class one_night:
p.vote.tally += 1 p.vote.tally += 1
def who_dead(self, options): def who_dead(self, options):
maxi = max(o.tally for o in options) maxi = max(o.tally for o in options)
dead = [p for p in self.player_list if p.tally >= maxi] dead = [p for p in self.player_list if p.tally >= maxi]
for d in dead: for d in dead:
@ -370,7 +373,7 @@ class one_night:
else: else:
if tanner_dead: if tanner_dead:
tanner_won = True tanner_won = True
if werewolf_dead: if werewolf_dead:
village_won = True village_won = True
@ -422,7 +425,7 @@ class one_night:
self.distribute_roles() self.distribute_roles()
await self.start_night() await self.start_night()
await self.send_role() await self.send_role()
await self.night_phases() await self.night_phases()
await self.start_day() await self.start_day()
@ -440,7 +443,7 @@ class one_night:
finally: finally:
self.end() self.end()
await self.send("Game ended") await self.send("Game ended")
bot = discord.Client() bot = discord.Client()
@ -477,9 +480,9 @@ async def on_message(message):
if message.content.startswith('$werewolf'): if message.content.startswith('$werewolf'):
# start (only one instance running) # start (only one instance running)
if werewolf_game.running: if werewolf_game.running:
await message.channel.send("Sorry! A game is already running") await message.channel.send("Sorry! A game is already running")
return return
@ -488,9 +491,9 @@ async def on_message(message):
werewolf_game.set_channel(message.channel) werewolf_game.set_channel(message.channel)
await werewolf_game.game() await werewolf_game.game()
return return
werewolf_game = one_night(bot) werewolf_game = one_night(bot)
bot.run(TOKEN) bot.run(TOKEN)