Fix circular import issue

This commit is contained in:
c0de 2022-11-11 20:06:14 -06:00
parent 03fcc5ef52
commit 16a419f558
7 changed files with 45 additions and 41 deletions

40
GhostBallBot/game/base.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
# Copyright 2022 - c0de <c0de@c0de.dev>
# Licensed under the MIT License (https://opensource.org/licenses/MIT)
# pylint: disable=missing-module-docstring
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()

View File

@ -7,7 +7,7 @@
import datetime import datetime
from database.models import GameModel as Game, GuessModel as Guess from database.models import GameModel as Game, GuessModel as Guess
from game.manager import BaseGameManager from game.base import BaseGameManager
from game.process_guess import ProcessGuess from game.process_guess import ProcessGuess

View File

@ -7,7 +7,7 @@
import uuid import uuid
from database.models import PlayerModel as Player, GuessModel as Guess from database.models import PlayerModel as Player, GuessModel as Guess
from game.manager import BaseGameManager from game.base import BaseGameManager
class GuessManager(BaseGameManager): class GuessManager(BaseGameManager):

View File

@ -4,7 +4,7 @@
# pylint: disable=missing-module-docstring # pylint: disable=missing-module-docstring
from game.manager import BaseGameManager from game.base import BaseGameManager
class HelpManager(BaseGameManager): class HelpManager(BaseGameManager):

View File

@ -10,8 +10,6 @@
Discord channel Discord channel
""" """
from database.models import database, GameModel as Game
from game.new_game import NewGameManager from game.new_game import NewGameManager
from game.end_game import EndGameManager from game.end_game import EndGameManager
from game.guess import GuessManager from game.guess import GuessManager
@ -19,40 +17,6 @@ from game.points import PointsManager
from game.help import HelpManager from game.help import HelpManager
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()
class GameManager( class GameManager(
NewGameManager, EndGameManager, GuessManager, PointsManager, HelpManager NewGameManager, EndGameManager, GuessManager, PointsManager, HelpManager
): ):

View File

@ -7,7 +7,7 @@
import uuid import uuid
from database.models import GameModel as Game from database.models import GameModel as Game
from game.manager import BaseGameManager from game.base import BaseGameManager
class NewGameManager(BaseGameManager): class NewGameManager(BaseGameManager):

View File

@ -5,7 +5,7 @@
# pylint: disable=not-an-iterable,missing-module-docstring # pylint: disable=not-an-iterable,missing-module-docstring
from database.models import PlayerModel as Player from database.models import PlayerModel as Player
from game.manager import BaseGameManager from game.base import BaseGameManager
class PointsManager(BaseGameManager): class PointsManager(BaseGameManager):