Added functionality to connect to discord web api
This commit is contained in:
@@ -5,9 +5,9 @@ class BotServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
async def run(self): pass
|
||||
|
||||
async def start_async(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def exit(self): pass
|
||||
async def stop_async(self): pass
|
||||
|
23
src/gismo_core/configuration/bot_settings.py
Normal file
23
src/gismo_core/configuration/bot_settings.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class BotSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._prefix: str = ''
|
||||
|
||||
@property
|
||||
def prefix(self) -> str:
|
||||
return self._prefix
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._prefix = settings['Prefix']
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
@@ -1,15 +1,26 @@
|
||||
from cpl_core.logging import LoggerABC
|
||||
from discord.ext import commands
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.configuration.bot_settings import BotSettings
|
||||
from gismo_core.configuration.discord_settings import DiscordSettings
|
||||
|
||||
|
||||
class BotService(BotServiceABC):
|
||||
class BotService(BotServiceABC, commands.Bot):
|
||||
|
||||
def __init__(self, discord_settings: DiscordSettings):
|
||||
def __init__(self, logger: LoggerABC, discord_settings: DiscordSettings, bot_settings: BotSettings):
|
||||
self._logger = logger
|
||||
self._discord_settings = discord_settings
|
||||
self._bot_settings: BotSettings = bot_settings
|
||||
# setup self
|
||||
commands.Bot.__init__(self, command_prefix=discord_settings.bot.prefix, help_command=None)
|
||||
commands.Bot.__init__(self, command_prefix=bot_settings.prefix, help_command=None)
|
||||
|
||||
async def run(self):
|
||||
pass
|
||||
async def start_async(self):
|
||||
self.run(self._discord_settings.token)
|
||||
|
||||
async def exit(self):
|
||||
pass
|
||||
async def stop_async(self):
|
||||
try:
|
||||
pass
|
||||
# save data
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Stop failed', e)
|
||||
|
Reference in New Issue
Block a user