Пример #1
0
 async def add_to_bench_command(self, ctx, user: discord.Member):
     user_name = UserUtils.get_nick_or_name_emojiless(user)
     log.info("Adding %s to bench...", user_name)
     bench = self.client.global_variables.bench
     bench.append(user)
     await ctx.send(ctx.author.mention + " User `" + user_name +
                    "` has been added to the bench")
     await ctx.send(
         embed=UserUtils.generate_player_list_embed(bench, "Bench"))
Пример #2
0
 async def remove_from_bench_command(self, ctx, user: discord.Member):
     user_name = UserUtils.get_nick_or_name_emojiless(user)
     log.info("Removing %s from bench...", user.name)
     bench = self.client.global_variables.bench
     if user in bench:
         bench.remove(user)
         await ctx.send(ctx.author.mention + " User `" + user_name +
                        "` has been removed from the bench")
     else:
         await ctx.send(ctx.author.mention + " User `" + user_name +
                        "` is not in the bench")
     await ctx.send(
         embed=UserUtils.generate_player_list_embed(bench, "Bench"))
Пример #3
0
    async def generate_teams_command(self, ctx):
        self.client.global_variables.teams = list()
        self.client.global_variables.spectators = list()
        teams = self.client.global_variables.teams
        teams.append(list())
        teams.append(list())

        bench = self.client.global_variables.bench

        log.info("Generating teams...")
        voice_channel = self.client.get_channel(
            Config.COMMUNITY_GAMES_VOICE_CHANNEL_ID)
        members = voice_channel.members

        # members = TestUtils.generate_players_list(14)
        # spectators = TestUtils.generate_players_list(3, UserUtils.IDLE)
        # members.extend(spectators)

        self.client.global_variables.spectators = UserUtils.filter_spectators(
            members)
        spectators = self.client.global_variables.spectators
        log.info("Spectator players:%s", UserUtils.print_players(spectators))

        log.debug("Removing spectators: %s from player pool: %s",
                  UserUtils.print_players(spectators),
                  UserUtils.print_players(members))
        UserUtils.remove_players_from_list(spectators, members)
        log.debug("Player pool after removing spectators: %s",
                  UserUtils.print_players(members))

        log.debug("Removing spectators: %s from player bench: %s",
                  UserUtils.print_players(spectators),
                  UserUtils.print_players(bench))
        UserUtils.remove_players_from_list(spectators, bench)
        log.debug("Bench pool after removing spectators: %s",
                  UserUtils.print_players(bench))

        num_of_players = len(members)

        await ctx.send(embed=(
            UserUtils.generate_player_list_embed(members, voice_channel.name)))
        if spectators:
            await ctx.send(embed=UserUtils.generate_player_list_embed(
                spectators, "Spectators"))

        log.info("Current number of players: " + str(num_of_players))

        if num_of_players < 12:
            error_msg = self.get_not_enough_players_msg(num_of_players)
            log.error(error_msg)
            await ctx.send(ctx.author.mention + error_msg)
            return

        UserUtils.remove_players_from_list(bench, members)
        log.info("Adding previously benched players to teams:%s",
                 UserUtils.print_players(bench))
        self.generate_teams(bench)
        log.info("Adding players from players pool to teams:%s",
                 UserUtils.print_players(members))
        self.generate_teams(members)

        log.info("Adding unselected players to bench:%s",
                 UserUtils.print_players(members))
        bench.extend(members)
        bench = ListUtils.remove_duplicates(bench)
        members.clear()

        team0 = teams[0]
        team1 = teams[1]

        log.info("Teams generated are: "
                 "\n Team 1: %s "
                 "\n Team 2: %s", UserUtils.print_players(team0),
                 UserUtils.print_players(team1))

        await ctx.send(embed=self.generate_team_embed_message(1, team0))
        await ctx.send(embed=self.generate_team_embed_message(2, team1))
        await ctx.send(
            embed=UserUtils.generate_player_list_embed(bench, "Bench"))