Merge pull request '2022.10.1' (#100) from 2022.10.1 into 2022.10

Reviewed-on: #100
This commit is contained in:
Sven Heidemann 2022-09-11 19:30:39 +02:00
commit 3c5ca594d5
34 changed files with 128 additions and 150 deletions

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -29,4 +29,4 @@ from .startup_abc import StartupABC
from .startup_extension_abc import StartupExtensionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -35,4 +35,4 @@ from .validator_abc import ValidatorABC
from .variable_argument import VariableArgument
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -28,4 +28,4 @@ from .foreground_color_enum import ForegroundColorEnum
from .spinner_thread import SpinnerThread
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -3,8 +3,8 @@
"Name": "cpl-core",
"Version": {
"Major": "2022",
"Minor": "7",
"Micro": "0.post5"
"Minor": "10",
"Micro": "1"
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -16,16 +16,16 @@
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"art==5.6",
"colorama==0.4.4",
"art==5.7",
"colorama==0.4.5",
"mysql-connector==2.2.9",
"psutil==5.9.0",
"psutil==5.9.2",
"packaging==21.3",
"pynput==1.7.6",
"setuptools==62.1.0",
"tabulate==0.8.9",
"setuptools==65.3.0",
"tabulate==0.8.10",
"termcolor==1.1.0",
"watchdog==2.1.7",
"watchdog==2.1.9",
"wheel==0.37.1"
],
"DevDependencies": [

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -26,4 +26,4 @@ from .database_settings import DatabaseSettings
from .table_abc import TableABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -25,4 +25,4 @@ from .database_connection import DatabaseConnection
from .database_connection_abc import DatabaseConnectionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -25,4 +25,4 @@ from .database_context import DatabaseContext
from .database_context_abc import DatabaseContextABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -31,4 +31,4 @@ from .service_provider import ServiceProvider
from .service_provider_abc import ServiceProviderABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -26,4 +26,4 @@ from .environment_name_enum import EnvironmentNameEnum
from .application_environment import ApplicationEnvironment
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -28,4 +28,4 @@ from .logging_settings import LoggingSettings
from .logging_settings_name_enum import LoggingSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -28,4 +28,4 @@ from .email_client_settings import EMailClientSettings
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.pipes'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -30,4 +30,4 @@ from .to_camel_case_pipe import ToCamelCasePipe
from .to_snake_case_pipe import ToSnakeCasePipe
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -25,4 +25,4 @@ from .time_format_settings import TimeFormatSettings
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post5'
__version__ = '2022.10.1'
from collections import namedtuple
@ -26,4 +26,4 @@ from .string import String
from .pip import Pip
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post5')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -55,4 +55,4 @@ def get_discord_collection(services: 'ServiceCollectionABC') -> 'DiscordCollecti
# build-ignore-end
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.application'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -24,4 +24,4 @@ from collections import namedtuple
from .discord_bot_application_abc import DiscordBotApplicationABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.command'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC
from .discord_commands_meta import DiscordCogMeta
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.configuration'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -24,4 +24,4 @@ from collections import namedtuple
from .discord_bot_settings import DiscordBotSettings
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -3,8 +3,8 @@
"Name": "cpl-discord",
"Version": {
"Major": "2022",
"Minor": "7",
"Micro": "0.post4"
"Minor": "10",
"Micro": "1"
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -17,7 +17,7 @@
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"cpl-core>=2022.7.0.post2",
"discord.py==1.7.3",
"discord.py==2.0.1",
"cpl-query==2022.7.0"
],
"DevDependencies": [

View File

@ -42,9 +42,6 @@ from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC
from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC
from cpl_discord.events.on_ready_abc import OnReadyABC
from cpl_discord.events.on_relationship_add_abc import OnRelationshipAddABC
from cpl_discord.events.on_relationship_remove_abc import OnRelationshipRemoveABC
from cpl_discord.events.on_relationship_update_abc import OnRelationshipUpdateABC
from cpl_discord.events.on_resume_abc import OnResumeABC
from cpl_discord.events.on_typing_abc import OnTypingABC
from cpl_discord.events.on_user_update_abc import OnUserUpdateABC
@ -95,9 +92,6 @@ class DiscordEventTypesEnum(Enum):
on_reaction_clear_emoji = OnReactionClearEmojiABC
on_reaction_remove = OnReactionRemoveABC
on_ready = OnReadyABC
on_relationship_add = OnRelationshipAddABC
on_relationship_remove = OnRelationshipRemoveABC
on_relationship_update = OnRelationshipUpdateABC
on_resume = OnResumeABC
on_typing = OnTypingABC
on_user_update = OnUserUpdateABC

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.events'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -62,9 +62,6 @@ from .on_reaction_clear_abc import OnReactionClearABC
from .on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
from .on_reaction_remove_abc import OnReactionRemoveABC
from .on_ready_abc import OnReadyABC
from .on_relationship_add_abc import OnRelationshipAddABC
from .on_relationship_remove_abc import OnRelationshipRemoveABC
from .on_relationship_update_abc import OnRelationshipUpdateABC
from .on_resume_abc import OnResumeABC
from .on_typing_abc import OnTypingABC
from .on_user_update_abc import OnUserUpdateABC
@ -72,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC
from .on_webhooks_update_abc import OnWebhooksUpdateABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -1,11 +0,0 @@
from abc import ABC, abstractmethod
import discord
class OnRelationshipAddABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
async def on_relationship_add(self, relationship: discord.Relationship): pass

View File

@ -1,11 +0,0 @@
from abc import ABC, abstractmethod
import discord
class OnRelationshipRemoveABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
async def on_relationship_remove(self, relationship: discord.Relationship): pass

View File

@ -1,12 +0,0 @@
from abc import ABC, abstractmethod
import discord
class OnRelationshipUpdateABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
async def on_relationship_update(
self, before: discord.Relationship, after: discord.Relationship): pass

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.service'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
__version__ = '2022.7.0.post4'
__version__ = '2022.10.1'
from collections import namedtuple
@ -29,4 +29,4 @@ from .discord_service import DiscordService
from .discord_service_abc import DiscordServiceABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
version_info = VersionInfo(major='2022', minor='10', micro='1')

View File

@ -21,29 +21,37 @@ class DiscordBotService(DiscordBotServiceABC):
discord_service: DiscordServiceABC
):
# services
self._config = config
self._logger = logger
self._env = env
self._logging_st = logging_st
self._discord_service = discord_service
# settings
if discord_bot_settings is None:
self._discord_settings = DiscordBotSettings()
token = config.get_configuration('TOKEN')
if token is None:
raise Exception('You have to configure discord token by appsettings or environment variables')
prefix = config.get_configuration('PREFIX')
self._discord_settings.from_dict({
'Token': token,
'Prefix': prefix if prefix is not None else '! '
})
else:
self._discord_settings = discord_bot_settings
self._discord_settings = self._get_settings(discord_bot_settings)
# setup super
DiscordBotServiceABC.__init__(self, command_prefix=self._discord_settings.prefix, help_command=None, intents=discord.Intents().all())
@staticmethod
def _is_string_invalid(x):
return x is None or x == ''
def _get_settings(self, settings_from_config: DiscordBotSettings) -> DiscordBotSettings:
new_settings = DiscordBotSettings()
token = settings_from_config.token
prefix = settings_from_config.prefix
env_token = self._config.get_configuration('TOKEN')
env_prefix = self._config.get_configuration('PREFIX')
new_settings.from_dict({
'Token': env_token if token is None or token == '' else token,
'Prefix': ('! ' if self._is_string_invalid(env_prefix) else env_prefix) if self._is_string_invalid(prefix) else prefix
})
if new_settings.token is None or new_settings.token == '':
raise Exception('You have to configure discord token by appsettings or environment variables')
return new_settings
async def start_async(self):
self._logger.trace(__name__, 'Try to connect to discord')
await self.start(self._discord_settings.token)
@ -63,6 +71,9 @@ class DiscordBotService(DiscordBotServiceABC):
if self._logging_st.console.value >= LoggingLevelEnum.INFO.value:
Console.banner(self._env.application_name if self._env.application_name != '' else 'A bot')
self._discord_service.init(self)
await self._discord_service.init(self)
await self.wait_until_ready()
await self.tree.sync()
self._logger.debug(__name__, f'Finished syncing commands')
await self._discord_service.on_ready()

View File

@ -3,9 +3,8 @@ from typing import Optional, Sequence, Union, Type
import discord
from discord.ext import commands
from discord.ext.commands import Context, CommandError
from discord.ext.commands import Context, CommandError, Cog, Command
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.logging import LoggerABC
from cpl_core.utils import String
@ -52,9 +51,6 @@ from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC
from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC
from cpl_discord.events.on_ready_abc import OnReadyABC
from cpl_discord.events.on_relationship_add_abc import OnRelationshipAddABC
from cpl_discord.events.on_relationship_remove_abc import OnRelationshipRemoveABC
from cpl_discord.events.on_relationship_update_abc import OnRelationshipUpdateABC
from cpl_discord.events.on_resume_abc import OnResumeABC
from cpl_discord.events.on_typing_abc import OnTypingABC
from cpl_discord.events.on_user_update_abc import OnUserUpdateABC
@ -97,20 +93,20 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
except Exception as e:
self._logger.error(__name__, f'Cannot execute {func_name} of {type(event_instance).__name__}', e)
def init(self, bot: commands.Bot):
async def init(self, bot: commands.Bot):
try:
bot.add_cog(self)
await bot.add_cog(self)
except Exception as e:
self._logger.error(__name__, f'{type(self).__name__} initialization failed', e)
try:
for command_type in self._collection.get_commands():
self._logger.trace(__name__, f'Register command {command_type.__name__}')
command = self._services.get_service(command_type)
command: Cog = self._services.get_service(command_type)
if command is None:
self._logger.warn(__name__, f'Instance of {command_type.__name__} not found')
continue
bot.add_cog(command)
await bot.add_cog(command)
except Exception as e:
self._logger.error(__name__, f'Registration of commands failed', e)
@ -352,18 +348,3 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
async def on_group_remove(self, channel: discord.GroupChannel, user: discord.User):
self._logger.trace(__name__, f'Received on_group_remove:\n\t{channel}\n\t{user}')
await self._handle_event(OnGroupRemoveABC, channel, user)
@commands.Cog.listener()
async def on_relationship_add(self, relationship: discord.Relationship):
self._logger.trace(__name__, f'Received on_relationship_add:\n\t{relationship}')
await self._handle_event(OnRelationshipAddABC, relationship)
@commands.Cog.listener()
async def on_relationship_remove(self, relationship: discord.Relationship):
self._logger.trace(__name__, f'Received on_relationship_remove:\n\t{relationship}')
await self._handle_event(OnRelationshipRemoveABC, relationship)
@commands.Cog.listener()
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship):
self._logger.trace(__name__, f'Received on_relationship_update:\n\t{before}\n\t{after}')
await self._handle_event(OnRelationshipUpdateABC, before, after)

View File

@ -157,12 +157,3 @@ class DiscordServiceABC(ABC):
@abstractmethod
async def on_group_remove(self, chhanel: discord.GroupChannel, user: discord.User): pass
@abstractmethod
async def on_relationship_add(self, relationship: discord.Relationship): pass
@abstractmethod
async def on_relationship_remove(self, relationship: discord.Relationship): pass
@abstractmethod
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship): pass

View File

@ -10,5 +10,9 @@
"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

@ -20,8 +20,9 @@ class PingCommand(DiscordCommandABC):
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@commands.command()
@commands.hybrid_command()
async def ping(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.send('Pong')

View File

@ -0,0 +1,31 @@
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.hybrid_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()
if ctx.interaction is None:
return
await ctx.interaction.response.send_message('Purged this channel xD')