recruitment/cr.py
async def command_cwr(
        self, ctx, member: Optional[discord.Member] = None, account: int = 1
    ):
        """View yours or other's clash royale CWR"""
        member = member or ctx.author
        pages = list()
        async with ctx.channel.typing():
            try:
                player_tag = self.tags.getTag(member.id, account)
                if player_tag is None:
                    return await ctx.send(
                        "You need to first save your profile using ``{}save #tag``".format(
                            ctx.prefix
                        )
                    )
                player_data = await self.clash.get_player(player_tag)
                leagues = await self.discord_helper.clanwar_readiness(player_data.cards)
            # REMINDER: Order is important. RequestError is base exception class.
            except AttributeError:
                return await ctx.send(
                    "Cannot connect to database. Please notify the devs."
                )
            except clashroyale.NotFoundError:
                return await ctx.send("Player tag is invalid.")
            except clashroyale.RequestError:
                return await ctx.send(
                    "Error: cannot reach Clash Royale Servers. Please try again later."
                )

            emote_mapper = {
                "legendary": self.discord_helper.emoji("legendleague"),
                "gold": self.discord_helper.emoji("goldleague"),
                "silver": self.discord_helper.emoji("silverleague"),
                "bronze": self.discord_helper.emoji("bronzeleague"),
            }

            embed = discord.Embed(color=0xFAA61A,)
            embed.set_author(
                name=player_data.name + " (" + player_data.tag + ")",
                icon_url=await self.constants.get_clan_image(player_data),
                url="https://royaleapi.com/player/" + player_data.tag.strip("#"),
            )
            embed.set_footer(text=credits, icon_url=credits_icon)
            embed.add_field(
                name="War Day Wins",
                value="{} {}".format(
                    self.discord_helper.emoji("warwin"), player_data.war_day_wins,
                ),
                inline=True,
            )
            embed.add_field(
                name="War Cards Collected",
                value="{} {}".format(
                    self.discord_helper.emoji("card"), player_data.clan_cards_collected,
                ),
                inline=True,
            )
            highest_league = None
            for l in leagues.keys():
                highest_league = l
                if leagues[l]["percent"] == 100:
                    break
            for league in leagues.keys():
                f_title = "{} {} League (Lvl {}) - {}%\n\u200b".format(
                    emote_mapper[league],
                    leagues[league]["name"],
                    leagues[league]["levels"],
                    leagues[league]["percent"],
                )
                value = []
                if len(leagues[league]["cards"]) > 20:
                    group = leagues[league]["cards"][:20]
                else:
                    group = leagues[league]["cards"]
                for card in group:
                    if card is not None:
                        emoji = await self.discord_helper.get_card_emoji(card)
                        if emoji:
                            value.append(emoji)
                        else:
                            value.append(f" {card} ")
                if len(value):
                    not_shown = len(leagues[league]["cards"]) - len(value)
                    value = " ".join(value)
                    value += f"+{not_shown} more\n\n\n" if not_shown else "\n\n\n"
                    embed.add_field(
                        name=f_title, value=value, inline=False,
                    )
                    if league != highest_league:
                        embed.add_field(name="\u200b", value="\u200b", inline=False)
            pages.append(embed)

            for league in leagues.keys():
                f_title = "{} {} League (Lvl {}) - {}%\n\u200b".format(
                    emote_mapper[league],
                    leagues[league]["name"],
                    leagues[league]["levels"],
                    leagues[league]["percent"],
                )
                embed = discord.Embed(color=0xFAA61A, title="Clan War Readiness",)
                embed.set_author(
                    name=player_data.name + " (" + player_data.tag + ")",
                    icon_url=await self.constants.get_clan_image(player_data),
                    url="https://royaleapi.com/player/" + player_data.tag.strip("#"),
                )
                embed.set_footer(text=credits, icon_url=credits_icon)
                groups = list(self.discord_helper.grouper(leagues[league]["cards"], 15))

                for index, group in enumerate(groups):
                    value = []
                    for card in group:
                        if card is not None:
                            emoji = await self.discord_helper.get_card_emoji(card)
                            if emoji:
                                value.append(emoji)
                            else:
                                value.append(f" {card} ")

                    if len(value):
                        value = " ".join(value)

                        embed.add_field(
                            name=f_title if index == 0 else "\u200b",
                            value=value,
                            inline=False,
                        )
                if groups:
                    pages.append(embed)
        return await menu(ctx, pages, DEFAULT_CONTROLS, timeout=60)
