Added logic to send context messages
This commit is contained in:
		@@ -39,8 +39,7 @@ class MessageService(MessageServiceABC):
 | 
				
			|||||||
    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}')
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            msg = await channel.send(message)
 | 
					            await self.delete_message(await channel.send(message))
 | 
				
			||||||
            await self.delete_message(msg)
 | 
					 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            self._logger.error(__name__, f'Send message to channel {channel.id} failed', e)
 | 
					            self._logger.error(__name__, f'Send message to channel {channel.id} failed', e)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
@@ -55,4 +54,19 @@ class MessageService(MessageServiceABC):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self._logger.debug(__name__, f'Send message to user {receiver.id}')
 | 
					            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: Union[str, discord.File]): 
 | 
				
			||||||
 | 
					        if ctx is None:
 | 
				
			||||||
 | 
					            self._logger.warn(__name__, 'Message context is empty')
 | 
				
			||||||
 | 
					            self._logger.debug(__name__, f'Message: {message}')
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        self._logger.debug(__name__, f'Try to send message {message} to channel {ctx.channel.id}')
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            if isinstance(message, discord.File):
 | 
				
			||||||
 | 
					                await self.delete_message(await ctx.send(file=message))
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                await self.delete_message(await ctx.send(message))
 | 
				
			||||||
 | 
					        except Exception as e:
 | 
				
			||||||
 | 
					            self._logger.error(__name__, f'Send message to channel {ctx.channel.id} failed', e)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self._logger.debug(__name__, f'Send message to channel {ctx.channel.id}')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user