recruitment/cr.py
async def command_legend(
        self,
        ctx: commands.Context,
        member: Optional[discord.Member] = None,
        account: int = 1,
    ):
        """
        Show Legend clans.
        Can also show clans based on a member's stats
        """
        async with ctx.channel.typing():
            # Show all clans if member is None.
            player_trophies = 9999
            player_pb = 9999
            player_cwr = {
                "legendary": {"percent": 0},
                "gold": {"percent": 0},
                "silver": {"percent": 0},
                "bronze": {"percent": 0},
            }
            player_wd_wins = 0
            if member is not None:
                try:
                    player_tag = self.tags.getTag(member.id, account)
                    if player_tag is None:
                        await ctx.send(
                            "You must associate a tag with this member first using "
                            "``{}save #tag @member``".format(ctx.prefix)
                        )
                        return
                    player_data = await self.clash.get_player(player_tag)
                    player_trophies = player_data.trophies
                    player_cards = player_data.cards
                    player_pb = player_data.best_trophies
                    player_maxwins = player_data.challenge_max_wins
                    player_cwr = await self.discord_helper.clanwar_readiness(
                        player_cards
                    )
                    player_wd_wins = player_data.warDayWins

                    if player_data.clan is None:
                        player_clanname = "*None*"
                    else:
                        player_clanname = player_data.clan.name

                    ign = player_data.name
                # 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."
                    )

            embed = discord.Embed(color=0xFAA61A)
            embed.set_author(
                name="Legend Family Clans",
                url="http://royaleapi.com/clan/family/legend",
                icon_url="https://cdn.discordapp.com/attachments/423094817371848716/425389610223271956/legend_logo-trans.png",
            )
            embed.set_footer(text=credits, icon_url=credits_icon)

            found_clan = False
            total_members = 0
            total_waiting = 0
            clans = await self.config.clans()
            if clans is None or len(clans) == 0:
                return await ctx.send(
                    "Use `{}refresh` to get clan data.".format(ctx.prefix)
                )

            for clan in clans:
                cwr_fulfilled = True

                clan_name = clan["name"]
                clan_requirements = self.family_clans[clan_name].get(
                    "requirements", dict()
                )
                waiting = self.family_clans[clan_name].get("waiting", list())
                num_waiting = len(waiting)
                total_waiting += num_waiting

                req_pb = clan_requirements.get("personalbest", 0)
                req_cwr = clan_requirements.get(
                    "cwr", {"legendary": 0, "gold": 0, "silver": 0, "bronze": 0}
                )
                req_bonus_str = clan_requirements.get("bonus", "")
                req_wd_wins = clan_requirements.get("wdwins", 0)

                member_count = clan.get("members")
                total_members += member_count

                if num_waiting > 0:
                    title = f"[{str(num_waiting)} Waiting] "
                else:
                    title = ""
                if str(clan.get("type")) != "inviteOnly":
                    title += f"[{str(clan.get('type')).title()}] "
                title += f"{clan['name']} ({clan['tag']}) "
                if req_pb > 0:
                    title += f"PB: {str(req_pb)}+  "
                for league in req_cwr:
                    if req_cwr[league] > 0:
                        title += "{}: {}%  ".format(
                            league[:1].capitalize(), req_cwr[league]
                        )
                        if player_cwr[league]["percent"] < req_cwr[league]:
                            cwr_fulfilled = False
                if req_wd_wins > 0:
                    title += "{}+ War Day Wins ".format(req_wd_wins)
                if req_bonus_str is not None:
                    title += req_bonus_str

                emoji = self.family_clans[clan_name].get("emoji", "")
                if member_count < 50:
                    shown_members = str(member_count) + "/50"
                else:
                    shown_members = "**FULL**ΓÇé "

                desc = "{}ΓÇé{} ΓÇéΓÇé{} {}+ΓÇéΓÇé{} {}ΓÇéΓÇé{}{}".format(
                    self.discord_helper.emoji(emoji),
                    shown_members,
                    self.discord_helper.emoji("PB"),
                    clan["required_trophies"],
                    self.discord_helper.getLeagueEmoji(clan["clan_war_trophies"]),
                    clan["clan_war_trophies"],
                    self.discord_helper.emoji("crtrophy"),
                    clan["clan_score"],
                )

                if (
                    (member is None)
                    or (
                        (player_trophies >= clan["required_trophies"])
                        and (player_pb >= req_pb)
                        and (cwr_fulfilled)
                        and (player_trophies - clan["required_trophies"] < 1500)
                        and (clan["type"] != "closed")
                        and (player_wd_wins >= req_wd_wins)
                    )
                    or (
                        (clan["required_trophies"] < 4000)
                        and (member_count != 50)
                        and (2000 < player_trophies < 5500)
                        and (clan["type"] != "closed")
                        and (player_wd_wins >= req_wd_wins)
                        and (cwr_fulfilled)
                    )
                ):
                    found_clan = True
                    embed.add_field(name=title, value=desc, inline=False)

            if not found_clan:
                embed.add_field(
                    name="uh oh!",
                    value="There are no clans available for you at the moment, "
                    "please type !legend to see all clans.",
                    inline=False,
                )

            embed.description = (
                "Our Family is made up of {} "
                "clans with a total of {} "
                "members. We have {} spots left "
                "and {} members in waiting lists.".format(
                    len(clans),
                    total_members,
                    (len(clans) * 50) - total_members,
                    total_waiting,
                )
            )
            await ctx.send(embed=embed)

            if member is not None:
                show_playerinfo = await self.config.guild(
                    ctx.guild
                ).player_info_legend()
                if not show_playerinfo:
                    return await ctx.send(
                        embed=discord.Embed(
                            color=0xFAA61A,
                            description=":warning: **YOU WILL BE REJECTED IF YOU JOIN ANY CLAN WITHOUT APPROVAL**",
                        )
                    )
                return await ctx.send(
                    embed=discord.Embed(
                        color=0xFAA61A,
                        description=(
                            "Hello **{}**, above are all the clans "
                            "you are allowed to join, based on your statistics. "
                            "Which clan would you like to join? \n\n"
                            "**Name:** {} (#{})\n**Trophies:** {}/{}\n"
                            "**CW Readiness:** {}\n"
                            "**Max Challenge Wins:** {}\n"
                            "**Clan:** {}\n\n"
                            ":warning: **YOU WILL BE REJECTED "
                            "IF YOU JOIN ANY CLAN WITHOUT "
                            "APPROVAL**".format(
                                ign,
                                ign,
                                player_tag,
                                player_trophies,
                                player_pb,
                                await self.discord_helper.get_best_league(player_cards),
                                player_maxwins,
                                player_clanname,
                            )
                        ),
                    )
                )
                # )

        Show Legend clans.
        Can also show clans based on a member's stats
        
