From 98de64b7aab2b71b643423d0e975178bba9bb474 Mon Sep 17 00:00:00 2001 From: c0de Date: Thu, 10 Nov 2022 22:41:42 -0600 Subject: [PATCH] Add new game manager --- GhostBallBot/game/manager.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 GhostBallBot/game/manager.py diff --git a/GhostBallBot/game/manager.py b/GhostBallBot/game/manager.py new file mode 100644 index 0000000..732428f --- /dev/null +++ b/GhostBallBot/game/manager.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# Copyright 2022 - c0de +# Licensed under the MIT License (https://opensource.org/licenses/MIT) + +# pylint: disable=no-member + +""" + A Context Manager / State Machine that keeps track of + a single game instance (there should only be one) in a + Discord channel +""" + +from database.models import database, GameModel as Game + +class BaseGameManager: + """Base Game Manager for each Game Manager class to inherit""" + + def __init__(self): + # Only one game should run at at time + self.is_running = False + + self.commands = [] + + self.game = Game + + # Discord message + self.message = None + + # Discord client instance + self.discord = None + + def __enter__(self): + """ + Allows use of `with Game() as game` for try/except statements + (https://peps.python.org/pep-0343/) + """ + + database.connect() + return self + + def __exit__(self, exception_type, exception_value, exception_traceback): + """ + Automagically close the database + when this class has ended execution + """ + database.close() +