From 0d1c15b31d3ad52d2236d167e9844ca81e08ead8 Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Sun, 20 Nov 2022 19:18:17 +0100 Subject: [PATCH 1/4] Added mass-move command #20 --- kdb-bot/src/bot/config | 2 +- kdb-bot/src/modules/base/base_module.py | 2 + .../modules/base/command/mass_move_command.py | 48 +++++++++++++++++++ kdb-bot/src/modules/base/thread/__init__.py | 1 + .../modules/base/thread/mass_move_thread.py | 17 +++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 kdb-bot/src/modules/base/command/mass_move_command.py create mode 100644 kdb-bot/src/modules/base/thread/__init__.py create mode 100644 kdb-bot/src/modules/base/thread/mass_move_thread.py diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 52d19fab6d..57dd85de79 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 52d19fab6dcfd2e7bce068f01d0e15ddf7d43212 +Subproject commit 57dd85de79d51893e5f5e5bd7f7d6065ba923f21 diff --git a/kdb-bot/src/modules/base/base_module.py b/kdb-bot/src/modules/base/base_module.py index f2dadd90c5..7477d701c1 100644 --- a/kdb-bot/src/modules/base/base_module.py +++ b/kdb-bot/src/modules/base/base_module.py @@ -10,6 +10,7 @@ from modules.base.abc.base_helper_abc import BaseHelperABC from modules.base.command.afk_command import AFKCommand from modules.base.command.help_command import HelpCommand from modules.base.command.info_command import InfoCommand +from modules.base.command.mass_move_command import MassMoveCommand from modules.base.command.ping_command import PingCommand from modules.base.command.presence_command import PresenceCommand from modules.base.command.purge_command import PurgeCommand @@ -42,6 +43,7 @@ class BaseModule(ModuleABC): self._dc.add_command(AFKCommand) self._dc.add_command(HelpCommand) self._dc.add_command(InfoCommand) + self._dc.add_command(MassMoveCommand) self._dc.add_command(PingCommand) self._dc.add_command(PresenceCommand) diff --git a/kdb-bot/src/modules/base/command/mass_move_command.py b/kdb-bot/src/modules/base/command/mass_move_command.py new file mode 100644 index 0000000000..a7490bac99 --- /dev/null +++ b/kdb-bot/src/modules/base/command/mass_move_command.py @@ -0,0 +1,48 @@ +import asyncio + +import discord +from cpl_discord.command import DiscordCommandABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe +from discord.ext import commands +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 modules.base.thread.mass_move_thread import MassMoveThread + + +class MassMoveCommand(DiscordCommandABC): + + def __init__( + self, + logger: CommandLogger, + message_service: MessageServiceABC, + bot: DiscordBotServiceABC, + translate: TranslatePipe, + ): + DiscordCommandABC.__init__(self) + self._logger = logger + self._message_service = message_service + self._bot = bot + self._t = translate + + @commands.hybrid_command(name='mass-move') + @CommandChecks.check_is_ready() + @CommandChecks.check_is_member_moderator() + async def mass_move(self, ctx: Context, channel_to: discord.VoiceChannel, + channel_from: discord.VoiceChannel = None): + self._logger.debug(__name__, f'Received command mass-move {ctx}') + + if channel_from is None and ctx.author.voice.channel is None: + ##Hier den User benachrichtigen, dass er nicht in einem Channel sitzt. + return + + if channel_from is None: + channel_from = ctx.author.voice.channel + + moves = [member.move_to(channel_to) for member in channel_from.members] + await asyncio.gather(*moves) + + self._logger.trace(__name__, f'Finished mass-move command') diff --git a/kdb-bot/src/modules/base/thread/__init__.py b/kdb-bot/src/modules/base/thread/__init__.py new file mode 100644 index 0000000000..425ab6c146 --- /dev/null +++ b/kdb-bot/src/modules/base/thread/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/kdb-bot/src/modules/base/thread/mass_move_thread.py b/kdb-bot/src/modules/base/thread/mass_move_thread.py new file mode 100644 index 0000000000..83505efccc --- /dev/null +++ b/kdb-bot/src/modules/base/thread/mass_move_thread.py @@ -0,0 +1,17 @@ +import asyncio +import threading + +import discord +from cpl_discord.service import DiscordBotServiceABC + + +class MassMoveThread(threading.Thread): + + def __init__(self, bot: DiscordBotServiceABC, member: discord.Member, channel_to: discord.VoiceChannel): + threading.Thread.__init__(self, daemon=True) + self._bot = bot + self._member = member + self._channel_to = channel_to + + def run(self): + self._bot.loop.create_task(self._member.move_to(self._channel_to)) From 2868b1afe29223cf88fdd46f10514fa489e0d616 Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Sun, 20 Nov 2022 23:27:22 +0100 Subject: [PATCH 2/4] Added messaging to mass-move #20 --- kdb-bot/src/bot/config | 2 +- kdb-bot/src/bot/translation/de.json | 4 ++++ kdb-bot/src/modules/base/command/mass_move_command.py | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 57dd85de79..e7e9d85f7d 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 57dd85de79d51893e5f5e5bd7f7d6065ba923f21 +Subproject commit e7e9d85f7d0054ba95ae1ff87d91b4e218ef510f diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 3ab63d0b75..8005bb1244 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -151,6 +151,10 @@ }, "footer": "" }, + "mass_move": { + "moved": "Alle Personen aus {} wurden nach {} verschoben.", + "channel_from_error": "Du musst dich in einem Voicechannel befinden oder die Option \"channel_from\" mit angeben." + }, "presence": { "changed": "Presence wurde geƤndert.", "removed": "Presence wurde entfernt.", 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 a7490bac99..ccf9f9d783 100644 --- a/kdb-bot/src/modules/base/command/mass_move_command.py +++ b/kdb-bot/src/modules/base/command/mass_move_command.py @@ -35,8 +35,8 @@ class MassMoveCommand(DiscordCommandABC): channel_from: discord.VoiceChannel = None): self._logger.debug(__name__, f'Received command mass-move {ctx}') - if channel_from is None and ctx.author.voice.channel is None: - ##Hier den User benachrichtigen, dass er nicht in einem Channel sitzt. + if channel_from is None and ctx.author.voice is None: + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.mass_move.channel_from_error')) return if channel_from is None: @@ -45,4 +45,6 @@ class MassMoveCommand(DiscordCommandABC): moves = [member.move_to(channel_to) for member in channel_from.members] await asyncio.gather(*moves) + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.mass_move.moved', channel_from.name, channel_to.name)) + self._logger.trace(__name__, f'Finished mass-move command') From 25c698273a37d753df01888100be21bd2561ba09 Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Mon, 21 Nov 2022 00:30:49 +0100 Subject: [PATCH 3/4] Fixed sending message with translation pipe #20 --- kdb-bot/src/modules/base/command/mass_move_command.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 ccf9f9d783..4d72ecb915 100644 --- a/kdb-bot/src/modules/base/command/mass_move_command.py +++ b/kdb-bot/src/modules/base/command/mass_move_command.py @@ -10,7 +10,6 @@ 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 modules.base.thread.mass_move_thread import MassMoveThread class MassMoveCommand(DiscordCommandABC): @@ -45,6 +44,6 @@ class MassMoveCommand(DiscordCommandABC): moves = [member.move_to(channel_to) for member in channel_from.members] await asyncio.gather(*moves) - await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.mass_move.moved', channel_from.name, channel_to.name)) + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.mass_move.moved').format(channel_from.mention, channel_to.mention)) self._logger.trace(__name__, f'Finished mass-move command') From 12369cdbe397fb75e249b86dcac99a7bf4e22fff Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Mon, 21 Nov 2022 18:20:23 +0100 Subject: [PATCH 4/4] Removed unused code for mass-move #20 --- .../src/modules/base/thread/mass_move_thread.py | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 kdb-bot/src/modules/base/thread/mass_move_thread.py diff --git a/kdb-bot/src/modules/base/thread/mass_move_thread.py b/kdb-bot/src/modules/base/thread/mass_move_thread.py deleted file mode 100644 index 83505efccc..0000000000 --- a/kdb-bot/src/modules/base/thread/mass_move_thread.py +++ /dev/null @@ -1,17 +0,0 @@ -import asyncio -import threading - -import discord -from cpl_discord.service import DiscordBotServiceABC - - -class MassMoveThread(threading.Thread): - - def __init__(self, bot: DiscordBotServiceABC, member: discord.Member, channel_to: discord.VoiceChannel): - threading.Thread.__init__(self, daemon=True) - self._bot = bot - self._member = member - self._channel_to = channel_to - - def run(self): - self._bot.loop.create_task(self._member.move_to(self._channel_to))