Exemplo n.º 1
0
    async def cancel(self, ctx: commands.Context, member: discord.Member):
        """
        Cancels the user’s ongoing game

        Only works if the game has not been scored yet
        """
        with session_scope() as session:
            game, participant = get_last_game(player_id=member.id,
                                              server_id=ctx.guild.id,
                                              session=session)

            if game and game.winner:
                await ctx.send(
                    "The game has already been scored and cannot be canceled anymore"
                )
                return

            session.delete(game)

        await ctx.send(
            f"{member.display_name}’s ongoing game was cancelled and deleted from the database"
        )
        await queue_channel_handler.update_queue_channels(
            bot=self.bot, server_id=ctx.guild.id)
        await remove_voice_channels(ctx, game)
Exemplo n.º 2
0
    async def won(
        self, ctx: commands.Context,
    ):
        with session_scope() as session:
            # Get the latest game
            game, participant = get_last_game(
                player_id=ctx.author.id, server_id=ctx.guild.id, session=session
            )

            if not game:
                await ctx.send("You have not played a game on this server yet")
                return

            elif game and game.winner:
                await ctx.send(
                    "Your last game seem to have already been scored\n"
                    "If there was an issue, please contact an admin"
                )
                return

            elif game.id in self.games_getting_scored_ids:
                await ctx.send("There is already a scoring or cancellation message active for this game")
                return

            else:
                self.games_getting_scored_ids.add(game.id)

            win_validation_message = await ctx.send(
                f"{game.players_ping}"
                f"{ctx.author.display_name} wants to score game {game.id} as a win for {participant.side}\n"
                f"Result will be validated once 6 players from the game press ✅"
            )

            validated, players_who_refused = await checkmark_validation(
                bot=self.bot,
                message=win_validation_message,
                validating_players_ids=game.player_ids_list,
                validation_threshold=6,
            )

            # Whatever happens, we’re not scoring it anymore if we get here
            self.games_getting_scored_ids.remove(game.id)

            if not validated:
                await ctx.send("Score input was either cancelled or timed out")
                return

            # If we get there, the score was validated and we can simply update the game and the ratings
            queue_channel_handler.mark_queue_related_message(
                await ctx.send(
                    f"Game {game.id} has been scored as a win for {participant.side} and ratings have been updated"
                )
            )
            categoria = discord.utils.get(ctx.guild.categories, name="âš” Game-%s" % str(game.id))
            for channel in categoria.channels:
                await channel.delete()
            await categoria.delete()

        matchmaking_logic.score_game_from_winning_player(player_id=ctx.author.id, server_id=ctx.guild.id)
        await ranking_channel_handler.update_ranking_channels(self.bot, ctx.guild.id)
Exemplo n.º 3
0
    async def champion(self,
                       ctx: commands.Context,
                       champion_name: ChampionNameConverter(),
                       game_id: int = None):
        with session_scope() as session:
            if not game_id:
                game, participant = get_last_game(player_id=ctx.author.id,
                                                  server_id=ctx.guild.id,
                                                  session=session)
            else:
                game, participant = (session.query(
                    Game, GameParticipant).select_from(Game).join(
                        GameParticipant).filter(Game.id == game_id).filter(
                            GameParticipant.player_id == ctx.author.id)
                                     ).one_or_none()

            # We write down the champion
            participant.champion_id = champion_name

            game_id = game.id

        await ctx.send(
            f"Champion for game {game_id} was set to "
            f"{lol_id_tools.get_name(champion_name, object_type='champion')} for {ctx.author.display_name}"
        )
Exemplo n.º 4
0
def add_player(player_id: int, role: str, channel_id: int, server_id: int = None, name: str = None):
    # Just in case
    assert role in roles_list

    with session_scope() as session:

        game, participant = get_last_game(player_id, server_id, session)

        if game and not game.winner:
            raise PlayerInGame

        # Then check if the player is in a ready-check
        if is_in_ready_check(player_id, session):
            raise PlayerInReadyCheck

        # This is where we add new Players to the server
        #   This is also useful to automatically update name changes
        session.merge(Player(id=player_id, server_id=server_id, name=name))

        # Finally, we actually add the player to the queue
        queue_player = QueuePlayer(
            channel_id=channel_id,
            player_id=player_id,
            player_server_id=server_id,
            role=role,
            queue_time=datetime.now(),
        )

        # We merge for simplicity (allows players to re-queue for the same role)
        session.merge(queue_player)
Exemplo n.º 5
0
    async def cancel(
        self,
        ctx: commands.Context,
    ):
        """
        Cancels your ongoing game

        Will require validation from at least 6 players in the game

        Example:
            !cancel
        """
        with session_scope() as session:
            # Get the latest game
            game, participant = get_last_game(player_id=ctx.author.id,
                                              server_id=ctx.guild.id,
                                              session=session)

            if game and game.winner:
                await ctx.send(
                    "It does not look like you are part of an ongoing game")
                return

            elif game.id in self.games_getting_scored_ids:
                await ctx.send(
                    "There is already a scoring or cancellation message active for this game"
                )
                return

            else:
                self.games_getting_scored_ids.add(game.id)

            cancel_validation_message = await ctx.send(
                f"{game.players_ping}"
                f"{ctx.author.display_name} wants to cancel game {game.id}\n"
                f"Game will be canceled once 6 players from the game press ✅")

            validated, players_who_refused = await checkmark_validation(
                bot=self.bot,
                message=cancel_validation_message,
                validating_players_ids=game.player_ids_list,
                validation_threshold=6,
            )

            self.games_getting_scored_ids.remove(game.id)

            if not validated:
                await ctx.send(f"Game {game.id} was not cancelled")

            else:

                for participant in game.participants.values():
                    self.players_whose_last_game_got_cancelled[
                        participant.player_id] = datetime.now()

                session.delete(game)

                queue_channel_handler.mark_queue_related_message(
                    await ctx.send(f"Game {game.id} was cancelled"))