View yours or other's clash royale CWR
View yours or other's clash royale CWR
View yours or other ' s clash royale CWR
async def command_cwr(
        self, ctx, member: Optional[discord.Member] = None, account: int = 1
    ):
        member = member or ctx.author
        pages = list()
        async with ctx.channel.typing():
            try:
                player_tag = self.tags.getTag(member.id, account)
                if player_tag is None:
                    return await ctx.send(
                        "You need to first save your profile using ``{}save #tag``".format(
                            ctx.prefix
                        )
                    )
                player_data = await self.clash.get_player(player_tag)
                leagues = await self.discord_helper.clanwar_readiness(player_data.cards)
            except AttributeError:
                return await ctx.send(
                    "Cannot connect to database. Please notify the devs."
                )
            except clashroyale.NotFoundError:
                return await ctx.send("Player tag is invalid.")
            except clashroyale.RequestError:
                return await ctx.send(
                    "Error: cannot reach Clash Royale Servers. Please try again later."
                )
            emote_mapper = {
                "legendary": self.discord_helper.emoji("legendleague"),
                "gold": self.discord_helper.emoji("goldleague"),
                "silver": self.discord_helper.emoji("silverleague"),
                "bronze": self.discord_helper.emoji("bronzeleague"),
            }
            embed = discord.Embed(color=0xFAA61A,)
            embed.set_author(
                name=player_data.name + " (" + player_data.tag + ")",
                icon_url=await self.constants.get_clan_image(player_data),
                url="https://royaleapi.com/player/" + player_data.tag.strip("#"),
            )
            embed.set_footer(text=credits, icon_url=credits_icon)
            embed.add_field(
                name="War Day Wins",
                value="{} {}".format(
                    self.discord_helper.emoji("warwin"), player_data.war_day_wins,
                ),
                inline=True,
            )
            embed.add_field(
                name="War Cards Collected",
                value="{} {}".format(
                    self.discord_helper.emoji("card"), player_data.clan_cards_collected,
                ),
                inline=True,
            )
            highest_league = None
            for l in leagues.keys():
                highest_league = l
                if leagues[l]["percent"] == 100:
                    break
            for league in leagues.keys():
                f_title = "{} {} League (Lvl {}) - {}%\n\u200b".format(
                    emote_mapper[league],
                    leagues[league]["name"],
                    leagues[league]["levels"],
                    leagues[league]["percent"],
                )
                value = []
                if len(leagues[league]["cards"]) > 20:
                    group = leagues[league]["cards"][:20]
                else:
                    group = leagues[league]["cards"]
                for card in group:
                    if card is not None:
                        emoji = await self.discord_helper.get_card_emoji(card)
                        if emoji:
                            value.append(emoji)
                        else:
                            value.append(f" {card} ")
                if len(value):
                    not_shown = len(leagues[league]["cards"]) - len(value)
                    value = " ".join(value)
                    value += f"+{not_shown} more\n\n\n" if not_shown else "\n\n\n"
                    embed.add_field(
                        name=f_title, value=value, inline=False,
                    )
                    if league != highest_league:
                        embed.add_field(name="\u200b", value="\u200b", inline=False)
            pages.append(embed)
            for league in leagues.keys():
                f_title = "{} {} League (Lvl {}) - {}%\n\u200b".format(
                    emote_mapper[league],
                    leagues[league]["name"],
                    leagues[league]["levels"],
                    leagues[league]["percent"],
                )
                embed = discord.Embed(color=0xFAA61A, title="Clan War Readiness",)
                embed.set_author(
                    name=player_data.name + " (" + player_data.tag + ")",
                    icon_url=await self.constants.get_clan_image(player_data),
                    url="https://royaleapi.com/player/" + player_data.tag.strip("#"),
                )
                embed.set_footer(text=credits, icon_url=credits_icon)
                groups = list(self.discord_helper.grouper(leagues[league]["cards"], 15))
                for index, group in enumerate(groups):
                    value = []
                    for card in group:
                        if card is not None:
                            emoji = await self.discord_helper.get_card_emoji(card)
                            if emoji:
                                value.append(emoji)
                            else:
                                value.append(f" {card} ")
                    if len(value):
                        value = " ".join(value)
                        embed.add_field(
                            name=f_title if index == 0 else "\u200b",
                            value=value,
                            inline=False,
                        )
                if groups:
                    pages.append(embed)
        return await menu(ctx, pages, DEFAULT_CONTROLS, timeout=60)
