Example #1
0
 async def king(self, ctx: Context, player1: Member, player2: Member,
                player3: Member, *players: Member):
     players = list(players)
     players.extend((player1, player2, player3))
     tasks = list()
     king = None
     i = 0
     count_description = literals('king')['count'] % (len(players) - 1)
     footer = literals('king')['footer']
     while len(players):
         player1 = players.pop(randrange(0, len(players)))
         if i == 0:
             king = player1
         else:
             embed = ChainedEmbed(title=literals('king')['number'] % i,
                                  description=count_description)
             embed.set_footer(text=footer)
             tasks.append(player1.send(embed=embed))
         i = i + 1
     embed = ChainedEmbed(title=literals('king')['king'] %
                          king.display_name,
                          description=count_description)
     embed.set_image(url=king.avatar_url)
     embed.set_footer(text=footer)
     tasks.append(
         ctx.send(' '.join(
             [member.mention for member in ctx.message.mentions]),
                  embed=embed))
     tasks.append(ctx.message.delete())
     await asyncio.wait(tasks)
Example #2
0
 async def send_cog_info(self, ctx: Context, cog: Cog):
     cog_name = cog.qualified_name
     if isinstance(cog, CustomCog):
         cog_name = cog.emoji + ' ' + cog_name
     brief = brief_cog(cog)
     embeds = ChainedEmbed(title=cog_name, description=brief)
     embeds.set_thumbnail(url=self.client.user.avatar_url)
     for embed in embeds.to_list():
         await ctx.send(embed=embed)
Example #3
0
def check_correlation(command: Command, keywords: List[str], embed: ChainedEmbed):
    found = 0
    command_info = stringify_command(command)
    for keyword in keywords:
        if keyword in command_info:
            embed.add_field(name=command.qualified_name, value=command_info)
            found += 1
        break
    if isinstance(command, CustomGroup):
        for subcommand in command.commands:
            found += check_correlation(subcommand, keywords, embed)
    return found
Example #4
0
 async def deck_list(self, ctx: Context):
     literal = literals('deck_list')
     list_embeds = ChainedEmbed(
         title=literal['title'],
         description='\n'.join([
             deck.get_brief()
             for deck in sorted(self.deck_handler.decks.values(),
                                key=lambda item: item.id)
         ]))
     list_embeds.set_thumbnail(url=self.client.user.avatar_url)
     for embed in list_embeds.to_list():
         await ctx.send(embed=embed)
Example #5
0
 def get_chip_embed(self):
     literal = literals('get_chip_embed')
     chip_embed = ChainedEmbed(title=literal['chip_title'],
                               description=literal['chip_description'])
     chip_embed.add_field(name=literal['chip_name'] % self.indian1.user,
                          value=IndianPoker.get_chip_str(self.indian1.chip))
     chip_embed.add_field(name=literal['betting_name'] % self.indian1.user,
                          value=IndianPoker.get_chip_str(
                              self.indian1.betting))
     chip_embed.add_field(name=literal['chip_name'] % self.indian2.user,
                          value=IndianPoker.get_chip_str(self.indian2.chip))
     chip_embed.add_field(name=literal['betting_name'] % self.indian2.user,
                          value=IndianPoker.get_chip_str(
                              self.indian2.betting))
     return chip_embed
Example #6
0
 async def yacht_help(self, ctx: Context):
     literal = literals('yacht_help')
     help_embed: ChainedEmbed = ChainedEmbed(
         title=literal['title'], description=literal['description'])
     for field in literal['fields']:
         help_embed.add_field(name=field['name'], value=field['value'])
     await ctx.send(embed=help_embed)
Example #7
0
 def get_score_embed(self) -> ChainedEmbed:
     literal = literals('get_score_embed')
     score_embed = ChainedEmbed(title=literal['title'] % self.round,
                                description=literal['description'] %
                                self.get_total_score())
     for i in range(len(CATEGORIES)):
         score = self.scores[CATEGORIES[i]]
         if score == -1:
             score = self.get_score_of_category(CATEGORIES[i])
             name = literal['name']
             value = literal['value']
         else:
             name = literal['done_name']
             value = literal['done_value']
         score_embed.add_field(name=name %
                               (CATEGORIES[i][1], CATEGORIES[i][0]),
                               inline=True,
                               value=value % score)
     return score_embed
Example #8
0
 def get_dice_embed(self, rerolled: int = 3) -> ChainedEmbed:
     literal = literals('get_dice_embed')
     sorted_dice = sorted(self.dice.items(), key=lambda item: item[1])
     description = ' '.join([d[0] for d in sorted_dice]) + '\n' + ' '.join(
         [DICE_DIE[d[1] - 1] for d in sorted_dice])
     dice_embed: ChainedEmbed = ChainedEmbed(
         title=literal['title'] %
         (self.round, literal['rerolled'][rerolled]),
         description=description)
     return dice_embed
