From f9a5a8023d9442e9e8057db5d7388df008df933a Mon Sep 17 00:00:00 2001 From: c0de Date: Thu, 10 Nov 2022 22:42:08 -0600 Subject: [PATCH] Add new game manager --- GhostBallBot/game/new_game.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 GhostBallBot/game/new_game.py diff --git a/GhostBallBot/game/new_game.py b/GhostBallBot/game/new_game.py new file mode 100644 index 0000000..8176b81 --- /dev/null +++ b/GhostBallBot/game/new_game.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# Copyright 2022 - c0de +# Licensed under the MIT License (https://opensource.org/licenses/MIT) + +# pylint: disable=missing-module-docstring + +import uuid + +from database.models import GameModel as Game +from game.manager import BaseGameManager + +class NewGameManager(BaseGameManager): + """Commands that run at the start of a new game""" + + def __init__(self): + self.commands.append(("braveball", self.start)) + super().__init__() + + async def start(self): + """ + Start command - Starts a new game if there isn't already one running + """ + + if self.is_running: + return await self.message.channel.send("A game is already running") + + self.is_running = True + + # game.pitch_value is unknown at the start of the game + self.game = Game.create(game_id=uuid.uuid4(), server_id=self.message.channel.id) + + await self.message.channel.send("Send me your guesses with !guess ")