forked from sh-edraft.de/sh_discord_bot
		
	Fixed log command
This commit is contained in:
		| @@ -1,10 +1,12 @@ | ||||
| import os | ||||
| from datetime import datetime | ||||
| from string import Template | ||||
| from zipfile import ZipFile | ||||
|  | ||||
| import discord | ||||
| from cpl_core.dependency_injection import ServiceProviderABC | ||||
| from cpl_core.environment import ApplicationEnvironmentABC | ||||
| from cpl_core.logging import LoggingSettings | ||||
| from cpl_core.time import TimeFormatSettings | ||||
| from cpl_discord.command import DiscordCommandABC | ||||
| from cpl_query.extension import List | ||||
| from cpl_translation import TranslatePipe | ||||
| @@ -30,6 +32,8 @@ class LogCommand(DiscordCommandABC): | ||||
|             client_utils: ClientUtilsServiceABC, | ||||
|             translate: TranslatePipe, | ||||
|             permissions: PermissionServiceABC, | ||||
|             time_format: TimeFormatSettings, | ||||
|             env: ApplicationEnvironmentABC | ||||
|     ): | ||||
|         DiscordCommandABC.__init__(self) | ||||
|  | ||||
| @@ -41,10 +45,14 @@ class LogCommand(DiscordCommandABC): | ||||
|         self._t = translate | ||||
|         self._permissions = permissions | ||||
|  | ||||
|         self._env = env | ||||
|         self._log_settings: LoggingSettings = logging_settings | ||||
|         self._time_format_settings: TimeFormatSettings = time_format | ||||
|  | ||||
|         self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') | ||||
|  | ||||
|     def _reduce_path(self, p: str) -> str: | ||||
|         if p.count('/') == 1 or p == '': | ||||
|         if len(p.split('/')) == 1 or p == '': | ||||
|             return p | ||||
|  | ||||
|         return self._reduce_path(os.path.dirname(p)) | ||||
| @@ -80,6 +88,9 @@ class LogCommand(DiscordCommandABC): | ||||
|                 continue | ||||
|             possible_log_paths.append(path) | ||||
|  | ||||
|         files_str = "\n\t".join(possible_log_paths.to_list()) | ||||
|         self._logger.debug(__name__, f'Possible log files: \n\t{files_str}') | ||||
|  | ||||
|         files = List(str) | ||||
|         for possible_path in possible_log_paths: | ||||
|             for r, d, f in os.walk(possible_path): | ||||
| @@ -93,6 +104,9 @@ class LogCommand(DiscordCommandABC): | ||||
|  | ||||
|                     files.append(os.path.join(r, file)) | ||||
|  | ||||
|         files_str = "\n\t".join(files.to_list()) | ||||
|         self._logger.debug(__name__, f'Log files: \n\t{files_str}') | ||||
|  | ||||
|         zip_file = ZipFile('logs.zip', 'w') | ||||
|         files.for_each(lambda x: zip_file.write(x)) | ||||
|         zip_file.close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user