Added mass-move command #136

Merged
edraft merged 4 commits from #20 into 0.3 2022-11-21 19:00:35 +01:00
5 changed files with 69 additions and 1 deletions
Showing only changes of commit 0d1c15b31d - Show all commits

@ -1 +1 @@
Subproject commit 52d19fab6dcfd2e7bce068f01d0e15ddf7d43212
Subproject commit 57dd85de79d51893e5f5e5bd7f7d6065ba923f21

View File

@ -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)

View File

@ -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')

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,17 @@
import asyncio
import threading
import discord
from cpl_discord.service import DiscordBotServiceABC
class MassMoveThread(threading.Thread):
Ebola-Chan marked this conversation as resolved Outdated

Thread kann nu weg

Thread kann nu weg
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))