recruitment/cr.py
async def waiting_add(
        self, ctx: commands.Context, member: discord.Member, clan_name, account: int = 1
    ):
        """Add people to the waiting list for a clan"""
        async with ctx.channel.typing():
            clan_name = clan_name.lower()

            valid_keys = [k["nickname"].lower() for k in self.family_clans.values()]
            if clan_name not in valid_keys:
                return await simple_embed(
                    ctx,
                    "Please use a valid clanname:\n{}".format(
                        humanize_list(list(valid_keys))
                    ),
                    False,
                )
            # Get requirements for clan to approve
            clan_info = None
            for name, data in self.family_clans.items():
                if data.get("nickname").lower() == clan_name:
                    clan_info = data

            clan_name = clan_info.get("name")
            clan_tag = clan_info.get("tag")
            clan_role = clan_info.get("clanrole")
            clan_pb = clan_info["requirements"].get("personalbest")
            clan_cwr = clan_info["requirements"].get("cwr")
            clan_private = clan_info["requirements"].get("private")
            clan_waiting = clan_info["waiting"]
            clan_wd_wins = clan_info["requirements"].get("wdwins")

            try:
                player_tag = self.tags.getTag(member.id, account)
                if player_tag is None:
                    return await simple_embed(
                        ctx,
                        "You must associate a tag with this member first using ``{}save #tag @member``".format(
                            ctx.prefix
                        ),
                        False,
                    )
                player_data = await self.clash.get_player(player_tag)
                # Clan data for clan to approve
                wait_clan_data = await self.clash.get_clan(clan_tag)

                player_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 simple_embed(
                    ctx,
                    "Error: cannot reach Clash Royale Servers. Please try again later.",
                )

            player_ign = player_data.name
            player_trophies = player_data.trophies
            player_cards = player_data.cards
            player_pb = player_data.best_trophies
            player_cwr = await self.discord_helper.clanwar_readiness(player_cards)
            player_wd_wins = player_data.warDayWins

            if (
                player_trophies < wait_clan_data.required_trophies
                or player_pb < clan_pb
            ):
                return await simple_embed(
                    ctx,
                    "Cannot add you to the waiting list, you don't meet the trophy requirements.",
                )

            player_cwr_good = True
            for league in clan_cwr:
                if clan_cwr[league] > 0:
                    if player_cwr[league]["percent"] < clan_cwr[league]:
                        player_cwr_good = False

            if not player_cwr_good:
                return await simple_embed(
                    ctx,
                    "Cannot add you to the waiting lists, you don't meet the CW Readiness requirements.",
                )

            if player_wd_wins < clan_wd_wins:
                return await simple_embed(
                    ctx,
                    "Approval failed, you don't meet requirements for war day wins.",
                    False,
                )

            if not await self.add_to_waiting(clan_name, member):
                return await ctx.send(
                    "You are already in a waiting list for this clan."
                )

            waiting_role = discord.utils.get(ctx.guild.roles, name="Waiting")
            if not waiting_role:
                await simple_embed(ctx, "Cannot find a role named waiting.")
            try:
                if waiting_role:
                    await member.add_roles(waiting_role, reason="added to waiting list")
            except discord.Forbidden:
                raise
            except discord.HTTPException:
                raise
            await ctx.send(
                (
                    f"{member.mention} You have been added to the waiting list for **"
                    f"{clan_name}"
                    "**. We will mention you when a spot is available."
                ),
                allowed_mentions=discord.AllowedMentions(users=True),
            )

            role = discord.utils.get(ctx.guild.roles, name=clan_role)
            to_post = self.bot.get_channel(
                await self.config.guild(ctx.guild).new_recruits_channel_id()
            )
            if to_post:
                await to_post.send(
                    "**{} (#{})** added to the waiting list for {}".format(
                        player_ign, player_tag, role.mention
                    ),
                    allowed_mentions=discord.AllowedMentions(
                        roles=(await self.config.guild(ctx.guild).mentions())[
                            "on_waitlist_add"
                        ]
                    ),
                )
        await ctx.tick()
