From e8e6a28d87f8f993b7ae07b7a0b76298d1e26799 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 16 Nov 2021 20:07:48 +0100 Subject: [PATCH] Added logic to delete message & send channel message --- src/gismo_core/service/message_service.py | 33 ++++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gismo_core/service/message_service.py b/src/gismo_core/service/message_service.py index f97aca0..db8307c 100644 --- a/src/gismo_core/service/message_service.py +++ b/src/gismo_core/service/message_service.py @@ -22,18 +22,31 @@ class MessageService(MessageServiceABC): async def delete_message(self, messages: List[discord.Message]): self._logger.debug(__name__, f'Try to delete {messages.count()} messages') for message in messages: - message: discord.Message = message - server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.g.id}') - await asyncio.sleep(server_st.message_delete_timer) - try: - self._logger.trace(__name__, f'Try to delete message: {message.content}') - await message.delete() - self._logger.trace(__name__, 'Deleted message') - except Exception as e: - self._logger.warn(__name__, f'Deleting message failed') + await self.delete_message(message) self._logger.debug(__name__, 'Deleting messages finished') + + async def delete_message(self, message: discord.Message): + server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.g.id}') + await asyncio.sleep(server_st.message_delete_timer) + try: + self._logger.trace(__name__, f'Try to delete message: {message.content}') + await message.delete() + self._logger.trace(__name__, 'Deleted message') + except Exception as e: + self._logger.warn(__name__, f'Deleting message failed') + else: + self._logger.debug(__name__, f'Deleted message {message.content}') + self._logger.trace(__name__, 'Deleting messages finished') - async def send_channel_message(self, channel: discord.TextChannel, message: str): pass + async def send_channel_message(self, channel: discord.TextChannel, message: str): + self._logger.debug(__name__, f'Try to send message {message} to channel {channel.id}') + try: + msg = await channel.send(message) + await self.delete_message(msg) + except Exception as e: + self._logger.warn(__name__, f'Send message to channel {channel.id} failed') + else: + self._logger.debug(__name__, f'Send message to channel {channel.id}') async def send_dm_message(self, message: str, receiver: Union[discord.User, discord.Member]): pass