A-0.1 - Modularer Aufbau #13
@ -19,7 +19,9 @@ __version__ = '0.1.0'
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
import nest_asyncio
|
||||||
|
nest_asyncio.apply()
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major='0', minor='1', micro='0')
|
version_info = VersionInfo(major='0', minor='1', micro='0')
|
||||||
|
@ -20,6 +20,6 @@ class Application(ApplicationABC):
|
|||||||
|
|
||||||
async def main(self):
|
async def main(self):
|
||||||
try:
|
try:
|
||||||
await self._bot.run()
|
await self._bot.start_async()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, 'A fatal error occured starting the bot', e)
|
self._logger.error(__name__, 'Start failed', e)
|
||||||
|
@ -11,5 +11,13 @@
|
|||||||
"Filename": "log_$start_time.log",
|
"Filename": "log_$start_time.log",
|
||||||
"ConsoleLogLevel": "TRACE",
|
"ConsoleLogLevel": "TRACE",
|
||||||
"FileLogLevel": "TRACE"
|
"FileLogLevel": "TRACE"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Discord": {
|
||||||
|
"Token": "OTA5ODc4NDcyNzExNzU3ODQ1.YZKsXA.BXBszIF3z3wHpoe9s3pKfO3Yd5c"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Bot": {
|
||||||
|
"Prefix": "!dev-g"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
{
|
{
|
||||||
"Discord": {
|
|
||||||
"Token": ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,13 @@
|
|||||||
"Filename": "log_$start_time.log",
|
"Filename": "log_$start_time.log",
|
||||||
"ConsoleLogLevel": "ERROR",
|
"ConsoleLogLevel": "ERROR",
|
||||||
"FileLogLevel": "WARN"
|
"FileLogLevel": "WARN"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Discord": {
|
||||||
|
"Token": "OTA5ODc3NDg3MjEzODk5ODQ3.YZKrcQ.qwfDWBFdkOzxZZT10jUWG5fY2RA"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Bot": {
|
||||||
|
"Prefix": "!g"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"sh_cpl-core>=2021.10.2",
|
"sh_cpl-core>=2021.10.2",
|
||||||
"sh_cpl-query>=2021.10.2",
|
"sh_cpl-query>=2021.10.2",
|
||||||
"discord.py==1.7.3"
|
"discord.py==1.7.3",
|
||||||
|
"nest-asyncio==1.5.1"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.9.2",
|
"PythonVersion": ">=3.9.2",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from cpl_core.application import ApplicationBuilder
|
from cpl_core.application import ApplicationBuilder, ApplicationABC
|
||||||
|
|
||||||
from application import Application
|
from gismo.application import Application
|
||||||
from startup import Startup
|
from gismo.startup import Startup
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
app_builder = ApplicationBuilder(Application)
|
app_builder = ApplicationBuilder(Application)
|
||||||
app_builder.use_startup(Startup)
|
app_builder.use_startup(Startup)
|
||||||
app: Application = await app_builder.build_async()
|
app: ApplicationABC = await app_builder.build_async()
|
||||||
await app.run_async()
|
await app.run_async()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ class BotServiceABC(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self): pass
|
def __init__(self): pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def run(self): pass
|
async def start_async(self): pass
|
||||||
|
|
||||||
@abstractmethod
|
@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.abc.bot_service_abc import BotServiceABC
|
||||||
|
from gismo_core.configuration.bot_settings import BotSettings
|
||||||
from gismo_core.configuration.discord_settings import DiscordSettings
|
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
|
# 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):
|
async def start_async(self):
|
||||||
pass
|
self.run(self._discord_settings.token)
|
||||||
|
|
||||||
async def exit(self):
|
async def stop_async(self):
|
||||||
pass
|
try:
|
||||||
|
pass
|
||||||
|
# save data
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, 'Stop failed', e)
|
||||||
|
Reference in New Issue
Block a user