Formatted stuff #405

This commit is contained in:
2023-10-15 11:30:29 +02:00
parent 3a7daf8b42
commit be6361f619
226 changed files with 1083 additions and 3252 deletions

View File

@@ -36,9 +36,7 @@ class ApiKeySeeder(DataSeederABC):
return
try:
frontend_key = ApiKey(
"frontend", "87f529fd-a32e-40b3-a1d1-7a1583cf3ff5", None
)
frontend_key = ApiKey("frontend", "87f529fd-a32e-40b3-a1d1-7a1583cf3ff5", None)
self._api_keys.add_api_key(frontend_key)
self._db.save_changes()
self._logger.info(__name__, f"Created frontend API-Key")

View File

@@ -54,9 +54,7 @@ class ApiKeyGroup(DiscordCommandABC):
def _get_api_key_str(self, api_key: ApiKey) -> str:
return hashlib.sha256(
f"{api_key.identifier}:{api_key.key}+{self._auth_settings.secret_key}".encode(
"utf-8"
)
f"{api_key.identifier}:{api_key.key}+{self._auth_settings.secret_key}".encode("utf-8")
).hexdigest()
@commands.hybrid_group(name="api-key")
@@ -69,9 +67,7 @@ class ApiKeyGroup(DiscordCommandABC):
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_technician()
async def get(self, ctx: Context, key: str, wait: int = None):
self._logger.debug(
__name__, f"Received command api-key get {ctx}: {key},{wait}"
)
self._logger.debug(__name__, f"Received command api-key get {ctx}: {key},{wait}")
api_key = self._api_keys.get_api_key_by_key(key)
await self._message_service.send_ctx_msg(
@@ -83,16 +79,12 @@ class ApiKeyGroup(DiscordCommandABC):
self._logger.trace(__name__, f"Finished command api-key get")
@get.autocomplete("key")
async def get_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[str]]:
async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
keys = self._api_keys.get_api_keys()
return [
app_commands.Choice(name=f"{key.identifier}: {key.key}", value=key.key)
for key in self._client_utils.get_auto_complete_list(
keys, current, lambda x: x.key
)
for key in self._client_utils.get_auto_complete_list(keys, current, lambda x: x.key)
]
@api_key.command()
@@ -100,14 +92,10 @@ class ApiKeyGroup(DiscordCommandABC):
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def add(self, ctx: Context, identifier: str):
self._logger.debug(
__name__, f"Received command api-key add {ctx}: {identifier}"
)
self._logger.debug(__name__, f"Received command api-key add {ctx}: {identifier}")
server = self._servers.get_server_by_discord_id(ctx.guild.id)
user = self._users.get_user_by_discord_id_and_server_id(
ctx.author.id, server.id
)
user = self._users.get_user_by_discord_id_and_server_id(ctx.author.id, server.id)
api_key = ApiKey(identifier, str(uuid.uuid4()), user)
self._api_keys.add_api_key(api_key)
self._db.save_changes()
@@ -137,21 +125,15 @@ class ApiKeyGroup(DiscordCommandABC):
api_key = keys.single()
self._api_keys.delete_api_key(api_key)
self._db.save_changes()
await self._message_service.send_ctx_msg(
ctx, self._t.transform("modules.technician.api_key.remove.success")
)
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.api_key.remove.success"))
self._logger.trace(__name__, f"Finished command api-key remove")
@remove.autocomplete("key")
async def set_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[str]]:
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
keys = self._api_keys.get_api_keys()
return [
app_commands.Choice(name=f"{key.identifier}: {key.key}", value=key.key)
for key in self._client_utils.get_auto_complete_list(
keys, current, lambda x: x.key
)
for key in self._client_utils.get_auto_complete_list(keys, current, lambda x: x.key)
]

View File

@@ -98,10 +98,7 @@ class LogCommand(DiscordCommandABC):
continue
split_filename = file.split(".")
if (
f".{split_filename[len(split_filename) - 1]}"
not in file_extensions
):
if f".{split_filename[len(split_filename) - 1]}" not in file_extensions:
continue
files.append(os.path.join(r, file))

View File

@@ -52,9 +52,7 @@ class RestartCommand(DiscordCommandABC):
self._config.add_configuration("IS_RESTART", "true")
await self._client_utils.presence_game("common.presence.restart")
await self._message_service.send_ctx_msg(
ctx, self._t.transform("modules.technician.restart_message")
)
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.restart_message"))
await asyncio.sleep(self._settings.wait_for_restart)
await self._data_integrity.check_data_integrity(is_for_shutdown=True)
await self._bot.stop_async()

