First migrations

This commit is contained in:
2022-09-10 10:27:31 +02:00
parent 88e83db330
commit 92ed684866
15 changed files with 81 additions and 109 deletions

View File

@@ -6,9 +6,13 @@
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
},
"LoggingSettings": {
"Path": "logs/",
"Filename": "log_dev.log",
"ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE"
}
"Path": "logs/",
"Filename": "log_dev.log",
"ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE"
},
"DiscordBotSettings": {
"Token": "",
"Prefix": "!cd "
}
}

View File

@@ -1,7 +1,7 @@
import asyncio
from typing import Optional
from cpl_core.application import ApplicationBuilder
from cpl_core.application import ApplicationBuilder, ApplicationABC
from discord_bot.application import Application
from discord_bot.startup import Startup
@@ -15,7 +15,7 @@ class Main:
async def main(self):
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
self._app: Application = await app_builder.build_async()
self._app: ApplicationABC = await app_builder.build_async()
await self._app.run_async()
async def stop(self):

View File

@@ -7,6 +7,7 @@ from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
from modules.hello_world.on_ready_event import OnReadyEvent
from modules.hello_world.on_ready_test_event import OnReadyTestEvent
from modules.hello_world.ping_command import PingCommand
from modules.hello_world.purge_command import PurgeCommand
class Startup(StartupABC):
@@ -28,5 +29,6 @@ class Startup(StartupABC):
dc_collection.add_event(DiscordEventTypesEnum.on_ready.value, OnReadyEvent)
dc_collection.add_event(DiscordEventTypesEnum.on_ready.value, OnReadyTestEvent)
dc_collection.add_command(PingCommand)
dc_collection.add_command(PurgeCommand)
return services.build_service_provider()

View File

@@ -25,3 +25,4 @@ class PingCommand(DiscordCommandABC):
self._logger.debug(__name__, f'Received command ping {ctx}')
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
self._logger.trace(__name__, f'Finished ping command')
await ctx.send('Pong')

View File

@@ -0,0 +1,28 @@
from discord.ext import commands
from discord.ext.commands import Context
from cpl_core.logging import LoggerABC
from cpl_discord.command.discord_command_abc import DiscordCommandABC
from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
class PurgeCommand(DiscordCommandABC):
def __init__(
self,
logger: LoggerABC,
bot: DiscordBotServiceABC,
):
DiscordCommandABC.__init__(self)
self._logger = logger
self._bot = bot
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@commands.command()
async def purge(self, ctx: Context):
self._logger.debug(__name__, f'Received command ping {ctx}')
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
self._logger.trace(__name__, f'Finished ping command')
await ctx.channel.purge()