Added logic to send dm messages

This commit is contained in:
Sven Heidemann 2021-11-16 20:12:42 +01:00
parent e8e6a28d87
commit b0b646bb2b

View File

@ -28,15 +28,13 @@ class MessageService(MessageServiceABC):
async def delete_message(self, message: discord.Message): async def delete_message(self, message: discord.Message):
server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.g.id}') server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.g.id}')
await asyncio.sleep(server_st.message_delete_timer) await asyncio.sleep(server_st.message_delete_timer)
self._logger.debug(__name__, f'Try to delete message: {message.content}')
try: try:
self._logger.trace(__name__, f'Try to delete message: {message.content}')
await message.delete() await message.delete()
self._logger.trace(__name__, 'Deleted message')
except Exception as e: except Exception as e:
self._logger.warn(__name__, f'Deleting message failed') self._logger.error(__name__, f'Deleting message failed', e)
else: else:
self._logger.debug(__name__, f'Deleted message {message.content}') 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): 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}') self._logger.debug(__name__, f'Try to send message {message} to channel {channel.id}')
@ -44,10 +42,17 @@ class MessageService(MessageServiceABC):
msg = await channel.send(message) msg = await channel.send(message)
await self.delete_message(msg) await self.delete_message(msg)
except Exception as e: except Exception as e:
self._logger.warn(__name__, f'Send message to channel {channel.id} failed') self._logger.error(__name__, f'Send message to channel {channel.id} failed', e)
else: else:
self._logger.debug(__name__, f'Send message to channel {channel.id}') 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 async def send_dm_message(self, message: str, receiver: Union[discord.User, discord.Member]):
self._logger.debug(__name__, f'Try to send message {message} to user {receiver.id}')
try:
await receiver.send(message)
except Exception as e:
self._logger.error(__name__, f'Send message to user {receiver.id} failed', e)
else:
self._logger.debug(__name__, f'Send message to user {receiver.id}')
async def send_ctx_msg(self, ctx: Context, message: str, file: discord.File = None): pass async def send_ctx_msg(self, ctx: Context, message: str, file: discord.File = None): pass