View File

@@ -51,9 +51,7 @@ class ShutdownCommand(DiscordCommandABC):
self._logger.debug(__name__, f"Received command shutdown {ctx}")
await self._client_utils.presence_game("common.presence.shutdown")
await self._message_service.send_ctx_msg(
ctx, self._t.transform("modules.technician.shutdown_message")
)
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.shutdown_message"))
await asyncio.sleep(self._settings.wait_for_shutdown)
await self._data_integrity.check_data_integrity(is_for_shutdown=True)
await self._bot.stop_async()

View File

@@ -71,28 +71,18 @@ class SyncXpGroup(DiscordCommandABC):
if ctx.guild is None:
return
settings: ServerConfig = self._config.get_configuration(
f"ServerConfig_{ctx.guild.id}"
)
if not FeatureFlagsSettings.get_flag_from_dict(
settings.feature_flags, FeatureFlagsEnum.sync_xp
):
await self._message_service.send_ctx_msg(
ctx, self._t.transform("common.feature_not_activated")
)
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.sync_xp):
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
return
other_server = self._servers.get_server_by_id(server_id)
users_on_other_server = self._users.get_users_by_server_id(
other_server.id
).where(lambda x: not x.left_server)
discord_ids_on_other_server = users_on_other_server.select(
lambda x: x.discord_id
)
users_on_other_server = self._users.get_users_by_server_id(other_server.id).where(lambda x: not x.left_server)
discord_ids_on_other_server = users_on_other_server.select(lambda x: x.discord_id)
for user in self._users.get_users_by_server_id(
self._servers.get_server_by_discord_id(ctx.guild.id).id
).where(lambda x: not x.left_server):
for user in self._users.get_users_by_server_id(self._servers.get_server_by_discord_id(ctx.guild.id).id).where(
lambda x: not x.left_server
):
try:
if user.discord_id not in discord_ids_on_other_server:
continue
@@ -106,21 +96,15 @@ class SyncXpGroup(DiscordCommandABC):
user.xp = user_on_other_server.xp
self._users.update_user(user)
self._db.save_changes()
await self._level_service.check_level(
ctx.guild.get_member(user.discord_id)
)
await self._level_service.check_level(ctx.guild.get_member(user.discord_id))
except Exception as e:
self._logger.error(__name__, f"Cannot sync user {user.name}", e)
await self._message_service.send_ctx_msg(
ctx, self._t.transform("modules.technician.synced_message")
)
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.synced_message"))
self._logger.trace(__name__, f"Finished sync xp command")
@all_members.autocomplete("server_id")
async def list_autocomplete(
self, interaction: discord.Interaction, current: str
) -> list[app_commands.Choice]:
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice]:
return [
app_commands.Choice(name=server.name, value=server.id)
for server in self._client_utils.get_auto_complete_list(
@@ -138,15 +122,9 @@ class SyncXpGroup(DiscordCommandABC):
if ctx.guild is None:
return
settings: ServerConfig = self._config.get_configuration(
f"ServerConfig_{ctx.guild.id}"
)
if not FeatureFlagsSettings.get_flag_from_dict(
settings.feature_flags, FeatureFlagsEnum.sync_xp
):
await self._message_service.send_ctx_msg(
ctx, self._t.transform("common.feature_not_activated")
)
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.sync_xp):
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
return
other_server = self._servers.get_server_by_id(server_id)
@@ -169,16 +147,12 @@ class SyncXpGroup(DiscordCommandABC):
except Exception as e:
self._logger.error(__name__, f"Cannot sync user {user.name}", e)
await self._message_service.send_ctx_msg(
ctx, self._t.transform("modules.technician.synced_message")
)
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.synced_message"))
await self._level_service.check_level(member)
self._logger.trace(__name__, f"Finished sync xp command")
@by_member.autocomplete("server_id")
async def list_autocomplete(
self, interaction: discord.Interaction, current: str
) -> list[app_commands.Choice]:
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice]:
return [
app_commands.Choice(name=server.name, value=server.id)
for server in self._client_utils.get_auto_complete_list(

View File

@@ -18,14 +18,10 @@ class TechnicianModule(ModuleABC):
def __init__(self, dc: DiscordCollectionABC):
ModuleABC.__init__(self, dc, FeatureFlagsEnum.base_module)
def configure_configuration(
self, config: ConfigurationABC, env: ApplicationEnvironmentABC
):
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
pass
def configure_services(
self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC
):
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
services.add_transient(DataSeederABC, ApiKeySeeder)
# commands
services.add_transient(RestartCommand)