From 2a4933f9718c94a720c88f6d99fa170884083902 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 9 Nov 2022 22:34:25 +0100 Subject: [PATCH] Added ontime to user info #97 --- kdb-bot/src/bot/translation/de.json | 1 + kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py | 2 +- kdb-bot/src/modules/base/command/user_group.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 606e89c604..fc7e563104 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -162,6 +162,7 @@ "discord_join": "Discord beigetreten am", "last_join": "Server beigetreten am", "xp": "XP", + "ontime": "Ontime", "roles": "Rollen", "joins": "Beitritte", "lefts": "Abgänge", diff --git a/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py b/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py index a9228c489a..d46a6f2b51 100644 --- a/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py +++ b/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py @@ -16,7 +16,7 @@ class UserJoinedVoiceChannelRepositoryABC(ABC): def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel: pass @abstractmethod - def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> list[UserJoinedVoiceChannel]: pass + def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[UserJoinedVoiceChannel]: pass @abstractmethod def get_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> UserJoinedVoiceChannel: pass diff --git a/kdb-bot/src/modules/base/command/user_group.py b/kdb-bot/src/modules/base/command/user_group.py index 1988902be4..a2efb8ba72 100644 --- a/kdb-bot/src/modules/base/command/user_group.py +++ b/kdb-bot/src/modules/base/command/user_group.py @@ -14,6 +14,7 @@ from bot_core.logging.command_logger import CommandLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC +from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -31,6 +32,7 @@ class UserGroup(DiscordCommandABC): servers: ServerRepositoryABC, users: UserRepositoryABC, user_joined_servers: UserJoinedServerRepositoryABC, + user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC, translate: TranslatePipe, date: DateTimeOffsetPipe ): @@ -45,6 +47,7 @@ class UserGroup(DiscordCommandABC): self._servers = servers self._users = users self._user_joined_servers = user_joined_servers + self._user_joined_voice_channel = user_joined_voice_channel self._t = translate self._date = date @@ -81,11 +84,15 @@ class UserGroup(DiscordCommandABC): color=int('ef9d0d', 16) ) + ujvs = self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id) + ontime = ujvs.sum(lambda join: round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2)) + embed.add_field(name=self._t.transform('modules.base.user_info.fields.id'), value=member.id) embed.add_field(name=self._t.transform('modules.base.user_info.fields.name'), value=member.name) embed.add_field(name=self._t.transform('modules.base.user_info.fields.discord_join'), value=self._date.transform(member.created_at), inline=False) embed.add_field(name=self._t.transform('modules.base.user_info.fields.last_join'), value=self._date.transform(member.joined_at), inline=False) embed.add_field(name=self._t.transform('modules.base.user_info.fields.xp'), value=str(user.xp)) + embed.add_field(name=self._t.transform('modules.base.user_info.fields.ontime'), value=str(ontime)) roles = '' for role in member.roles: