general.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:Excalibot 作者: endreman0 项目源码 文件源码
def color_list(self, ctx, per_page : int = 6):
        """Lists all named colors available."""
        colors = [(' '.join(word.title() for word in name.split('_')), color, str(color).upper()) for name, color in self._colors()]
        colors += [('Default', discord.Color(0), '#000000')] * (6 - len(colors) % 6)
        per_page = 6
        letter_emoji = abc_emoji[:per_page]
        pages = [discord.Embed() for page_num in range(math.ceil(len(colors) / per_page))]
        def update_embeds(shown):
            for page_num, page in enumerate(pages):
                page_colors = colors[page_num*per_page:][:per_page] # Two slices is more readable than [page_num*per_page:page_num*per_page + per_page]
                page.color = page_colors[shown][1]
                for field_num, (name, _, hex_) in enumerate(page_colors):
                    page.set_field_at(
                        field_num,
                        name='{}: {}{}'.format(string.ascii_uppercase[field_num], name, ' (shown)' if field_num == shown else ''),
                        value=hex_
                    )

        for i, _ in enumerate(colors):
            pages[i // per_page].add_field(name='', value='') # Add fields so set_field_at in update_embeds is valid
        update_embeds(0)

        reactor = react.Paginator(ctx, (..., *letter_emoji), pages)
        async for reaction in reactor:
            if reaction in letter_emoji:
                update_embeds(letter_emoji.index(reaction))
                reactor.next(0) # Re-send the same embed to show updated color and names
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号