# Path: bot/commands/abstract/command.py
# class Command(ABC):
#     """Represents a command, a way of reacting to chat messages."""
# 
#     perm = Permission.Admin
# 
#     def __init__(self, bot):
#         """Initialize the command."""
#         pass
# 
#     def match(self, bot, user, msg, tag_info):
#         """Return whether this command should be run."""
#         return False
# 
#     def run(self, bot, user, msg, tag_info):
#         """Run this command."""
#         pass
# 
#     def close(self, bot):
#         """Clean up."""
#         pass
# 
# Path: bot/utilities/startgame.py
# def start_game(bot, user, msg, cmd):
#     """Return whether a user can start a game.
# 
#     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))
#     else:  # The calling user is a mod, so we only check if the command is correct
#         if msg == cmd:
#             bot.game_running = True
#         return msg == cmd
# 
# 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 random
from bot.commands.abstract.command import Command
from bot.utilities.permission import Permission
from bot.utilities.startgame import start_game
from bot.utilities.tools import replace_vars
        Afterwards, check if a message contains the emote n times."""
        self.responses = bot.config.responses["KappaGame"]
        cmd = msg.strip()

        if not self.active:
            self.active = True
            self.n = random.randint(1, 25)
            self.answered = []
            print("Kappas: " + str(self.n))
            bot.write(self.responses["start_msg"]["msg"])
        else:
            if msg == "!kstop" and bot.get_permission(user) not in [
                Permission.User,
                Permission.Subscriber,
            ]:
                self.close(bot)
                bot.write(self.responses["stop_msg"]["msg"])
                return

            i = self.count_emotes(cmd, "Kappa")
            if i == self.n:
                var = {"<USER>": bot.twitch.display_name(user), "<AMOUNT>": self.n}
                bot.write(replace_vars(self.responses["winner_msg"]["msg"], var))
                bot.ranking.increment_points(user, self.kappa_game_points, bot)
                bot.game_running = False
                self.active = False
                self.answered = []
            elif i != -1:
                if i not in self.answered:
                    var = {"<AMOUNT>": i}

# Path: bot/commands/abstract/command.py
# class Command(ABC):
#     """Represents a command, a way of reacting to chat messages."""
# 
#     perm = Permission.Admin
# 
#     def __init__(self, bot):
#         """Initialize the command."""
#         pass
# 
#     def match(self, bot, user, msg, tag_info):
#         """Return whether this command should be run."""
#         return False
# 
#     def run(self, bot, user, msg, tag_info):
#         """Run this command."""
#         pass
# 
#     def close(self, bot):
#         """Clean up."""
#         pass
# 
# Path: bot/utilities/startgame.py
# def start_game(bot, user, msg, cmd):
#     """Return whether a user can start a game.
# 
#     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))
#     else:  # The calling user is a mod, so we only check if the command is correct
#         if msg == cmd:
#             bot.game_running = True
#         return msg == cmd
# 
# 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/commands/kappagame.py
import random
from bot.commands.abstract.command import Command
from bot.utilities.permission import Permission
from bot.utilities.startgame import start_game
from bot.utilities.tools import replace_vars

        Afterwards, check if a message contains the emote n times."""
        self.responses = bot.config.responses["KappaGame"]
        cmd = msg.strip()

        if not self.active:
            self.active = True
            self.n = random.randint(1, 25)
            self.answered = []
            print("Kappas: " + str(self.n))
            bot.write(self.responses["start_msg"]["msg"])
        else:
            if msg == "!kstop" and bot.get_permission(user) not in [
                Permission.User,
                Permission.Subscriber,
            ]:
                self.close(bot)
                bot.write(self.responses["stop_msg"]["msg"])
                return

            i = self.count_emotes(cmd, "Kappa")
            if i == self.n:
                var = {"<USER>": bot.twitch.display_name(user), "<AMOUNT>": self.n}
                bot.write(replace_vars(self.responses["winner_msg"]["msg"], var))
                bot.ranking.increment_points(user, self.kappa_game_points, bot)
                bot.game_running = False
                self.active = False
                self.answered = []
            elif i != -1:
                if i not in self.answered:
                    var = {"<AMOUNT>": i}

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