From 356dc1848c4518e5e3b48095663cc2865e4aa575 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 9 Nov 2022 22:34:25 +0100 Subject: [PATCH 1/5] 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: From 2a4933f9718c94a720c88f6d99fa170884083902 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 9 Nov 2022 22:34:25 +0100 Subject: [PATCH 2/5] 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: From ef41ce03d346e753dc2a07a1bc554fb67f9f2558 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 10 Nov 2022 19:50:42 +0100 Subject: [PATCH 3/5] Added functionality to auto-role rule add to add reaction to message #63 --- .../auto_role/command/auto_role_group.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kdb-bot/src/modules/auto_role/command/auto_role_group.py b/kdb-bot/src/modules/auto_role/command/auto_role_group.py index 072a3bf56a..6dbf51c803 100644 --- a/kdb-bot/src/modules/auto_role/command/auto_role_group.py +++ b/kdb-bot/src/modules/auto_role/command/auto_role_group.py @@ -7,7 +7,7 @@ from cpl_discord.container import TextChannel from cpl_discord.service import DiscordBotServiceABC from cpl_query.extension import List from cpl_translation import TranslatePipe -from discord import app_commands +from discord import app_commands, Guild from discord.ext import commands from discord.ext.commands import Context @@ -258,13 +258,27 @@ class AutoRoleGroup(DiscordCommandABC): self._logger.trace(__name__, f'Finished command auto-role rule add') return - if self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).count() > 0: + if self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).first_or_default() is not None: await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(auto_role)) self._logger.trace(__name__, f'Finished command auto-role rule add') return self._auto_roles.add_auto_role_rule(AutoRoleRule(auto_role, emoji_name, int(role_id))) self._db_context.save_changes() + rule = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).single() + try: + message = await ctx.fetch_message(auto_role_from_db.discord_message_id) + guild: Guild = self._bot.guilds.where(lambda g: g == ctx.guild).single() + emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single() + + if emoji is None: + self._logger.debug(__name__, f'Emoji {rule.emoji_name} not found') + return + await message.add_reaction(emoji) + self._logger.debug(__name__, f'Added reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}') + except Exception as e: + self._logger.error(__name__, f'Cannot add reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}', e) + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.success').format(emoji, role.name, auto_role)) self._logger.trace(__name__, f'Finished command auto-role rule add') From 25cc98732d6a5d4dc444d02ec241187795789bc0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 10 Nov 2022 20:02:53 +0100 Subject: [PATCH 4/5] Fixed restart after message #62 --- kdb-bot/src/modules/base/command/restart_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdb-bot/src/modules/base/command/restart_command.py b/kdb-bot/src/modules/base/command/restart_command.py index 56c489583e..829810e0a2 100644 --- a/kdb-bot/src/modules/base/command/restart_command.py +++ b/kdb-bot/src/modules/base/command/restart_command.py @@ -58,8 +58,8 @@ class RestartCommand(DiscordCommandABC): self._config.add_configuration('IS_RESTART', 'true') await self._client_utils.presence_game('common.presence.restart') - await asyncio.sleep(self._settings.wait_for_restart) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.restart_message')) + await asyncio.sleep(self._settings.wait_for_restart) await self._bot.stop_async() self._logger.trace(__name__, f'Finished restart command') From b4fce51b571f98d0d3c3249da776646c22c50496 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 10 Nov 2022 20:56:45 +0100 Subject: [PATCH 5/5] Added is admin check to level create --- kdb-bot/src/modules/level/command/level_group.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kdb-bot/src/modules/level/command/level_group.py b/kdb-bot/src/modules/level/command/level_group.py index 7a49593c6d..e253846a04 100644 --- a/kdb-bot/src/modules/level/command/level_group.py +++ b/kdb-bot/src/modules/level/command/level_group.py @@ -122,6 +122,11 @@ class LevelGroup(DiscordCommandABC): return self._client_utils.received_command(ctx.guild.id) + if not self._permissions.is_member_admin(ctx.author): + await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message')) + self._logger.trace(__name__, f'Finished command level remove') + return + try: color = hex(discord.Colour.from_str(color).value) except Exception as e: