2022-11-12 02:06:14 +00:00
|
|
|
#!/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
|
|
|
|
|
2023-03-02 23:48:35 +00:00
|
|
|
import logging
|
|
|
|
|
2022-11-12 02:06:14 +00:00
|
|
|
from database.models import database, GameModel as Game
|
|
|
|
|
2022-11-12 02:07:23 +00:00
|
|
|
|
2022-11-12 02:06:14 +00:00
|
|
|
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
|
|
|
|
|
2023-03-02 23:48:35 +00:00
|
|
|
logger = logging.getLogger()
|
|
|
|
console = logging.StreamHandler()
|
|
|
|
|
|
|
|
format_str = '%(asctime)s\t%(levelname)s -- %(processName)s %(filename)s:%(lineno)s -- %(message)s'
|
|
|
|
console.setFormatter(logging.Formatter(format_str))
|
|
|
|
|
|
|
|
logger.addHandler(console)
|
|
|
|
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
self.logger = logger
|
|
|
|
|
2022-11-12 02:06:14 +00:00
|
|
|
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
|
|
|
|
"""
|
2022-11-12 02:07:23 +00:00
|
|
|
database.close()
|