Finished log command #44

This commit is contained in:
2022-11-17 22:45:10 +01:00
parent 2c7f4647af
commit 7b8dca64bf
4 changed files with 15 additions and 7 deletions

View File

@@ -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')