Show Legend clans.
Can also show clans based on a member's stats
Show Legend clans . Can also show clans based on a member ' s stats
async def command_legend(
        self,
        ctx: commands.Context,
        member: Optional[discord.Member] = None,
        account: int = 1,
    ):
        async with ctx.channel.typing():
            player_trophies = 9999
            player_pb = 9999
            player_cwr = {
                "legendary": {"percent": 0},
                "gold": {"percent": 0},
                "silver": {"percent": 0},
                "bronze": {"percent": 0},
            }
            player_wd_wins = 0
            if member is not None:
                try:
                    player_tag = self.tags.getTag(member.id, account)
                    if player_tag is None:
                        await ctx.send(
                            "You must associate a tag with this member first using "
                            "``{}save #tag @member``".format(ctx.prefix)
                        )
                        return
                    player_data = await self.clash.get_player(player_tag)
                    player_trophies = player_data.trophies
                    player_cards = player_data.cards
                    player_pb = player_data.best_trophies
                    player_maxwins = player_data.challenge_max_wins
                    player_cwr = await self.discord_helper.clanwar_readiness(
                        player_cards
                    )
                    player_wd_wins = player_data.warDayWins
                    if player_data.clan is None:
                        player_clanname = "*None*"
                    else:
                        player_clanname = player_data.clan.name
                    ign = player_data.name
                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."
                    )
            embed = discord.Embed(color=0xFAA61A)
            embed.set_author(
                name="Legend Family Clans",
                url="http://royaleapi.com/clan/family/legend",
                icon_url="https://cdn.discordapp.com/attachments/423094817371848716/425389610223271956/legend_logo-trans.png",
            )
            embed.set_footer(text=credits, icon_url=credits_icon)
            found_clan = False
            total_members = 0
            total_waiting = 0
            clans = await self.config.clans()
            if clans is None or len(clans) == 0:
                return await ctx.send(
                    "Use `{}refresh` to get clan data.".format(ctx.prefix)
                )
            for clan in clans:
                cwr_fulfilled = True
                clan_name = clan["name"]
                clan_requirements = self.family_clans[clan_name].get(
                    "requirements", dict()
                )
                waiting = self.family_clans[clan_name].get("waiting", list())
                num_waiting = len(waiting)
                total_waiting += num_waiting
                req_pb = clan_requirements.get("personalbest", 0)
                req_cwr = clan_requirements.get(
                    "cwr", {"legendary": 0, "gold": 0, "silver": 0, "bronze": 0}
                )
                req_bonus_str = clan_requirements.get("bonus", "")
                req_wd_wins = clan_requirements.get("wdwins", 0)
                member_count = clan.get("members")
                total_members += member_count
                if num_waiting > 0:
                    title = f"[{str(num_waiting)} Waiting] "
                else:
                    title = ""
                if str(clan.get("type")) != "inviteOnly":
                    title += f"[{str(clan.get('type')).title()}] "
                title += f"{clan['name']} ({clan['tag']}) "
                if req_pb > 0:
                    title += f"PB: {str(req_pb)}+  "
                for league in req_cwr:
                    if req_cwr[league] > 0:
                        title += "{}: {}%  ".format(
                            league[:1].capitalize(), req_cwr[league]
                        )
                        if player_cwr[league]["percent"] < req_cwr[league]:
                            cwr_fulfilled = False
                if req_wd_wins > 0:
                    title += "{}+ War Day Wins ".format(req_wd_wins)
                if req_bonus_str is not None:
                    title += req_bonus_str
                emoji = self.family_clans[clan_name].get("emoji", "")
                if member_count < 50:
                    shown_members = str(member_count) + "/50"
                else:
                    shown_members = "**FULL**ΓÇé "
                desc = "{}ΓÇé{} ΓÇéΓÇé{} {}+ΓÇéΓÇé{} {}ΓÇéΓÇé{}{}".format(
                    self.discord_helper.emoji(emoji),
                    shown_members,
                    self.discord_helper.emoji("PB"),
                    clan["required_trophies"],
                    self.discord_helper.getLeagueEmoji(clan["clan_war_trophies"]),
                    clan["clan_war_trophies"],
                    self.discord_helper.emoji("crtrophy"),
                    clan["clan_score"],
                )
                if (
                    (member is None)
                    or (
                        (player_trophies >= clan["required_trophies"])
                        and (player_pb >= req_pb)
                        and (cwr_fulfilled)
                        and (player_trophies - clan["required_trophies"] < 1500)
                        and (clan["type"] != "closed")
                        and (player_wd_wins >= req_wd_wins)
                    )
                    or (
                        (clan["required_trophies"] < 4000)
                        and (member_count != 50)
                        and (2000 < player_trophies < 5500)
                        and (clan["type"] != "closed")
                        and (player_wd_wins >= req_wd_wins)
                        and (cwr_fulfilled)
                    )
                ):
                    found_clan = True
                    embed.add_field(name=title, value=desc, inline=False)
            if not found_clan:
                embed.add_field(
                    name="uh oh!",
                    value="There are no clans available for you at the moment, "
                    "please type !legend to see all clans.",
                    inline=False,
                )
            embed.description = (
                "Our Family is made up of {} "
                "clans with a total of {} "
                "members. We have {} spots left "
                "and {} members in waiting lists.".format(
                    len(clans),
                    total_members,
                    (len(clans) * 50) - total_members,
                    total_waiting,
                )
            )
            await ctx.send(embed=embed)
            if member is not None:
                show_playerinfo = await self.config.guild(
                    ctx.guild
                ).player_info_legend()
                if not show_playerinfo:
                    return await ctx.send(
                        embed=discord.Embed(
                            color=0xFAA61A,
                            description=":warning: **YOU WILL BE REJECTED IF YOU JOIN ANY CLAN WITHOUT APPROVAL**",
                        )
                    )
                return await ctx.send(
                    embed=discord.Embed(
                        color=0xFAA61A,
                        description=(
                            "Hello **{}**, above are all the clans "
                            "you are allowed to join, based on your statistics. "
                            "Which clan would you like to join? \n\n"
                            "**Name:** {} (#{})\n**Trophies:** {}/{}\n"
                            "**CW Readiness:** {}\n"
                            "**Max Challenge Wins:** {}\n"
                            "**Clan:** {}\n\n"
                            ":warning: **YOU WILL BE REJECTED "
                            "IF YOU JOIN ANY CLAN WITHOUT "
                            "APPROVAL**".format(
                                ign,
                                ign,
                                player_tag,
                                player_trophies,
                                player_pb,
                                await self.discord_helper.get_best_league(player_cards),
                                player_maxwins,
                                player_clanname,
                            )
                        ),
                    )
                )
