# Path: bot/utilities/tools.py
# def replace_vars(msg, args):
#     """Replace the variables in the message."""
#     oldmsg = msg
#     newmsg = msg
# 
#     for key in args:
#         newmsg = newmsg.replace(key, str(args[key]))
#         """Check if something was replaced, otherwise something went wrong."""
#         if newmsg is oldmsg:
#             print("ERROR: Could not replace variable in string!")
# 
#         oldmsg = newmsg
#     return newmsg


import time
from bot.utilities.permission import Permission
from bot.utilities.tools import replace_vars
    Takes off points if a non moderator wants to start a game.
    Also makes sure only one game is running at a time.
    """
    responses = bot.config.responses["startGame"]

    if bot.game_running:
        return False
    elif (
        user != bot.config.nickname and
        bot.get_permission(user) in [Permission.User, Permission.Subscriber]
        and msg == cmd
    ):
        """Check if pleb_gametimer is not on cooldown."""
        if (time.time() - bot.last_plebgame) > bot.config.pleb_gametimer:
            # The calling user is not a mod, so we subtract 5 points.
            if bot.ranking.get_points(user) > bot.config.config["points"]["game_start"]:
                bot.last_plebgame = time.time()  # Set pleb_gametimer
                bot.ranking.increment_points(
                    user, -int(bot.config.config["points"]["game_start"]), bot
                )
                bot.game_running = True
                return True
            else:
                var = {"<AMOUNT>": int(bot.config.config["points"]["game_start"])}
                bot.write(replace_vars(responses["points_needed"]["msg"], var))
                return False
        else:
            t = bot.config.pleb_gametimer - time.time() + bot.last_plebgame
            next_plebgame = "%8.0f" % t
            var = {"<COOLDOWN>": next_plebgame}

# Path: bot/utilities/tools.py
# def replace_vars(msg, args):
#     """Replace the variables in the message."""
#     oldmsg = msg
#     newmsg = msg
# 
#     for key in args:
#         newmsg = newmsg.replace(key, str(args[key]))
#         """Check if something was replaced, otherwise something went wrong."""
#         if newmsg is oldmsg:
#             print("ERROR: Could not replace variable in string!")
# 
#         oldmsg = newmsg
#     return newmsg


# Path: bot/utilities/startgame.py
import time
from bot.utilities.permission import Permission
from bot.utilities.tools import replace_vars

    Takes off points if a non moderator wants to start a game.
    Also makes sure only one game is running at a time.
    """
    responses = bot.config.responses["startGame"]

    if bot.game_running:
        return False
    elif (
        user != bot.config.nickname and
        bot.get_permission(user) in [Permission.User, Permission.Subscriber]
        and msg == cmd
    ):
        """Check if pleb_gametimer is not on cooldown."""
        if (time.time() - bot.last_plebgame) > bot.config.pleb_gametimer:
            # The calling user is not a mod, so we subtract 5 points.
            if bot.ranking.get_points(user) > bot.config.config["points"]["game_start"]:
                bot.last_plebgame = time.time()  # Set pleb_gametimer
                bot.ranking.increment_points(
                    user, -int(bot.config.config["points"]["game_start"]), bot
                )
                bot.game_running = True
                return True
            else:
                var = {"<AMOUNT>": int(bot.config.config["points"]["game_start"])}
                bot.write(replace_vars(responses["points_needed"]["msg"], var))
                return False
        else:
            t = bot.config.pleb_gametimer - time.time() + bot.last_plebgame
            next_plebgame = "%8.0f" % t
            var = {"<COOLDOWN>": next_plebgame}

            bot.write(replace_vars(responses["plebgames_on_cooldown"]["msg"], var))