Exemplo n.º 1
0
async def test_render_applications(client, message):
    """
    Renders the detectable applications.
    """
    applications = await client.applications_detectable()
    pages = [Embed(description=chunk) for chunk in pchunkify(applications)]
    await Pagination(client, message.channel, pages)
Exemplo n.º 2
0
async def test_render_application(client, message):
    """
    Renders the client's application.
    """
    pages = [
        Embed(description=chunk) for chunk in pchunkify(client.application)
    ]
    await Pagination(client, message.channel, pages)
Exemplo n.º 3
0
    async def command(client, message, content):
        user = _oauth2_query(message, content)
        if user is None:
            await client.message_create(message.channel,
                                        'Could not find that user')
            return

        await Pagination(
            client, message.channel,
            [Embed(description=chunk) for chunk in pchunkify(user)])
Exemplo n.º 4
0
async def test_list_invites(client, message):
    """
    Lists the invites of the respective guild.
    """
    guild = message.guild
    if guild is None:
        return

    invites = await client.invite_get_guild(guild)
    embeds = [Embed('Invites', chunk) for chunk in pchunkify(invites)]
    await Pagination(client, message.channel, embeds)
Exemplo n.º 5
0
 async def command(client, message, channel:ChannelBase=None):
     guild = message.channel.guild
     if channel is None:
         if not guild.cached_permissions_for(client).can_manage_guild:
             await client.message_create(message.channel,
                 'I dont have enough permission, to request the invites.')
             return
         invites = await client.invite_get_guild(guild)
     else:
         if not channel.cached_permissions_for(client).can_manage_channel:
             await client.message_create(message.channel,
                 'I dont have enough permission, to request the invites.')
             return
         invites = await client.invite_get_channel(channel)
     
     pages=[Embed(description=chunk) for chunk in pchunkify(invites,write_parents=False)]
     await Pagination(client, message.channel,pages,120.)
Exemplo n.º 6
0
async def test_channel_pretty_render(client, message):
    """
    Renders the local channels.
    """
    channel = message.channel
    guild = channel.guild
    if guild is None:
        to_render = channel
    else:
        to_render = guild.channels

    pages = [Embed(description=chunk) for chunk in pchunkify(to_render)]
    await Pagination(
        client,
        message.channel,
        pages,
    )
Exemplo n.º 7
0
    async def command(client, message, message_id: int,
                      channel: Converter('channel',
                                         default_code='message.channel')):
        if not channel.cached_permissions_for(client).can_read_message_history:
            await client.message_create(
                message.channel,
                'I am unable to read the messages at the specified channel.')
            return

        try:
            target_message = await client.message_get(channel, message_id)
        except DiscordException as err:
            await client.message_create(message.channel, err.__repr__())
            return
        await Pagination(
            client, message.channel,
            [Embed(description=chunk) for chunk in pchunkify(target_message)])
Exemplo n.º 8
0
async def test_get_webhooks(client, message):
    """
    Gets the webhooks of the guild.
    
    Guild only!
    """
    # make sure
    guild = message.guild
    if guild is None:
        return

    webhooks = await client.webhook_get_guild(guild, )
    pages = [Embed(description=chunk) for chunk in pchunkify(webhooks)]
    await Pagination(
        client,
        message.channel,
        pages,
    )
Exemplo n.º 9
0
async def test_get_integrations(client, message):
    """
    Gets the integrations of the guild.
    
    Guild only!
    """
    # make sure
    guild = message.guild
    if guild is None:
        return

    integrations = await client.integration_get_all(guild,
                                                    include_applications=True)
    pages = [Embed(description=chunk) for chunk in pchunkify(integrations)]
    await Pagination(
        client,
        message.channel,
        pages,
    )
Exemplo n.º 10
0
 async def command(client, message, guild:'guild'=None, user:User=None, event_name: str=''):
     if guild is None:
         guild = message.guild
         if guild is None:
             await client.message_create(message.channel,
                 'Cannot default to current guild. The command was not called from a guild.')
             return
     
     if not guild.cached_permissions_for(client).can_view_audit_logs:
         await client.message_create(message.channel,
             'I have no permissions at the guild, to request audit logs.')
         return
     
     while True:
         if not event_name:
             event=None
             break
         
         try:
             event = AuditLogEvent.INSTANCES[int(event_name)]
             break
         except (KeyError, ValueError):
             pass
         
         try:
             event = getattr(AuditLogEvent, event_name.upper())
             break
         except AttributeError:
             pass
         
         event = None
         break
 
     with client.keep_typing(message.channel):
         iterator = client.audit_log_iterator(guild,user,event)
         await iterator.load_all()
         logs = iterator.transform()
     
     await Pagination(client, message.channel, [Embed(description=chunk) for chunk in pchunkify(logs)])
