Ejemplo n.º 1
0
    async def convert(self, ctx, argument):
        bot = ctx.bot
        match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument)
        guild = ctx.guild
        result = None
        if match is None:
            # not a mention...
            if guild:
                result = guild.get_member_named(argument)
                if not result:
                    result = guild.get_member_named(argument.lower())
            else:
                result = _get_from_guilds(bot, 'get_member_named', argument)
                if not result:
                    result = _get_from_guilds(bot, 'get_member_named', argument.lower())
        else:
            user_id = int(match.group(1))
            if guild:
                result = guild.get_member(user_id) or _utils_get(ctx.message.mentions, id=user_id)
            else:
                result = _get_from_guilds(bot, 'get_member', user_id)

        if not result:
            members = guild.members
            for m in members:
                if get_member_name(m) == get_member_name(argument):
                    return m
        if result is None:
            raise BadArgument('Member "{}" not found'.format(argument))

        return result
Ejemplo n.º 2
0
    async def generate_captains(self, team_a_channel, team_b_channel):
        """
        Generates two new captains and sets them as captains
            :ret discord.Embed: embed object to display 
        """
        if len(self.remaining) != 10:
            return discord.Embed(
                title="Valorant 10 Man Bot",
                description=
                "Please use the command !new and ensure you have 10 players in the channel before selecting captains"
            )
        potential = []
        check_prev = self.previous_time and (
            datetime.now() - self.previous_time
        ).seconds / SECS_TO_HOURS <= TIME_THRESOLD  #seconds to hours conversion
        for p in self.remaining:
            was_captain = p in self.previous_captains.values()
            was_in_previous = not check_prev or (check_prev and p
                                                 in self.previous_players)
            blacklisted = get_member_name(p) in self.blacklist
            if not was_captain and was_in_previous and not blacklisted:
                potential.append(p)

        caps = random.sample(potential, 2)  # 2 captains

        for i, team in enumerate(self.captains.keys()):
            await self.set_captain(caps[i], team)

        return discord.Embed(
            title="Valorant 10 Man Bot",
            description="The captains are @{} (1st pick) and @{} (2nd pick)".
            format(get_member_name(caps[0], lower=False),
                   get_member_name(caps[1], lower=False)))
Ejemplo n.º 3
0
async def setcaps(ctx, cap1: Player, cap2: Player):
    lobby_channel = next(
        (i for i in ctx.guild.voice_channels if i.name == options['lobby']),
        None)
    players = lobby_channel.members
    await bot.new_game(players)
    await bot.set_captain(cap1, "A")
    await bot.set_captain(cap2, "B")
    embed = discord.Embed(title="Valorant 10 Man Bot",
                          description="The captains are {} and {}".format(
                              get_member_name(cap1, lower=False),
                              get_member_name(cap2, lower=False)))
    await ctx.send(embed=embed)
Ejemplo n.º 4
0
 async def get_team_embed(self):
     """
     Generates an embed for the chosen teams
     """
     embed = discord.Embed(title="Valorant 10 Man Bot",
                           colour=discord.Colour(0x470386))
     team_a_strings = [
         get_member_name(m, lower=False) for m in self.teams["A"]
     ]
     team_b_strings = [
         get_member_name(m, lower=False) for m in self.teams["B"]
     ]
     embed.add_field(name="Defenders",
                     value="{}".format("\n".join(team_a_strings)),
                     inline=True)
     embed.add_field(name="Attackers",
                     value="{}".format("\n".join(team_b_strings)),
                     inline=True)
     return embed
Ejemplo n.º 5
0
 async def add_to_team(self, player: Player, team):
     """
     Adds player to team
         :param player: Discord.Member representing player member
         :param team: string representing team name
         :return discord.Embed: embed message to display
     """
     if player in self.remaining:
         self.teams[team].append(player)
         self.remaining.remove(player)
         return discord.Embed(
             title="Valorant 10 Man Bot",
             description="{} has been drafted to team {}".format(
                 get_member_name(player, lower=False),
                 ":a:" if team == "A" else ":b:"))
     else:
         return discord.Embed(
             title="Valorant 10 Man Bot",
             description="Sorry, {} is already drafted".format(
                 get_member_name(player)))
