Added filter to mass_move channel_from #296 #332

Merged
edraft-dev merged 1 commits from #296_mass_move_filter into 1.1.0 2023-08-14 21:01:03 +02:00
3 changed files with 34 additions and 2 deletions

View File

@ -25,8 +25,8 @@ class ModuleList:
[
CoreModule, # has to be first!
DataModule,
ConfigModule, # has to be before db check
DatabaseModule,
ConfigModule, # has be to after db check
GraphQLModule,
PermissionModule,
AutoRoleModule,

View File

@ -4,6 +4,7 @@ import discord
from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_translation import TranslatePipe
from discord.app_commands import Transform
from discord.ext import commands
from discord.ext.commands import Context
@ -11,6 +12,7 @@ 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
from modules.base.helper.voice_channel_transformer import VoiceChannelTransformer
class MassMoveCommand(DiscordCommandABC):
@ -36,7 +38,7 @@ class MassMoveCommand(DiscordCommandABC):
self,
ctx: Context,
channel_to: discord.VoiceChannel,
channel_from: discord.VoiceChannel = None,
channel_from: Transform[str, VoiceChannelTransformer] = None,
):
self._logger.debug(__name__, f"Received command mass-move {ctx}")

View File

@ -0,0 +1,30 @@
import discord
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_query.extension import List
from discord import Interaction, app_commands
from discord.app_commands import Transformer, Choice
from bot_core.abc.client_utils_abc import ClientUtilsABC
class VoiceChannelTransformer(Transformer):
async def transform(self, interaction: Interaction, value: str, /) -> discord.VoiceChannel:
voice_channel = (
List(discord.VoiceChannel, interaction.guild.voice_channels)
.where(lambda x: str(x.id) == value)
.first_or_default()
)
return voice_channel
async def autocomplete(self, interaction: Interaction, current: str, /) -> list[Choice[str]]:
@ServiceProviderABC.inject
def get_client_utils(client_utils: ClientUtilsABC) -> ClientUtilsABC:
return client_utils
voice_channels = List(discord.Role, interaction.guild.voice_channels).where(lambda x: len(x.members) > 0)
return [
app_commands.Choice(
name=f"{vc.name}" if vc.category is None else f"{vc.name}: {vc.category.name}", value=vc.name
)
for vc in get_client_utils().get_auto_complete_list(voice_channels, current, lambda x: x.name)
]