Exemplo n.º 11
0
async def message_(
    client,
    event,
    message: ('str', 'Link to the message'),
    raw: ('bool', 'Should display json?') = True,
):
    """Shows up the message's payload."""
    if not event.user.has_role(ROLE__NEKO_DUNGEON__TESTER):
        abort(
            f'You must have {ROLE__NEKO_DUNGEON__TESTER.mention} to invoke this command.'
        )

    if not event.channel.cached_permissions_for(client).can_send_messages:
        abort('I need `send messages` permission to execute this command.')

    message_reference = parse_message_reference(message)
    if message_reference is None:
        abort('Could not identify the message.')

    guild_id, channel_id, message_id = message_reference
    try:
        message = MESSAGES[message_id]
    except KeyError:
        if channel_id:
            try:
                channel = CHANNELS[channel_id]
            except KeyError:
                abort('I have no access to the channel.')
                return
        else:
            channel = event.channel

        if not channel.cached_permissions_for(client).can_read_message_history:
            abort('I have no permission to get that message.')

        # We only really need `channel_id` and `guild_id`, so we can ignore `guild_id`.

        if raw:
            getter_coroutine = client.http.message_get(channel.id, message_id)
        else:
            getter_coroutine = client.message_get(channel, message_id)
    else:
        if raw:
            getter_coroutine = client.http.message_get(message.channel.id,
                                                       message_id)
        else:
            getter_coroutine = None

    if (getter_coroutine is not None):
        try:
            response = await getter_coroutine
            if raw:
                data = response
            else:
                message = response
        except ConnectionError:
            # No internet
            return
        except DiscordException as err:
            if err.code in (
                    ERROR_CODES.unknown_channel,  # message deleted
                    ERROR_CODES.unknown_message,  # channel deleted
            ):
                # The message is already deleted.
                abort('The referenced message is already yeeted.')

            if err.code == ERROR_CODES.missing_access:  # client removed
                abort('The client is not in the guild / channel')

            if err.code == ERROR_CODES.missing_permissions:  # permissions changed meanwhile
                abort('I have no permission to get that message.')

            raise

    if raw:
        chunks = cchunkify(
            json.dumps(data, indent=4, sort_keys=True).splitlines())
    else:
        chunks = pchunkify(message)

    pages = [Embed(description=chunk) for chunk in chunks]
    await Pagination(client, event, pages)
Exemplo n.º 12
0
async def invites_(
    client,
    event,
    channel: ('channel',
              'Which channel\'s invites do you wanna check?') = None,
):
    """Shows up the guild's or the selected channel's invites."""
    guild = event.guild
    if guild is None:
        abort('Guild only command')

    if guild not in client.guild_profiles:
        abort('I must be in the guild to execute the command.')

    if (channel is not None) and isinstance(channel, ChannelCategory):
        abort('Category channels have no invites.')

    if not event.channel.cached_permissions_for(client).can_send_messages:
        abort(
            'I must have `send messages` permission to invoke this command correctly.'
        )

    if channel is None:
        permissions = event.user_permissions
        if (not permissions.can_create_instant_invite) or (
                not permissions.can_manage_guild):
            abort(
                'You must have `create instant invite` and `manage guild` permission to invoke this command.'
            )

        permissions = guild.cached_permissions_for(client)
        if (not permissions.can_create_instant_invite) or (
                not permissions.can_manage_guild):
            abort(
                'I must have `create instant invite` and `manage guild` to invite to execute this command.'
            )

    else:
        permissions = event.user_permissions
        if (not permissions.can_create_instant_invite) or (
                not permissions.can_manage_channel):
            abort(
                'You must have `create instant invite` and `manage channel` permission to invoke this command.'
            )

        permissions = channel.cached_permissions_for(client)
        if (not permissions.can_create_instant_invite) or (
                not permissions.can_manage_channel):
            abort(
                'I must have `create instant invite` and `manage channel` to invite to execute this command.'
            )

    yield

    if channel is None:
        coroutine = client.invite_get_all_guild(guild)
    else:
        coroutine = client.invite_get_all_guild(guild)
    invites = await coroutine

    pages = [
        Embed(description=chunk)
        for chunk in pchunkify(invites, write_parents=False)
    ]

    if channel is None:
        check = check_guild_invites_pagination_permissions
    else:
        check = check_channel_invites_pagination_permissions

    await Pagination(client, event, pages, timeout=120., check=check)