Example #9
0
 async def send_cog_list(self, ctx: Context):
     literal = literals('send_cog_list')
     states = list()
     count = len(self.client.cogs)
     message = None
     for i, cog in enumerate(sorted(self.client.cogs.items(),
                                    key=lambda item: get_cog(type(item[1]).__name__)['priority'])):
         name, cog = cog
         if isinstance(cog, CustomCog):
             name = cog.emoji + ' ' + name
         page_embed = ChainedEmbed(title=literal['title'], description=literal['description'])
         page_embed.set_thumbnail(url=self.client.user.avatar_url)
         page_embed.add_field(name=name, value=brief_cog(cog))
         page_embed.set_footer(text=literal['footer'] % (i + 1, count))
         if message is None:
             message = await ctx.send(embed=page_embed)
         states.append(InterfaceState(callback=message.edit, embed=page_embed))
     await attach_page_interface(self.client, message, states, user=ctx.author)
Example #10
0
 async def search(self, ctx: Context, keyword: str, *keywords: str):
     literal = literals('search')
     keywords = list(keywords)
     keywords.append(keyword)
     description = literal['found']
     embeds = ChainedEmbed(title=literal['title'], description=description)
     embeds.set_thumbnail(url=self.client.user.avatar_url)
     found = 0
     for command in self.client.commands:
         found += check_correlation(command, keywords, embeds)
     embeds.description = description % (found, ', '.join(keywords)) if found \
         else literal['not_found'] % ', '.join(keywords)
     for embed in embeds.to_list():
         await ctx.send(embed=embed)
Example #11
0
def get_application_embed(data: list):
    literal = literals('get_application_embed')
    discord_id = data[APPLICATION_DISCORD_ID]
    title = literal['title'] % discord_id + get_application_state_emoji(data)
    embeds = ChainedEmbed(
        title=title,
        description=literal['description'] %
        (data[APPLICATION_TIMESTAMP], data[APPLICATION_EMAIL]))
    if data[APPLICATION_SUBACCOUNT] != literal['false']:
        embeds.add_field(name=literal['subaccount'],
                         value=literal['mainaccount'] %
                         data[APPLICATION_SUBACCOUNT])
    if data[APPLICATION_NICKNAME]:
        embeds.add_field(name=literal['nickname'],
                         value='**' + data[APPLICATION_NICKNAME] + '**')
    if data[APPLICATION_DISCORD_ID]:
        embeds.add_field(name=literal['discord_id'],
                         value='`' + data[APPLICATION_DISCORD_ID] + '`',
                         inline=True)
    if data[APPLICATION_INVITER]:
        embeds.add_field(name=literal['inviter'],
                         value='`' + data[APPLICATION_INVITER] + '`',
                         inline=True)
    if data[APPLICATION_PERIOD]:
        embeds.add_field(name=literal['period'],
                         value='**' + data[APPLICATION_PERIOD] + '**',
                         inline=True)
    if data[APPLICATION_TWITTER_ID]:
        embeds.add_field(name=literal['twitter_id'],
                         value='`' + data[APPLICATION_TWITTER_ID] + '`',
                         inline=True)
    if data[APPLICATION_KNOWLEDGE]:
        embeds.add_field(name=literal['knowledge'],
                         value='```\n' + data[APPLICATION_KNOWLEDGE] + '\n```')
    if data[APPLICATION_REMARKS]:
        embeds.add_field(name=literal['remarks'],
                         value='```\n' + data[APPLICATION_REMARKS] + '\n```')
    return embeds
Example #12
0
async def get_guild_profile_embed(guild: Guild, brief: bool = True):
    literal = literals('get_guild_profile_embed')
    online_members = (await guild.widget()).members
    description = literal['description'] % (guild.region, guild.member_count)
    if guild.premium_tier:
        description += '\n' + literal['tier'] % guild.premium_tier
    if online_members:
        description += '\n' + (literal['online'] % len(online_members))
    guild_embed = ChainedEmbed(title=guild.name, description=description)
    guild_embed.set_author(name=literal['author'] % guild.owner.name,
                           icon_url=guild.owner.avatar_url)
    guild_embed.set_thumbnail(url=guild.icon_url)
    if not brief:
        if guild.premium_subscription_count:
            guild_embed.add_field(
                name=literal['boost'] % guild.premium_subscription_count,
                value='\n'.join(
                    str(subscriber)
                    for subscriber in guild.premium_subscribers))
        guild_embed.set_footer(text=f'{to_kst(guild.created_at)} · {guild.id}')
        guild_embed.set_image(url=guild.banner_url)
        if guild.channels:
            value = literal['category'] % len(guild.categories)
            value += '\n' + literal['text_channel'] % len(guild.text_channels)
            value += '\n' + literal['voice_channel'] % len(
                guild.voice_channels)
            guild_embed.add_field(name=literal['channel'] %
                                  len(guild.channels),
                                  value=value)
    return guild_embed