Add people to the waiting list for a clan
Add people to the waiting list for a clan
Add people to the waiting list for a clan
async def waiting_add(
        self, ctx: commands.Context, member: discord.Member, clan_name, account: int = 1
    ):
        async with ctx.channel.typing():
            clan_name = clan_name.lower()
            valid_keys = [k["nickname"].lower() for k in self.family_clans.values()]
            if clan_name not in valid_keys:
                return await simple_embed(
                    ctx,
                    "Please use a valid clanname:\n{}".format(
                        humanize_list(list(valid_keys))
                    ),
                    False,
                )
            clan_info = None
            for name, data in self.family_clans.items():
                if data.get("nickname").lower() == clan_name:
                    clan_info = data
            clan_name = clan_info.get("name")
            clan_tag = clan_info.get("tag")
            clan_role = clan_info.get("clanrole")
            clan_pb = clan_info["requirements"].get("personalbest")
            clan_cwr = clan_info["requirements"].get("cwr")
            clan_private = clan_info["requirements"].get("private")
            clan_waiting = clan_info["waiting"]
            clan_wd_wins = clan_info["requirements"].get("wdwins")
            try:
                player_tag = self.tags.getTag(member.id, account)
                if player_tag is None:
                    return await simple_embed(
                        ctx,
                        "You must associate a tag with this member first using ``{}save #tag @member``".format(
                            ctx.prefix
                        ),
                        False,
                    )
                player_data = await self.clash.get_player(player_tag)
                wait_clan_data = await self.clash.get_clan(clan_tag)
                player_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 simple_embed(
                    ctx,
                    "Error: cannot reach Clash Royale Servers. Please try again later.",
                )
            player_ign = player_data.name
            player_trophies = player_data.trophies
            player_cards = player_data.cards
            player_pb = player_data.best_trophies
            player_cwr = await self.discord_helper.clanwar_readiness(player_cards)
            player_wd_wins = player_data.warDayWins
            if (
                player_trophies < wait_clan_data.required_trophies
                or player_pb < clan_pb
            ):
                return await simple_embed(
                    ctx,
                    "Cannot add you to the waiting list, you don't meet the trophy requirements.",
                )
            player_cwr_good = True
            for league in clan_cwr:
                if clan_cwr[league] > 0:
                    if player_cwr[league]["percent"] < clan_cwr[league]:
                        player_cwr_good = False
            if not player_cwr_good:
                return await simple_embed(
                    ctx,
                    "Cannot add you to the waiting lists, you don't meet the CW Readiness requirements.",
                )
            if player_wd_wins < clan_wd_wins:
                return await simple_embed(
                    ctx,
                    "Approval failed, you don't meet requirements for war day wins.",
                    False,
                )
            if not await self.add_to_waiting(clan_name, member):
                return await ctx.send(
                    "You are already in a waiting list for this clan."
                )
            waiting_role = discord.utils.get(ctx.guild.roles, name="Waiting")
            if not waiting_role:
                await simple_embed(ctx, "Cannot find a role named waiting.")
            try:
                if waiting_role:
                    await member.add_roles(waiting_role, reason="added to waiting list")
            except discord.Forbidden:
                raise
            except discord.HTTPException:
                raise
            await ctx.send(
                (
                    f"{member.mention} You have been added to the waiting list for **"
                    f"{clan_name}"
                    "**. We will mention you when a spot is available."
                ),
                allowed_mentions=discord.AllowedMentions(users=True),
            )
            role = discord.utils.get(ctx.guild.roles, name=clan_role)
            to_post = self.bot.get_channel(
                await self.config.guild(ctx.guild).new_recruits_channel_id()
            )
            if to_post:
                await to_post.send(
                    "**{} (#{})** added to the waiting list for {}".format(
                        player_ign, player_tag, role.mention
                    ),
                    allowed_mentions=discord.AllowedMentions(
                        roles=(await self.config.guild(ctx.guild).mentions())[
                            "on_waitlist_add"
                        ]
                    ),
                )
        await ctx.tick()
