示例#1
0
    async def link(
        self,
        ctx: commands.Context,
        vc: typing.Optional[discord.VoiceChannel] = None,
        *,
        role_or_channel: typing.Union[discord.Role, discord.TextChannel,
                                      None] = None,
    ):
        """
        Links a role or text channel to a voice channel.

        When a member joins or leaves the channel, the role is applied accordingly.

        As well, if the related settings are enabled:
            When a member becomes deafened or undeafened, the role is applied accordingly.
            When a member becomes server muted or unmuted, the channel permissions are updated accordingly.

        If a role or channel is not set, the bot will update the other instead.
        """
        if not vc:
            if not ctx.author.voice:
                raise commands.MissingRequiredArgument(
                    # pylint: disable=no-member
                    inspect.signature(self.link.callback).parameters["vc"])
            vc = ctx.author.voice.channel
        assert vc
        if not role_or_channel:
            await self.config.channel(vc).clear()
            del self.channel_cache[vc.id]
            await ctx.send("Link(s) for {vc} cleared.".format(vc=vc))
        elif isinstance(role_or_channel, discord.Role):
            await self.config.channel(vc).role.set(role_or_channel.id)
            self.channel_cache[vc.id]["role"] = role_or_channel.id
            await ctx.send("Role for {vc} set to {role}.".format(
                vc=vc, role=role_or_channel))
        else:
            if vc == ctx.guild.afk_channel:
                return await ctx.send(
                    "Text channels cannot be linked to the guild's AFK channel."
                )
            await self.config.channel(vc).channel.set(role_or_channel.id)
            self.channel_cache[vc.id]["channel"] = role_or_channel.id
            await ctx.send("Text channel for {vc} set to {channel}".format(
                vc=vc, channel=role_or_channel))
示例#2
0
 def _maybe_fill_missing(
     cls,
     ctx: commands.Context,
     parameters: Dict[str, inspect.Parameter],
     kwargs: Dict[str, Any],
 ):
     ignore_optional_for_conversion = ctx.command.ignore_optional_for_conversion
     for name, param in parameters.items():
         if param.default is not param.empty:
             continue
         anno = param.annotation
         if (not ignore_optional_for_conversion
                 and get_origin(anno) is Union
                 and type(None) in get_args(anno)):
             kwargs[name] = None
         elif cls.__total__:
             raise commands.MissingRequiredArgument(param)
         else:
             kwargs[name] = cls.MISSING
示例#3
0
 async def convert(cls, ctx: commands.Context, argument: str):
     parameters = dict(inspect.signature(cls).parameters)
     parameter = None
     kwargs: Dict[str, Any] = {}
     old_view = ctx.view
     view = StringView(argument)
     ctx.view = view
     try:
         while not view.eof:
             if parameter:
                 kwargs[parameter.name], parameter = (
                     await ctx.command.transform(ctx, parameter),
                     None,
                 )
             else:
                 parameter = await cls._transform_identifier(
                     ctx, parameters, kwargs)
     finally:
         ctx.view = old_view
     if parameter:
         raise commands.MissingRequiredArgument(parameter)
     cls._maybe_fill_missing(ctx, parameters, kwargs)
     return cls(**kwargs)  # type: ignore
示例#4
0
def RaiseMissingArguement():
    raise commands.MissingRequiredArgument(
        inspect.Parameter("startdate", inspect.Parameter.POSITIONAL_ONLY))