From f3eff977807faede6f205f4878bc6df94d3106bd Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 30 Dec 2022 11:25:48 +0100 Subject: [PATCH] Added logic to count moved users to mass move #156 --- kdb-bot/src/bot/config | 2 +- kdb-bot/src/bot_core/abc/client_utils_service_abc.py | 3 +++ kdb-bot/src/bot_core/service/client_utils_service.py | 7 +++++++ kdb-bot/src/modules/base/command/mass_move_command.py | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index c8983770..0b18f8e5 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit c8983770f7a41f84441e6b60cdfe5eb694039f1c +Subproject commit 0b18f8e5963bb963779968f102579d797016ccb6 diff --git a/kdb-bot/src/bot_core/abc/client_utils_service_abc.py b/kdb-bot/src/bot_core/abc/client_utils_service_abc.py index da5d099a..5510efee 100644 --- a/kdb-bot/src/bot_core/abc/client_utils_service_abc.py +++ b/kdb-bot/src/bot_core/abc/client_utils_service_abc.py @@ -14,6 +14,9 @@ class ClientUtilsServiceABC(ABC): @abstractmethod def moved_user(self, guild_id: int): pass + @abstractmethod + def moved_users(self, guild_id: int, count: int): pass + @abstractmethod def get_client(self, dc_ic: int, guild_id: int): pass diff --git a/kdb-bot/src/bot_core/service/client_utils_service.py b/kdb-bot/src/bot_core/service/client_utils_service.py index 3d072700..ad8fbb7f 100644 --- a/kdb-bot/src/bot_core/service/client_utils_service.py +++ b/kdb-bot/src/bot_core/service/client_utils_service.py @@ -54,6 +54,13 @@ class ClientUtilsService(ClientUtilsServiceABC): self._clients.update_client(client) self._db.save_changes() + def moved_users(self, guild_id: int, count: int): + server = self._servers.get_server_by_discord_id(guild_id) + client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id) + client.moved_users_count += count + self._clients.update_client(client) + self._db.save_changes() + def get_client(self, dc_ic: int, guild_id: int): server = self._servers.get_server_by_discord_id(guild_id) client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id) diff --git a/kdb-bot/src/modules/base/command/mass_move_command.py b/kdb-bot/src/modules/base/command/mass_move_command.py index 4d72ecb9..85862a14 100644 --- a/kdb-bot/src/modules/base/command/mass_move_command.py +++ b/kdb-bot/src/modules/base/command/mass_move_command.py @@ -10,6 +10,7 @@ from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.helper.command_checks import CommandChecks from bot_core.logging.command_logger import CommandLogger +from bot_core.service.client_utils_service import ClientUtilsService class MassMoveCommand(DiscordCommandABC): @@ -20,12 +21,14 @@ class MassMoveCommand(DiscordCommandABC): message_service: MessageServiceABC, bot: DiscordBotServiceABC, translate: TranslatePipe, + client_utils: ClientUtilsService ): DiscordCommandABC.__init__(self) self._logger = logger self._message_service = message_service self._bot = bot self._t = translate + self._client_utils = client_utils @commands.hybrid_command(name='mass-move') @CommandChecks.check_is_ready() @@ -42,7 +45,9 @@ class MassMoveCommand(DiscordCommandABC): channel_from = ctx.author.voice.channel moves = [member.move_to(channel_to) for member in channel_from.members] + move_count = len(moves) await asyncio.gather(*moves) + self._client_utils.moved_users(ctx.guild.id, move_count) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.mass_move.moved').format(channel_from.mention, channel_to.mention))