async def command_legend ( self , ctx : commands . Context , member : Optional [ discord . Member ] = None , account : int = 1 , ) : async with ctx . channel . typing ( ) : player_trophies = 9999 player_pb = 9999 player_cwr = { "legendary" : { "percent" : 0 } , "gold" : { "percent" : 0 } , "silver" : { "percent" : 0 } , "bronze" : { "percent" : 0 } , } player_wd_wins = 0 if member is not None : try : player_tag = self . tags . getTag ( member . id , account ) if player_tag is None : await ctx . send ( "You must associate a tag with this member first using " "``{}save #tag @member``" . format ( ctx . prefix ) ) return player_data = await self . clash . get_player ( player_tag ) player_trophies = player_data . trophies player_cards = player_data . cards player_pb = player_data . best_trophies player_maxwins = player_data . challenge_max_wins player_cwr = await self . discord_helper . clanwar_readiness ( player_cards ) player_wd_wins = player_data . warDayWins if player_data . clan is None : player_clanname = "*None*" else : player_clanname = player_data . clan . name ign = player_data . name 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." ) embed = discord . Embed ( color = 0xFAA61A ) embed . set_author ( name = "Legend Family Clans" , url = "http://royaleapi.com/clan/family/legend" , icon_url = "https://cdn.discordapp.com/attachments/423094817371848716/425389610223271956/legend_logo-trans.png" , ) embed . set_footer ( text = credits , icon_url = credits_icon ) found_clan = False total_members = 0 total_waiting = 0 clans = await self . config . clans ( ) if clans is None or len ( clans ) == 0 : return await ctx . send ( "Use `{}refresh` to get clan data." . format ( ctx . prefix ) ) for clan in clans : cwr_fulfilled = True clan_name = clan [ "name" ] clan_requirements = self . family_clans [ clan_name ] . get ( "requirements" , dict ( ) ) waiting = self . family_clans [ clan_name ] . get ( "waiting" , list ( ) ) num_waiting = len ( waiting ) total_waiting += num_waiting req_pb = clan_requirements . get ( "personalbest" , 0 ) req_cwr = clan_requirements . get ( "cwr" , { "legendary" : 0 , "gold" : 0 , "silver" : 0 , "bronze" : 0 } ) req_bonus_str = clan_requirements . get ( "bonus" , "" ) req_wd_wins = clan_requirements . get ( "wdwins" , 0 ) member_count = clan . get ( "members" ) total_members += member_count if num_waiting > 0 : title = f"[{str(num_waiting)} Waiting] " else : title = "" if str ( clan . get ( "type" ) ) != "inviteOnly" : title += f"[{str(clan.get('type')).title()}] " title += f"{clan['name']} ({clan['tag']}) " if req_pb > 0 : title += f"PB: {str(req_pb)}+  " for league in req_cwr : if req_cwr [ league ] > 0 : title += "{}: {}%  " . format ( league [ : 1 ] . capitalize ( ) , req_cwr [ league ] ) if player_cwr [ league ] [ "percent" ] < req_cwr [ league ] : cwr_fulfilled = False if req_wd_wins > 0 : title += "{}+ War Day Wins " . format ( req_wd_wins ) if req_bonus_str is not None : title += req_bonus_str emoji = self . family_clans [ clan_name ] . get ( "emoji" , "" ) if member_count < 50 : shown_members = str ( member_count ) + "/50" else : shown_members = "**FULL**ΓÇé " desc = "{}ΓÇé{} ΓÇéΓÇé{} {}+ΓÇéΓÇé{} {}ΓÇéΓÇé{}{}".format( self . discord_helper . emoji ( emoji ) , shown_members , self . discord_helper . emoji ( "PB" ) , clan [ "required_trophies" ] , self . discord_helper . getLeagueEmoji ( clan [ "clan_war_trophies" ] ) , clan [ "clan_war_trophies" ] , self . discord_helper . emoji ( "crtrophy" ) , clan [ "clan_score" ] , ) if ( ( member is None ) or ( ( player_trophies >= clan [ "required_trophies" ] ) and ( player_pb >= req_pb ) and ( cwr_fulfilled ) and ( player_trophies - clan [ "required_trophies" ] < 1500 ) and ( clan [ "type" ] != "closed" ) and ( player_wd_wins >= req_wd_wins ) ) or ( ( clan [ "required_trophies" ] < 4000 ) and ( member_count != 50 ) and ( 2000 < player_trophies < 5500 ) and ( clan [ "type" ] != "closed" ) and ( player_wd_wins >= req_wd_wins ) and ( cwr_fulfilled ) ) ) : found_clan = True embed . add_field ( name = title , value = desc , inline = False ) if not found_clan : embed . add_field ( name = "uh oh!" , value = "There are no clans available for you at the moment, " "please type !legend to see all clans." , inline = False , ) embed . description = ( "Our Family is made up of {} " "clans with a total of {} " "members. We have {} spots left " "and {} members in waiting lists." . format ( len ( clans ) , total_members , ( len ( clans ) * 50 ) - total_members , total_waiting , ) ) await ctx . send ( embed = embed ) if member is not None : show_playerinfo = await self . config . guild ( ctx . guild ) . player_info_legend ( ) if not show_playerinfo : return await ctx . send ( embed = discord . Embed ( color = 0xFAA61A , description = ":warning: **YOU WILL BE REJECTED IF YOU JOIN ANY CLAN WITHOUT APPROVAL**" , ) ) return await ctx . send ( embed = discord . Embed ( color = 0xFAA61A , description = ( "Hello **{}**, above are all the clans " "you are allowed to join, based on your statistics. " "Which clan would you like to join? \n\n" "**Name:** {} (#{})\n**Trophies:** {}/{}\n" "**CW Readiness:** {}\n" "**Max Challenge Wins:** {}\n" "**Clan:** {}\n\n" ":warning: **YOU WILL BE REJECTED " "IF YOU JOIN ANY CLAN WITHOUT " "APPROVAL**" . format ( ign , ign , player_tag , player_trophies , player_pb , await self . discord_helper . get_best_league ( player_cards ) , player_maxwins , player_clanname , ) ) , ) )
Show Legend clans.
Show Legend clans .
"""
        Show Legend clans.
        Can also show clans based on a member's stats
        """ # Show all clans if member is None. # REMINDER: Order is important. RequestError is base exception class. # )
self
ctx
commands.Context
member
Optional[discord.Member]
account
int