async def command_cwr ( self , ctx , member : Optional [ discord . Member ] = None , account : int = 1 ) : member = member or ctx . author pages = list ( ) async with ctx . channel . typing ( ) : try : player_tag = self . tags . getTag ( member . id , account ) if player_tag is None : return await ctx . send ( "You need to first save your profile using ``{}save #tag``" . format ( ctx . prefix ) ) player_data = await self . clash . get_player ( player_tag ) leagues = await self . discord_helper . clanwar_readiness ( player_data . cards ) except AttributeError : return await ctx . send ( "Cannot connect to database. Please notify the devs." ) except clashroyale . NotFoundError : return await ctx . send ( "Player tag is invalid." ) except clashroyale . RequestError : return await ctx . send ( "Error: cannot reach Clash Royale Servers. Please try again later." ) emote_mapper = { "legendary" : self . discord_helper . emoji ( "legendleague" ) , "gold" : self . discord_helper . emoji ( "goldleague" ) , "silver" : self . discord_helper . emoji ( "silverleague" ) , "bronze" : self . discord_helper . emoji ( "bronzeleague" ) , } embed = discord . Embed ( color = 0xFAA61A , ) embed . set_author ( name = player_data . name + " (" + player_data . tag + ")" , icon_url = await self . constants . get_clan_image ( player_data ) , url = "https://royaleapi.com/player/" + player_data . tag . strip ( "#" ) , ) embed . set_footer ( text = credits , icon_url = credits_icon ) embed . add_field ( name = "War Day Wins" , value = "{} {}" . format ( self . discord_helper . emoji ( "warwin" ) , player_data . war_day_wins , ) , inline = True , ) embed . add_field ( name = "War Cards Collected" , value = "{} {}" . format ( self . discord_helper . emoji ( "card" ) , player_data . clan_cards_collected , ) , inline = True , ) highest_league = None for l in leagues . keys ( ) : highest_league = l if leagues [ l ] [ "percent" ] == 100 : break for league in leagues . keys ( ) : f_title = "{} {} League (Lvl {}) - {}%\n\u200b" . format ( emote_mapper [ league ] , leagues [ league ] [ "name" ] , leagues [ league ] [ "levels" ] , leagues [ league ] [ "percent" ] , ) value = [ ] if len ( leagues [ league ] [ "cards" ] ) > 20 : group = leagues [ league ] [ "cards" ] [ : 20 ] else : group = leagues [ league ] [ "cards" ] for card in group : if card is not None : emoji = await self . discord_helper . get_card_emoji ( card ) if emoji : value . append ( emoji ) else : value . append ( f" {card} " ) if len ( value ) : not_shown = len ( leagues [ league ] [ "cards" ] ) - len ( value ) value = " " . join ( value ) value += f"+{not_shown} more\n\n\n" if not_shown else "\n\n\n" embed . add_field ( name = f_title , value = value , inline = False , ) if league != highest_league : embed . add_field ( name = "\u200b" , value = "\u200b" , inline = False ) pages . append ( embed ) for league in leagues . keys ( ) : f_title = "{} {} League (Lvl {}) - {}%\n\u200b" . format ( emote_mapper [ league ] , leagues [ league ] [ "name" ] , leagues [ league ] [ "levels" ] , leagues [ league ] [ "percent" ] , ) embed = discord . Embed ( color = 0xFAA61A , title = "Clan War Readiness" , ) embed . set_author ( name = player_data . name + " (" + player_data . tag + ")" , icon_url = await self . constants . get_clan_image ( player_data ) , url = "https://royaleapi.com/player/" + player_data . tag . strip ( "#" ) , ) embed . set_footer ( text = credits , icon_url = credits_icon ) groups = list ( self . discord_helper . grouper ( leagues [ league ] [ "cards" ] , 15 ) ) for index , group in enumerate ( groups ) : value = [ ] for card in group : if card is not None : emoji = await self . discord_helper . get_card_emoji ( card ) if emoji : value . append ( emoji ) else : value . append ( f" {card} " ) if len ( value ) : value = " " . join ( value ) embed . add_field ( name = f_title if index == 0 else "\u200b" , value = value , inline = False , ) if groups : pages . append ( embed ) return await menu ( ctx , pages , DEFAULT_CONTROLS , timeout = 60 )
View yours or other's clash royale CWR
View yours or other ' s clash royale CWR
"""View yours or other's clash royale CWR""" # REMINDER: Order is important. RequestError is base exception class.
self
ctx
member
Optional[discord.Member]
account
int