Example #13
0
def get_profile_embed(user: User, brief: bool = True):
    literal = literals('get_profile_embed')
    profile_embed = ChainedEmbed(title=user.display_name,
                                 color=user.colour,
                                 description=str(user))
    profile_embed.set_thumbnail(url=user.avatar_url)
    if isinstance(user, Member):
        profile_embed.set_author(name=user.guild.name + ' ' +
                                 user.top_role.name,
                                 icon_url=user.guild.icon_url)
    if not brief:
        profile_embed.set_image(url=user.avatar_url)
        profile_embed.set_footer(text=f'{to_kst(user.created_at)} · {user.id}')
        if isinstance(user, Member):
            profile_embed.add_field(name=literal['join'],
                                    value=to_kst(user.joined_at))
            if user.premium_since:
                profile_embed.add_field(name=literal['boost'],
                                        value=to_kst(user.premium_since))
            if roles := user.roles[1:]:
                roles.reverse()
                profile_embed.add_field(name=literal['roles'],
                                        value='\n'.join(
                                            [role.name for role in roles]))
Example #14
0
 def get_custom_emoji_embed(self, emoji_id: int):
     emoji: PartialEmoji = self.client.get_emoji(emoji_id)
     embed = ChainedEmbed()
     embed.set_image(url=emoji.url)
     embed.set_author(name=f':{emoji.name}:')
     return embed
Example #15
0
 def get_card_embed(player: Indian):
     literal = literals('get_card_embed')
     if player.card:
         return ChainedEmbed(title=literal['card_title'] % player.user,
                             description=literal['emoji'][player.card - 1])
     return None
Example #16
0
 async def get_deck_embed(self,
                          deck: Deck,
                          brief: bool = True) -> ChainedEmbed:
     literal = literals('get_deck_embed')
     deck_embed = ChainedEmbed(title=literal['title'] % deck.name,
                               description=deck.topic)
     deck_role = discord.utils.get(await
                                   self.deck_handler.guild.fetch_roles(),
                                   name=deck.name)
     deck_members = list()
     async for member in self.deck_handler.guild.fetch_members():
         if deck_role in member.roles:
             deck_members.append(str(member))
     deck_embed.set_thumbnail(url=deck.manager.avatar_url)
     deck_embed.add_field(name=literal['manager'], value=str(deck.manager))
     if deck.public:
         deck_embed.add_field(name=literal['public_name'],
                              value=literal['public_value'])
     if deck.nsfw:
         deck_embed.add_field(name=literal['nsfw_name'],
                              value=literal['nsfw_value'])
     if deck.auto:
         deck_embed.add_field(name=literal['auto_name'],
                              value=literal['auto_value'])
     if deck.lock:
         deck_embed.add_field(name=literal['lock_name'],
                              value=literal['lock_value'])
     if deck.pending:
         deck_embed.add_field(name=literal['pending'] % len(deck.pending),
                              value=' '.join(
                                  [str(member) for member in deck.pending]))
     if not brief:
         if deck_members:
             deck_embed.add_field(name=literal['members'] %
                                  len(deck_members),
                                  value='\n'.join(deck_members),
                                  inline=True)
         channels = list()
         for channel in deck.category_channel.channels:
             channels.append(
                 (literal['voice'] if isinstance(channel, VoiceChannel
                                                 ) else '') +
                 (channel.name if channel != deck.default_channel else
                  f'**__{channel.name}__**'))
         deck_embed.add_field(name=literal['channels'] %
                              len(deck.category_channel.channels),
                              value='\n'.join(channels),
                              inline=True)
     deck_embed.set_footer(text=literal['id'] % deck.id)
     return deck_embed
Example #17
0
 async def send_command_help(self, ctx: Context, command: Command):
     literal = literals('send_command_help')
     command_name = command.qualified_name
     default_signature = get_command_default_signature(command)
     footer = get_command_signature(command)
     description = ''
     if command.help is not None:
         description = command.help + '\n'
     elif command.brief is not None:
         description = command.brief + '\n'
     description += f'`{default_signature}`'
     embeds = ChainedEmbed(title=get_constant('default_prefix') + command_name, description=description)
     embeds.set_thumbnail(url=self.client.user.avatar_url)
     if not command.enabled:
         embeds.add_field(name=literal['disabled_name'], value=literal['disabled_value'])
     if isinstance(command, CustomGroup):
         embeds.add_field(name=literal['subcommand'],
                          value=f'\n{brief_group(command)}\n')
     for check in command.checks:
         data = get_check(check.name)
         if data is None:
             continue
         embeds.add_field(name=f'{data["emoji"]} {data["name"]}', value=data["description"])
     if command.cog is not None:
         category = command.cog.qualified_name
         if isinstance(command.cog, CustomCog):
             category = command.cog.emoji + ' ' + category
         footer += ' · ' + category
     embeds.set_footer(text=footer)
     for embed in embeds.to_list():
         await ctx.send(embed=embed)