Exemplo n.º 6
0
def score_game_from_winning_player(player_id: int, server_id: int):
    """
    Scores the last game of the player on the server as a *win*
    """
    with session_scope() as session:
        game, participant = get_last_game(player_id, server_id, session)

        game.winner = participant.side

        update_trueskill(game, session)
Exemplo n.º 7
0
    async def cancel(self, ctx: commands.Context):
        """
        Scores your last game as a win for (mostly made to be used after !test game)
        """
        with session_scope() as session:
            game, participant = get_last_game(
                player_id=ctx.author.id, server_id=ctx.guild.id, session=session
            )

            session.delete(game)

        await ctx.send(f"{ctx.author.display_name}’s last game was cancelled and deleted from the database")
        await queue_channel_handler.update_queue_channels(bot=self.bot, server_id=ctx.guild.id)
Exemplo n.º 8
0
    async def won(
        self,
        ctx: commands.Context,
    ):
        """
        Scores your last game as a win

        Will require validation from at least 6 players in the game

        Example:
            !won
        """
        # TODO MED PRIO ONLY ONE ONGOING CANCEL/SCORING MESSAGE PER GAME
        with session_scope() as session:
            # Get the latest game
            game, participant = get_last_game(player_id=ctx.author.id,
                                              server_id=ctx.guild.id,
                                              session=session)

            if game and game.winner:
                await ctx.send(
                    "Your last game seem to have already been scored\n"
                    "If there was an issue, please contact an admin")
                return

            win_validation_message = await ctx.send(
                f"{ctx.author.display_name} wants to score game {game.id} as a win for {participant.side}\n"
                f"{', '.join([f'<@{discord_id}>' for discord_id in game.player_ids_list])} can validate the result\n"
                f"Result will be validated once 6 players from the game press ✅"
            )

            validated, players_who_refused = await checkmark_validation(
                bot=self.bot,
                message=win_validation_message,
                validating_players_ids=game.player_ids_list,
                validation_threshold=6,
                timeout=60,
            )

            if not validated:
                await ctx.send("Score input was either cancelled or timed out")
                return

            # If we get there, the score was validated and we can simply update the game and the ratings
            queue_channel_handler.mark_queue_related_message(await ctx.send(
                f"Game {game.id} has been scored as a win for {participant.side} and ratings have been updated"
            ))

        matchmaking_logic.score_game_from_winning_player(
            player_id=ctx.author.id, server_id=ctx.guild.id)
Exemplo n.º 9
0
    async def cancel(
        self,
        ctx: commands.Context,
    ):
        """
        Cancels your ongoing game

        Will require validation from at least 6 players in the game

        Example:
            !cancel
        """
        # TODO MED PRIO ONLY ONE ONGOING CANCEL/SCORING MESSAGE PER GAME

        with session_scope() as session:
            # Get the latest game
            game, participant = get_last_game(player_id=ctx.author.id,
                                              server_id=ctx.guild.id,
                                              session=session)

            if game and game.winner:
                await ctx.send(
                    "It does not look like you are part of an ongoing game")
                return

            cancel_validation_message = await ctx.send(
                f"{ctx.author.display_name} wants to cancel game {game.id}\n"
                f"{', '.join([f'<@{discord_id}>' for discord_id in game.player_ids_list])} can cancel the game\n"
                f"Game will be canceled once 6 players from the game press ✅"
            )

            validated, players_who_refused = await checkmark_validation(
                bot=self.bot,
                message=cancel_validation_message,
                validating_players_ids=game.player_ids_list,
                validation_threshold=6,
                timeout=60,
            )

            if not validated:
                await ctx.send(f"Game {game.id} was not cancelled")
            else:
                session.delete(game)
                queue_channel_handler.mark_queue_related_message(
                    await ctx.send(f"Game {game.id} was cancelled"))
Exemplo n.º 10
0
    async def champion(
        self, ctx: commands.Context, champion_name: ChampionNameConverter(), game_id: int = None
    ):
        """
        Saves the champion you used in your last game

        Older games can be filled with !champion champion_name game_id
        You can find the ID of the games you played with !history

        Example:
            !champion riven
            !champion riven 1
        """

        with session_scope() as session:
            if not game_id:
                game, participant = get_last_game(
                    player_id=ctx.author.id, server_id=ctx.guild.id, session=session
                )
            else:
                game, participant = (
                    session.query(Game, GameParticipant)
                    .select_from(Game)
                    .join(GameParticipant)
                    .filter(Game.id == game_id)
                    .filter(GameParticipant.player_id == ctx.author.id)
                ).one_or_none()

            # We write down the champion
            participant.champion_id = champion_name

            game_id = game.id

        await ctx.send(
            f"Champion for game {game_id} was set to "
            f"{lol_id_tools.get_name(champion_name, object_type='champion')} for {ctx.author.display_name}"
        )