コード例 #1
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("👎")
コード例 #2
0
 async def force_remove(self, ctx, mention):
     """Remove the player from the current queue."""
     mode = get_channel_mode(ctx)
     player = await get_player_by_mention(ctx, mode, mention)
     game = get_game(ctx)
     queue = game.queues[mode]
     await ctx.send(embed=Embed(color=0x00FF00,
         description=queue.remove_player(player)))
コード例 #3
0
    async def queue(self, ctx):
        """Show the current queue.

        When using it on a channel in Modes category, the user will see the
        current queue with everyone's Elo.
        Can't be used outside Modes category.
        """
        game = get_game(ctx)
        mode = get_channel_mode(ctx)
        await ctx.send(
            embed=Embed(color=0x00FF00, description=str(game.queues[mode])))
コード例 #4
0
 def predicate(ctx):
     game = games[ctx.guild.id]
     mode = get_channel_mode(ctx)
     if mode not in game.available_modes:
         return False
     queue = game.queues[mode]
     if queue.mode < 2:
         raise commands.errors.BadArgument("This mode doesn't allow picks")
     if not queue.has_queue_been_full:
         raise commands.errors.BadArgument(
             "The pick session hasn't started")
     return True
コード例 #5
0
 async def leave_with(self, ctx):
     game = get_game(ctx)
     mode = get_channel_mode(ctx)
     queue = game.queues[mode]
     player = await get_player_by_id(ctx, mode, ctx.author.id)
     if player in queue.players:
         # The queue is full after the second team gets added so they can't leave anyway
         queue.players = queue.players[queue.max_queue // 2:]
         await ctx.send(embed=Embed(
             color=0x00FF00,
             description="Your team was removed from the queue."))
         return
     await send_error(ctx, "You are not in the queue.")
コード例 #6
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
コード例 #7
0
    async def leave(self, ctx):
        """Remove the player from the queue.

        As opposite to the !join, the leave will remove the player from the
        queue if he was in.
        Can't be used outside Modes category.
        The user needs to be in the queue for using this command.
        The user can't leave a queue after it went full."""
        game = get_game(ctx)
        mode = get_channel_mode(ctx)
        player = await get_player_by_id(ctx, mode, ctx.author.id)
        await ctx.send(
            embed=Embed(color=0x00FF00,
                        description=game.queues[mode].remove_player(player)))
コード例 #8
0
 async def clear_queue(self, ctx):
     """Clear the current queue."""
     game = get_game(ctx)
     mode = get_channel_mode(ctx)
     last_id = game.queues[mode].game_id
     if not game.queues[mode].has_queue_been_full:
         for player in game.queues[mode].players:
             if player in TIMEOUTS:
                 TIMEOUTS[player].cancel()
                 TIMEOUTS.pop(player, None)
         game.queues[mode] = Queue(
             2 * int(split_with_numbers(mode)[0]), game.queues[mode].mode,
             game.queues[mode].mapmode, last_id)
     await ctx.send(embed=Embed(color=0x00FF00,
                                description="The queue is now empty"))
コード例 #9
0
    async def pick(self, ctx, p1, p2=""):
        """Pick a player in the remaining player.

        Let's say Anddy is the red captain, and it's his turn to pick.
        Remaining players:
        1) @orp
        2) @grünersamt
        To pick orp, Anddy can either do:
        !p @orp
        or
        !p 1
        """
        game = get_game(ctx)
        mode = get_channel_mode(ctx)
        queue = game.queues[mode]
        team_id = await get_captain_team(ctx, queue, mode, ctx.author.id)
        await pick_players(ctx, queue, mode, team_id, p1, p2)
        await finish_the_pick(ctx, game, queue, mode, team_id)
コード例 #10
0
async def join_aux(ctx, player=None):
    game = get_game(ctx)
    mode = get_channel_mode(ctx)
    queue = game.queues[mode]
    if player is None:
        player = await get_player_by_id(ctx, mode, ctx.author.id)
        await check_if_submitted(ctx, game, mode, player)

    setattr(player, "last_join", datetime.now())
    is_queue_now_full = queue.has_queue_been_full
    res = await queue.add_player(ctx, player, game)
    is_queue_now_full = queue.has_queue_been_full != is_queue_now_full

    await ctx.send(content=queue.ping_everyone() if is_queue_now_full else "",
                   embed=Embed(color=0x00FF00, description=res))

    if queue.is_finished():
        await ctx.send(
            embed=Embed(color=0x00FF00,
                        description=game.add_game_to_be_played(queue, mode)))
        await set_map(ctx, game, queue, mode)
        await announce_game(ctx, res, queue, mode)
コード例 #11
0
 async def force_join(self, ctx, mention):
     """Force a user to join the queue."""
     mode = get_channel_mode(ctx)
     player = await get_player_by_mention(ctx, mode, mention)
     await join_aux(ctx, player)