Ejemplo n.º 1
0
    async def description(client, message):
        prefix = client.command_processer.get_prefix_for(message)
        lines = [
            'Reloads the specified extension by it\'s name.',
            f'Usage : `{prefix}reload <name>`',
            '\nAvailable extensions:',
        ]
        for extension in EXTENSION_LOADER.extensions.values():
            lines.append(
                f'- `{extension.name}`{" (locked)" if extension.locked else ""}'
            )

        pages = [
            Embed('reload', chunk, color=KOISHI_HELP_COLOR)
            for chunk in chunkify(lines)
        ]

        limit = len(pages)
        index = 0
        while index < limit:
            embed = pages[index]
            index += 1
            embed.add_footer(f'page {index}/{limit}')

        return pages
Ejemplo n.º 2
0
async def test_webhook_response_avatar_url(client, message, avatar_url):
    """
    Creates a message with a webhook for checking whether avatar is included. Please include avatr url, hehe.
    """
    channel = message.channel
    result = ['']

    content = str(random_id())

    http_type = type(client.http)
    original_webhook_message_create = http_type.webhook_message_create

    async def replace_webhook_message_create(client, *args):
        data = await original_webhook_message_create(client, *args)
        if (data is not None) and (data.get('content') == content):
            result[0] = str(data)
        return data

    http_type.webhook_message_create = replace_webhook_message_create

    webhooks = await client.webhook_get_channel(channel)
    for webhook in webhooks:
        if webhook.type is WebhookType.bot:
            executor_webhook = webhook
            break

    else:
        executor_webhook = None

    if (executor_webhook is None):
        executor_webhook = await client.webhook_create(channel, 'tester')

    source_MESSAGE_CREATE = PARSERS['MESSAGE_CREATE']

    def replace_MESSAGE_CREATE(client, data):
        if data.get('content') == content:
            result.append(str(data))

        return source_MESSAGE_CREATE(client, data)

    PARSERS['MESSAGE_CREATE'] = replace_MESSAGE_CREATE

    message = await client.webhook_message_create(executor_webhook,
                                                  content,
                                                  avatar_url=avatar_url,
                                                  wait=True)

    http_type.webhook_message_create = original_webhook_message_create

    await sleep(1.0)

    if PARSERS['MESSAGE_CREATE'] is replace_MESSAGE_CREATE:
        PARSERS['MESSAGE_CREATE'] = source_MESSAGE_CREATE

    await Pagination(
        client, channel,
        [Embed(description=description) for description in chunkify(result)])
Ejemplo n.º 3
0
async def test_webhook_response_with_url(client, message, url):
    """
    Creates a message with a webhook for checking whether avatar is included.
    """
    channel = message.channel
    result = ['']

    content = str(random_id())

    http_type = type(client.http)
    original_webhook_message_create = http_type.webhook_message_create

    async def replace_webhook_message_create(client, *args):
        data = await original_webhook_message_create(client, *args)
        if data.get('content') == content:
            result[0] = str(data)
        return data

    http_type.webhook_message_create = replace_webhook_message_create

    source_MESSAGE_CREATE = PARSERS['MESSAGE_CREATE']

    def replace_MESSAGE_CREATE(client, data):
        if data.get('content') == content:
            result.append(str(data))

        return source_MESSAGE_CREATE(client, data)

    PARSERS['MESSAGE_CREATE'] = replace_MESSAGE_CREATE

    executor_webhook = Webhook.from_url(url)

    message = await client.webhook_message_create(executor_webhook,
                                                  content,
                                                  wait=True)

    http_type.webhook_message_create = original_webhook_message_create

    await sleep(1.0)

    if PARSERS['MESSAGE_CREATE'] is replace_MESSAGE_CREATE:
        PARSERS['MESSAGE_CREATE'] = source_MESSAGE_CREATE

    await Pagination(
        client, channel,
        [Embed(description=description) for description in chunkify(result)])
