diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 986e5de0..9398972e 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -247,7 +247,8 @@ }, "technician": { "restart_message": "Bin gleich wieder da :D", - "shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)" + "shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)", + "log_message": "Hier sind deine Logdateien! :)" } }, "api": { diff --git a/kdb-bot/src/bot_core/abc/message_service_abc.py b/kdb-bot/src/bot_core/abc/message_service_abc.py index 614dd1df..3542e2b7 100644 --- a/kdb-bot/src/bot_core/abc/message_service_abc.py +++ b/kdb-bot/src/bot_core/abc/message_service_abc.py @@ -28,4 +28,4 @@ class MessageServiceABC(ABC): 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 @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): pass + 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 diff --git a/kdb-bot/src/bot_core/service/message_service.py b/kdb-bot/src/bot_core/service/message_service.py index 04f33bfb..dcd329a2 100644 --- a/kdb-bot/src/bot_core/service/message_service.py +++ b/kdb-bot/src/bot_core/service/message_service.py @@ -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): + 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): 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) + await interaction.response.send_message(embed=message, **kwargs) else: - await interaction.response.send_message(message) + await interaction.response.send_message(message, **kwargs) except Exception as e: self._logger.error(__name__, f'Send message to channel {interaction.channel.id} failed', e) else: diff --git a/kdb-bot/src/modules/technician/command/log_command.py b/kdb-bot/src/modules/technician/command/log_command.py index d7395d46..8d8c7832 100644 --- a/kdb-bot/src/modules/technician/command/log_command.py +++ b/kdb-bot/src/modules/technician/command/log_command.py @@ -1,6 +1,8 @@ import os from datetime import datetime +from zipfile import ZipFile +import discord from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggingSettings from cpl_discord.command import DiscordCommandABC @@ -51,7 +53,7 @@ class LogCommand(DiscordCommandABC): @commands.guild_only() @CommandChecks.check_is_ready() @CommandChecks.check_is_member_technician() - async def log(self, ctx: Context, date_from: datetime = datetime.now()): + async def log(self, ctx: Context): self._logger.debug(__name__, f'Received command log {ctx}') possible_log_paths = List(str) @@ -79,7 +81,6 @@ class LogCommand(DiscordCommandABC): possible_log_paths.append(path) files = List(str) - now = datetime.now() for possible_path in possible_log_paths: for r, d, f in os.walk(possible_path): for file in f: @@ -92,4 +93,10 @@ class LogCommand(DiscordCommandABC): files.append(os.path.join(r, file)) + 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) + os.remove(zip_file.filename) + self._logger.trace(__name__, f'Finished log command')