Merge pull request 'Added logic to handle public and private messages #147' (#148) from #147 into 0.3
Reviewed-on: sh-edraft.de/kd_discord_bot#148 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Closes #147
This commit is contained in:
commit
a46122243f
@ -25,7 +25,7 @@ class MessageServiceABC(ABC):
|
||||
async def send_dm_message(self, message: Union[str, discord.Embed], receiver: Union[discord.User, discord.Member], without_tracking=False): pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None, without_tracking=True): pass
|
||||
async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, is_public: bool = False, wait_before_delete: int = None, without_tracking=True): pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_interaction_msg(self, interaction: Interaction, message: Union[str, discord.Embed], is_persistent: bool = False, wait_before_delete: int = None, without_tracking=True, **kwargs): pass
|
||||
async def send_interaction_msg(self, interaction: Interaction, message: Union[str, discord.Embed], is_persistent: bool = False, is_public: bool = False, wait_before_delete: int = None, without_tracking=True, **kwargs): pass
|
||||
|
@ -89,7 +89,7 @@ class MessageService(MessageServiceABC):
|
||||
self._db.save_changes()
|
||||
self._logger.info(__name__, f'Sent message to user {receiver.id}')
|
||||
|
||||
async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None, without_tracking=False):
|
||||
async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, is_public: bool = False, wait_before_delete: int = None, without_tracking=False):
|
||||
if ctx is None:
|
||||
self._logger.warn(__name__, 'Message context is empty')
|
||||
self._logger.debug(__name__, f'Message: {message}')
|
||||
@ -99,9 +99,9 @@ class MessageService(MessageServiceABC):
|
||||
msg = None
|
||||
try:
|
||||
if isinstance(message, discord.Embed):
|
||||
msg = await ctx.send(embed=message, file=file)
|
||||
msg = await ctx.send(embed=message, file=file, ephemeral=not is_public)
|
||||
else:
|
||||
msg = await ctx.send(message, file=file)
|
||||
msg = await ctx.send(message, file=file, ephemeral=not is_public)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Send message to channel {ctx.channel.id} failed', e)
|
||||
else:
|
||||
@ -119,7 +119,7 @@ class MessageService(MessageServiceABC):
|
||||
if ctx.guild is not None:
|
||||
await self.delete_message(msg, without_tracking)
|
||||
|
||||
async def send_interaction_msg(self, interaction: Interaction, message: Union[str, discord.Embed], is_persistent: bool = False, wait_before_delete: int = None, without_tracking=False, **kwargs):
|
||||
async def send_interaction_msg(self, interaction: Interaction, message: Union[str, discord.Embed], is_persistent: bool = False, is_public: bool = False, wait_before_delete: int = None, without_tracking=False, **kwargs):
|
||||
if interaction is None:
|
||||
self._logger.warn(__name__, 'Message context is empty')
|
||||
self._logger.debug(__name__, f'Message: {message}')
|
||||
@ -128,9 +128,9 @@ class MessageService(MessageServiceABC):
|
||||
self._logger.debug(__name__, f'Try to send message\t\t{message}\n\tto: {interaction.channel}')
|
||||
try:
|
||||
if isinstance(message, discord.Embed):
|
||||
await interaction.response.send_message(embed=message, **kwargs)
|
||||
await interaction.response.send_message(embed=message, ephemeral=not is_public, **kwargs)
|
||||
else:
|
||||
await interaction.response.send_message(message, **kwargs)
|
||||
await interaction.response.send_message(message, ephemeral=not is_public, **kwargs)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Send message to channel {interaction.channel.id} failed', e)
|
||||
else:
|
||||
|
@ -42,7 +42,7 @@ class HelpCommand(DiscordCommandABC):
|
||||
self._logger.debug(__name__, f'Received command help {ctx}:{persistent_flag}')
|
||||
settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}')
|
||||
is_persistent = persistent_flag == '--stay'
|
||||
await self._message_service.send_ctx_msg(ctx, settings.help_command_reference_url, is_persistent=is_persistent)
|
||||
await self._message_service.send_ctx_msg(ctx, settings.help_command_reference_url, is_persistent=is_persistent, is_public=True)
|
||||
self._logger.trace(__name__, f'Finished help command')
|
||||
|
||||
@help.autocomplete('persistent_flag')
|
||||
|
@ -110,7 +110,7 @@ class LogCommand(DiscordCommandABC):
|
||||
zip_file = ZipFile('logs.zip', 'w')
|
||||
files.for_each(lambda x: zip_file.write(x))
|
||||
zip_file.close()
|
||||
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.technician.log_message'), file=discord.File(zip_file.filename, 'logs.zip'), ephemeral=True)
|
||||
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.technician.log_message'), file=discord.File(zip_file.filename, 'logs.zip'))
|
||||
os.remove(zip_file.filename)
|
||||
|
||||
self._logger.trace(__name__, f'Finished log command')
|
||||
|
Loading…
Reference in New Issue
Block a user