Ejemplo n.º 4
0
    async def command(self, message):
        bonk = sorted(list((await executor(self, DB.child('Tags').shallow().get().val))\
            or ['We dont have tags for now']))

        color = colourfunc(message)
        pages = [
            Embed('Tags', tag_name, color=color) for tag_name in chunkify(bonk)
        ]

        limit = len(pages)
        index = 0

        while index < limit:
            embed = pages[index]
            index += 1
            embed.add_footer(f'page {index}/{limit}')

        await Pagination(self, message.channel, pages)
Ejemplo n.º 5
0
async def voice_state(client, message):
    voice_client = client.voice_client_for(message)
    lines = []
    guild = message.guild
    if voice_client is None:
        title = f'No client in {guild.name}.'
    else:
        title = f'Client info for {guild.name}.'
        
        source = voice_client.source
        queue = voice_client.queue
        if (source is not None) or queue:
            if (source is not None):
                lines.append(f'Actual: {source.title}')
            
            for index, source in enumerate(queue, 1):
                lines.append(f'Track {index}.: {source.title}')
        
        audio_streams = voice_client.get_audio_streams()
        if audio_streams:
            if lines:
                lines.append('')
            
            lines.append('Receives')
            
            for index, (user, stream) in enumerate(audio_streams):
                lines.append(f'Stream {index}.: {user.full_name}, {stream!r}')
        
        audio_sources = voice_client._audio_sources
        if audio_sources:
            if lines:
                lines.append('')
            
            counter = 0
            for index, source in enumerate(audio_sources.values(), 1):
                lines.append(f'{index}.: {source}')
    
    color = VOICE_COLORS.get(client)
    pages = [Embed(title, chunk, color) for chunk in chunkify(lines)]
    
    await Pagination(client, message.channel, pages)
Ejemplo n.º 6
0
async def test_webhook_response(client,
                                message,
                                user: User,
                                use_user_avatar: int = 1):
    """
    Creates a message with a webhook for checking whether avatar is included.
    
    Also pass user maybe?
    """
    channel = message.channel
    result = ['']

    content = str(random_id())

    http_type = type(client.http)
    original_webhook_message_create = http_type.webhook_message_create

    async def replace_webhook_message_create(client, *args):
        data = await original_webhook_message_create(client, *args)
        if (data is not None) and (data.get('content') == content):
            result[0] = str(data)
        return data

    http_type.webhook_message_create = replace_webhook_message_create

    webhooks = await client.webhook_get_channel(channel)
    for webhook in webhooks:
        if webhook.avatar_type is ICON_TYPE_NONE:
            continue

        if webhook.type is WebhookType.bot:
            executor_webhook = webhook
            break

    else:
        executor_webhook = None

    if (executor_webhook is None):
        executor_webhook = await client.webhook_create(channel, 'tester')

    if not use_user_avatar:
        webhook_avatar_data = await client.download_url(user.avatar_url)
        await client.webhook_edit(executor_webhook, avatar=webhook_avatar_data)

    source_MESSAGE_CREATE = PARSERS['MESSAGE_CREATE']

    def replace_MESSAGE_CREATE(client, data):
        if data.get('content') == content:
            result.append(str(data))

        return source_MESSAGE_CREATE(client, data)

    PARSERS['MESSAGE_CREATE'] = replace_MESSAGE_CREATE

    if use_user_avatar:
        avatar_url = user.avatar_url
    else:
        avatar_url = None

    message = await client.webhook_message_create(executor_webhook,
                                                  content,
                                                  avatar_url=avatar_url,
                                                  wait=True)

    http_type.webhook_message_create = original_webhook_message_create

    await sleep(1.0)

    if PARSERS['MESSAGE_CREATE'] is replace_MESSAGE_CREATE:
        PARSERS['MESSAGE_CREATE'] = source_MESSAGE_CREATE

    await Pagination(
        client, channel,
        [Embed(description=description) for description in chunkify(result)])