Ejemplo n.º 6
0
    async def draft_player(self, captain: Player, player: Player,
                           channel_dict):
        """
        Drafts a player according to 1-2-1-1-1-1-1-1-1 schema
            :param captain: discord.Member object representing captain
            :param player:  discord.Member object representing player
        """
        if player not in self.remaining:
            return discord.Embed(
                title="Valorant 10 Man Bot",
                description=
                "{} is not a valid player or they have been drafted already".
                format(player))
        elif captain not in self.captains.values():
            return discord.Embed(title="Valorant 10 Man Bot",
                                 description="{} is not a captain".format(
                                     get_member_name(captain)))

        team = "A" if captain == self.captains["A"] else "B"
        opp = "B" if team == "A" else "A"

        if len(self.teams[team]) == 0 and len(
                self.teams[opp]) == 0 and self.order[0] != captain:
            return discord.Embed(
                title="Valorant 10 Man bot",
                description="The other captain gets to draft first, sorry!")
        elif len(self.teams[team]) > len(self.teams[opp]) \
                or len(self.teams[team]) >= sum(self.drafting_dict[team][:self.turn]) + 1: # + 1 to include captain
            return discord.Embed(
                title="Valorant 10 Man bot",
                description=
                "You've already drafted this turn, please wait for the other captain"
            )

        embed = await self.add_to_team(player, team)
        if len(self.remaining) == 0:
            embed = await self.get_team_embed()
            self.previous_time = datetime.now()
        channel = channel_dict[team]
        await self.move_player(player, channel)

        if team == "B" and len(
                self.teams[team]) == sum(self.drafting_dict[team][:self.turn]
                                         ) + 1:  # + 1 to include captain
            self.turn += 1

        return embed
Ejemplo n.º 7
0
 async def new_game(self, players):
     """
     Clears instance variables in preperation for new game
         :param players: list of Discord.Member variables representing players
     """
     if len(players) != 10:
         return discord.Embed(
             title="Valorant 10 Man Bot",
             description="You cannot start a game with only {} players".
             format(len(players)))
     self.teams = {"A": [], "B": []}
     self.previous_captains = self.captains
     self.captains = {"A": None, "B": None}
     self.nick_to_player = {get_member_name(p): p for p in players}
     self.previous_players = self.remaining
     self.remaining = players.copy()
     self.turn = 1
     self.order = []
     self.map_dict = {k: True for k in self.map_dict.keys()}
     return discord.Embed(title="Valorant 10 Man Bot",
                          description="New game started".format(
                              len(players)))
Ejemplo n.º 8
0
 def __init__(self, command_prefix, drafting_scheme, maps, blacklist):
     """
     Constructor for Bot
         :param command_prefix: symbol to type before command. For ex, use "!" if you want to use "!<command>"
         :param drafting_scheme: list contains strings of format "<A/B><1-2>" where first char is team and 2nd char is # players
         :param maps: list of strings where each string corresponds to a map name
     """
     commands.Bot.__init__(self, command_prefix=command_prefix)
     self.teams = {"A": [], "B": []}
     self.remaining = []
     self.captains = {"A": None, "B": None}
     self.channels = {"A": None, "B": None}
     self.order = []
     self.blacklist = [get_member_name(f) for f in blacklist]
     self.previous_players = []
     self.previous_captains = {}
     self.previous_time = None
     self.drafting_dict = {
         "A": [int(s[1]) for s in drafting_scheme if s[0] == "A"],
         "B": [int(s[1]) for s in drafting_scheme if s[0] == "B"]
     }
     self.turn = -1
     self.map_dict = {k.lower(): True for k in maps}
     self.remove_command("help")  # we make a custom help command