async def waiting_add ( self , ctx : commands . Context , member : discord . Member , clan_name , account : int = 1 ) : async with ctx . channel . typing ( ) : clan_name = clan_name . lower ( ) valid_keys = [ k [ "nickname" ] . lower ( ) for k in self . family_clans . values ( ) ] if clan_name not in valid_keys : return await simple_embed ( ctx , "Please use a valid clanname:\n{}" . format ( humanize_list ( list ( valid_keys ) ) ) , False , ) clan_info = None for name , data in self . family_clans . items ( ) : if data . get ( "nickname" ) . lower ( ) == clan_name : clan_info = data clan_name = clan_info . get ( "name" ) clan_tag = clan_info . get ( "tag" ) clan_role = clan_info . get ( "clanrole" ) clan_pb = clan_info [ "requirements" ] . get ( "personalbest" ) clan_cwr = clan_info [ "requirements" ] . get ( "cwr" ) clan_private = clan_info [ "requirements" ] . get ( "private" ) clan_waiting = clan_info [ "waiting" ] clan_wd_wins = clan_info [ "requirements" ] . get ( "wdwins" ) try : player_tag = self . tags . getTag ( member . id , account ) if player_tag is None : return await simple_embed ( ctx , "You must associate a tag with this member first using ``{}save #tag @member``" . format ( ctx . prefix ) , False , ) player_data = await self . clash . get_player ( player_tag ) wait_clan_data = await self . clash . get_clan ( clan_tag ) player_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 simple_embed ( ctx , "Error: cannot reach Clash Royale Servers. Please try again later." , ) player_ign = player_data . name player_trophies = player_data . trophies player_cards = player_data . cards player_pb = player_data . best_trophies player_cwr = await self . discord_helper . clanwar_readiness ( player_cards ) player_wd_wins = player_data . warDayWins if ( player_trophies < wait_clan_data . required_trophies or player_pb < clan_pb ) : return await simple_embed ( ctx , "Cannot add you to the waiting list, you don't meet the trophy requirements." , ) player_cwr_good = True for league in clan_cwr : if clan_cwr [ league ] > 0 : if player_cwr [ league ] [ "percent" ] < clan_cwr [ league ] : player_cwr_good = False if not player_cwr_good : return await simple_embed ( ctx , "Cannot add you to the waiting lists, you don't meet the CW Readiness requirements." , ) if player_wd_wins < clan_wd_wins : return await simple_embed ( ctx , "Approval failed, you don't meet requirements for war day wins." , False , ) if not await self . add_to_waiting ( clan_name , member ) : return await ctx . send ( "You are already in a waiting list for this clan." ) waiting_role = discord . utils . get ( ctx . guild . roles , name = "Waiting" ) if not waiting_role : await simple_embed ( ctx , "Cannot find a role named waiting." ) try : if waiting_role : await member . add_roles ( waiting_role , reason = "added to waiting list" ) except discord . Forbidden : raise except discord . HTTPException : raise await ctx . send ( ( f"{member.mention} You have been added to the waiting list for **" f"{clan_name}" "**. We will mention you when a spot is available." ) , allowed_mentions = discord . AllowedMentions ( users = True ) , ) role = discord . utils . get ( ctx . guild . roles , name = clan_role ) to_post = self . bot . get_channel ( await self . config . guild ( ctx . guild ) . new_recruits_channel_id ( ) ) if to_post : await to_post . send ( "**{} (#{})** added to the waiting list for {}" . format ( player_ign , player_tag , role . mention ) , allowed_mentions = discord . AllowedMentions ( roles = ( await self . config . guild ( ctx . guild ) . mentions ( ) ) [ "on_waitlist_add" ] ) , ) await ctx . tick ( )
Add people to the waiting list for a clan
Add people to the waiting list for a clan
"""Add people to the waiting list for a clan""" # Get requirements for clan to approve # Clan data for clan to approve # REMINDER: Order is important. RequestError is base exception class.
self
ctx
commands.Context
member
discord.Member
clan_name
account
int