Exemplo n.º 1
0
async def pick_players(ctx, queue, mode, team_id, p1, p2):
    nb_p = nb_players_to_pick(queue, team_id)
    if nb_p == 2 and not p2 or nb_p == 1 and p2:
        await send_error(ctx, f"You need to pick **{nb_p}** players.")
        raise PassException()

    lst = [await get_picked_player(ctx, mode, queue, p1)]
    if nb_p > 1:
        lst.append(await get_picked_player(ctx, mode, queue, p2))
        if lst[0] == lst[1]:
            await send_error(ctx, f"You picked twice <@{lst[0].id_user}>.")
            raise PassException()
    for i in range(nb_p):
        await queue.set_player_team(ctx, team_id, lst[i])
Exemplo n.º 2
0
    async def join_with(self, ctx, *mentions):
        """Join the queue with your own team.

        Example in 4vs4:
        !jw @player1 @player2 @player3
        """
        game = get_game(ctx)
        mode = get_channel_mode(ctx)
        queue = game.queues[mode]
        nb_players = int(split_with_numbers(mode)[0])
        players = {await get_player_by_id(ctx, mode, ctx.author.id)} |\
            {await get_player_by_mention(ctx, mode, m) for m in mentions}
        if nb_players != len(players):
            await send_error(
                ctx,
                f"You joined with {len(players)} player(s) but you need exactly {nb_players}"
            )
            raise PassException()

        embed = Embed(title=f"Invitations for {mode} from {ctx.author.display_name}",
            description="To join with your team, everyone involved have to confirm by clicking on 👍.\n"
                "To deny, click on the 👎.")\
            .add_field(name=f"Captain", value=ctx.author.mention)

        for i in range(len(mentions)):
            embed.add_field(name=f"Player n°{i + 1}", value=mentions[i])

        msg = await ctx.send(embed=embed)
        await msg.add_reaction("👍")
        await msg.add_reaction("👎")
Exemplo n.º 3
0
 async def set_player_team(self, ctx, team_id, player):
     """Move the player from the players to the team."""
     team = self.red_team if team_id == 1 else self.blue_team
     try:
         team.append(self.players.pop(self.players.index(player)))
     except Exception as e:
         await send_error(ctx, f"Couldn't find <@{player.id_user}> here.")
         raise PassException()
Exemplo n.º 4
0
 async def get_captain_team(self, ctx, player):
     """Return 1 if red, 2 if blue, 0 if none."""
     red_cap, blue_cap = self.red_team[0], self.blue_team[0]
     for i, p in enumerate([red_cap, blue_cap], start=1):
         if p == player:
             return i
     await send_error(ctx, "You are not captain.")
     raise PassException()
Exemplo n.º 5
0
 async def setstat(self, ctx, mode, mention, stat_name, value):
     player = await get_player_by_mention(ctx, mode, mention)
     if not value.isdigit():
         await send_error(ctx, "Value must be an integer")
         raise PassException()
     if stat_name in Player.STATS[1: -2]:
         old = getattr(player, stat_name)
         setattr(player, stat_name, int(value))
         await ctx.send(embed=Embed(color=0x00FF00,
             description=f"The stat {stat_name} was changed from {old} to {value}"))
     else:
         await send_error(ctx, "You can not modify this stat.")
Exemplo n.º 6
0
async def check_if_submitted(ctx, game, mode, player):
    start = datetime.now()
    queue = game.get_last_undecided_game_by(player, mode)
    if queue is None or not hasattr(queue, "reacted")\
        or not queue.reacted or player.id_user in queue.reacted:
        return True

    await send_error(
        ctx,
        f"You must react to the game n°{queue.game_id} before joining a new queue."
    )
    raise PassException()
Exemplo n.º 7
0
    async def add_player(self, ctx, player, game):
        """Add a player in the queue."""
        if player in self.players:
            await send_error(
                ctx, "You can't join twice, maybe you're looking for !l.")
            return
        if self.is_full() or self.has_queue_been_full:
            await send_error(ctx, "Queue is full...")
            raise PassException()
        self.players.append(player)
        TIMEOUTS[player] = asyncio.ensure_future(
            self.timeout_player(player, ctx))
        res = f'<@{player.id_user}> has been added to the queue. '\
            f'**[{len(self.players)}/{int(self.max_queue)}]**'
        if self.is_full():
            res += "\nQueue is full, let's start the next session.\n"
            res += self.on_queue_full(game, get_channel_mode(ctx), TIMEOUTS)
            if self.mode >= 2:
                CAPTAINS[self] = {1: Captain(120), 2: Captain(100)}
                await CAPTAINS[self][1].start(ctx, game, get_channel_mode(ctx),
                                              self.game_id, self.red_team[0])

        return res
Exemplo n.º 8
0
 async def add_players(self, ctx, players, game, mode):
     """Add multiple players in the queue."""
     success = True
     len_at_start = len(self.players)
     for player in players:
         if player in self.players or self.is_full(
         ) or self.has_queue_been_full:
             success = False
             break
         self.players.append(player)
     if not success:
         len_at_end = len(self.players)
         for _ in range(len_at_end - len_at_start):
             self.players.pop()
         await send_error(ctx,
                          "One or more of your players cannot be added,\n")
         raise PassException()
     await ctx.send(embed=Embed(color=0x00FF00, description=\
         f"Your team: {team_to_player_id(players)} was correctly added."))
     res = ""
     if self.is_full():
         res += "\nQueue is full, let's start the next session.\n"
         res += self.on_queue_full(game, mode)
     return res