Exemplo n.º 1
0
 def no_dm_check(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage('No Private Hacking!!')
     return True
Exemplo n.º 2
0
 def predicate(ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage()
     elif ctx.guild.id != must_be_in_guild_id:
         raise NotInServer(must_be_in_guild_id=must_be_in_guild_id)
     return True
Exemplo n.º 3
0
    def cog_check(self, ctx: commands.Context):
        if not ctx.guild:
            raise commands.NoPrivateMessage('This command can\'t be used in DM channels.')

        return True
Exemplo n.º 4
0
async def option_picker(ctx,
                        *options,
                        timeout: float = 300,
                        formatter=option_picker_formatter,
                        option_formatter=str,
                        max_lines: int = 6) -> typing.Any:
    """
    Displays a list of options, enabling the user to pick one by
    providing input. If the user closes the pagination of options, we assume
    this to be closing the option picker, and we return None.
    If timeout is reached, we return None.
    :param ctx: the command context, or a tuple of bot, message, and channel
    :param options: the options to show.
    :param timeout: timeout to wait for before killing the prompt.
    :param formatter: the formatter for each page of options.
    :param option_formatter: the formatter to use to get what to display
        for each option.
    :param max_lines: the max lines to show per page.
    """
    if isinstance(ctx, commands.Context):
        bot, message, channel = ctx.bot, ctx.message, ctx.channel
    else:
        bot, message, channel = ctx

    if message.guild is None:
        raise commands.NoPrivateMessage('Option pickers will not work in DMs.')

    binder = bookbinding.StringBookBinder(ctx,
                                          max_lines=max_lines,
                                          timeout=None)

    binder.with_page_number_formatter(formatter)

    for i, option in enumerate(options):
        binder.add_line(f'{i + 1} - {option_formatter(option)!s}',
                        dont_alter=True)

    book = binder.build()

    async def run_options_view():
        await book.start()
        raise ClosedInterrupt

    def predicate(response):
        return response.author == message.author and \
               response.channel == message.channel

    async def get_option():
        # Raises a ResultPickedInterrupt when finished.
        user_input = None

        while user_input is None:
            m = await bot.wait_for('message', check=predicate, timeout=timeout)

            content = m.content

            try:
                option_num = int(content)

                if option_num < 1 or option_num > len(options):
                    raise IndexError
            except IndexError:
                await channel.send('Out of range', delete_after=5)
                continue
            except ValueError:
                await channel.send('Cancelling...', delete_after=5)
                await helpers.attempt_delete(m)
                raise ClosedInterrupt
            else:
                await helpers.attempt_delete(m)

            raise ResultPickedInterrupt(options[option_num - 1])

    try:
        option, _ = await asyncio.gather(get_option(), run_options_view())
    except ResultPickedInterrupt as result:
        return result.result
    except ClosedInterrupt:
        return None
    except asyncio.TimeoutError:
        return None
    except discord.Forbidden as ex:
        raise ex from None
    finally:
        try:
            if book.is_running():
                await book.delete()
                await book.__aexit__(None, None, None)
        except:
            pass
Exemplo n.º 5
0
 def predicate(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage()
     _bot_has_permissions(ctx, kick_members=True)
     return True
Exemplo n.º 6
0
async def is_allowed_in_all_guild_channels(context):
    if context.channel.type.name == 'private':
        raise commands.NoPrivateMessage()
    return True
Exemplo n.º 7
0
 def predicate(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage()
     return True
Exemplo n.º 8
0
 async def __local_check(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage(
             "Settings can't be modified on private messages.")
     return True
Exemplo n.º 9
0
 def cog_check(self, ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage(
             "This command can only be used within a guild")
     return True
Exemplo n.º 10
0
 async def cog_check(self, ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage(
             'This command cannot be used in private messages.')
     return True
Exemplo n.º 11
0
 def cog_check(self, ctx: commands.Context):
     if not ctx.guild:
         raise commands.NoPrivateMessage("This command can not be used in DMs.")
     return True
Exemplo n.º 12
0
    def cog_check(self, ctx: commands.Context):
        if not ctx.guild:
            raise commands.NoPrivateMessage('xD go get in a server silly!')

        return True
Exemplo n.º 13
0
 def cog_check(self, ctx):
     if ctx.guild is None:
         raise dpy_commands.NoPrivateMessage(
             "Moderation commands can't be used in DMs")
     return True
Exemplo n.º 14
0
    def cog_check(self, ctx: commands.Context):
        if not ctx.guild:
            raise commands.NoPrivateMessage(
                'Bu komut özel mesaj olarak kullanılamaz')

        return True
Exemplo n.º 15
0
 async def cog_check(self, ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage("Tag commands cannot be used in DMs")
     else:
         return True
Exemplo n.º 16
0
 def __local_check(self, ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage(
             '**This command cannot be used in a private message.**')
     return True
Exemplo n.º 17
0
 def cog_check(self, ctx):
     """Check function called before any command of the cog."""
     if ctx.guild is None:
         raise commands.NoPrivateMessage()
     return True
Exemplo n.º 18
0
 def cog_check(self, ctx: commands.Context):
     if not ctx.guild:
         raise commands.NoPrivateMessage('Эту команду нельзя использовать в личке.')
     return True
Exemplo n.º 19
0
 def cog_check(self, ctx):
     """Extra checks for the cog's commands."""
     if not ctx.guild:
         raise commands.NoPrivateMessage(
             'This command cannot be used in a private message.')
     return True
Exemplo n.º 20
0
 async def predicate(ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage()
     if ctx.guild.owner != ctx.author:
         raise NotGuildOwner()
     return True
Exemplo n.º 21
0
 def cog_check(self, ctx):
     if not ctx.guild:
         raise commands.NoPrivateMessage()
     if ctx.guild.owner != ctx.author:
         raise base.NotGuildOwner()
     return True
Exemplo n.º 22
0
    def cog_check(self, ctx: commands.Context):
        if not ctx.guild:
            raise commands.NoPrivateMessage('Questo comando non può essere usato in DM')

        return True
Exemplo n.º 23
0
async def globally_block_dms(ctx):
    if ctx.guild is None:
        raise commands.NoPrivateMessage("No dm allowed!")
    else:
        return True
Exemplo n.º 24
0
 async def cog_check(self, ctx: KurisuContext):
     if ctx.guild is None and ctx.command.name != "listwarns":
         raise commands.NoPrivateMessage()
     return True
Exemplo n.º 25
0
 def predicate(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage()
     _has_permissions(ctx, manage_messages=True)
     return True
Exemplo n.º 26
0
 def no_dm_check(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage('Private messages not permitted.')
     return True
Exemplo n.º 27
0
 async def cog_check(self, ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage()
     return True
Exemplo n.º 28
0
 def no_dm_check(ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage("I refuse.")
     return True
Exemplo n.º 29
0
 def __local_check(self, ctx):
     if ctx.guild is None:
         raise commands.NoPrivateMessage(
             'This command cannot be used in private messages.')
     return True
Exemplo n.º 30
0
 def no_dm_check(ctx):
     """ Check for DMs """
     if ctx.guild is None:
         raise commands.NoPrivateMessage("Private messages not permitted.")
     return True