Added on_error to event types enum
This commit is contained in:
parent
71efbd1b42
commit
b2ce8a6924
@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -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.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -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.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -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.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "7",
|
||||
"Micro": "0.post2"
|
||||
"Micro": "0.post4"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -6,6 +6,7 @@ from cpl_discord.events.on_command_completion_abc import OnCommandCompletionABC
|
||||
from cpl_discord.events.on_command_error_abc import OnCommandErrorABC
|
||||
from cpl_discord.events.on_connect_abc import OnConnectABC
|
||||
from cpl_discord.events.on_disconnect_abc import OnDisconnectABC
|
||||
from cpl_discord.events.on_error_abc import OnErrorABC
|
||||
from cpl_discord.events.on_group_join_abc import OnGroupJoinABC
|
||||
from cpl_discord.events.on_group_remove_abc import OnGroupRemoveABC
|
||||
from cpl_discord.events.on_guild_available_abc import OnGuildAvailableABC
|
||||
@ -58,6 +59,7 @@ class DiscordEventTypesEnum(Enum):
|
||||
on_command_completion = OnCommandCompletionABC
|
||||
on_connect = OnConnectABC
|
||||
on_disconnect = OnDisconnectABC
|
||||
on_error = OnErrorABC
|
||||
on_group_join = OnGroupJoinABC
|
||||
on_group_remove = OnGroupRemoveABC
|
||||
on_guild_available = OnGuildAvailableABC
|
||||
|
@ -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.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -72,4 +72,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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -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.post2'
|
||||
__version__ = '2022.7.0.post4'
|
||||
|
||||
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.post2')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post4')
|
||||
|
@ -16,6 +16,7 @@ from cpl_discord.events.on_command_completion_abc import OnCommandCompletionABC
|
||||
from cpl_discord.events.on_command_error_abc import OnCommandErrorABC
|
||||
from cpl_discord.events.on_connect_abc import OnConnectABC
|
||||
from cpl_discord.events.on_disconnect_abc import OnDisconnectABC
|
||||
from cpl_discord.events.on_error_abc import OnErrorABC
|
||||
from cpl_discord.events.on_group_join_abc import OnGroupJoinABC
|
||||
from cpl_discord.events.on_group_remove_abc import OnGroupRemoveABC
|
||||
from cpl_discord.events.on_guild_available_abc import OnGuildAvailableABC
|
||||
@ -76,7 +77,7 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
|
||||
self._collection = dc_collection
|
||||
self._services = services
|
||||
|
||||
async def _handle_event(self, event: Type, *args):
|
||||
async def _handle_event(self, event: Type, *args, **kwargs):
|
||||
event_collection = self._collection.get_events_by_base(event)
|
||||
if event_collection is None:
|
||||
return
|
||||
@ -92,7 +93,7 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
|
||||
|
||||
try:
|
||||
func = getattr(event_instance, func_name)
|
||||
await func(*args)
|
||||
await func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Cannot execute {func_name} of {type(event_instance).__name__}', e)
|
||||
|
||||
@ -138,6 +139,11 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
|
||||
self._logger.trace(__name__, f'Received on_disconnect')
|
||||
await self._handle_event(OnDisconnectABC)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_error(self, event: str, *args, **kwargs):
|
||||
self._logger.trace(__name__, f'Received on_error')
|
||||
await self._handle_event(OnErrorABC, event, *args, **kwargs)
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.trace(__name__, f'Received on_ready')
|
||||
await self._handle_event(OnReadyABC)
|
||||
|
@ -29,6 +29,9 @@ class DiscordServiceABC(ABC):
|
||||
@abstractmethod
|
||||
async def on_disconnect(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_error(self, event: str, *args, **kwargs): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_ready(self): pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user