# 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/error_classes/error_classes.py
# class UserNotFoundError(ValueError):
#     """Raised when a username is not found."""
# 
#     def __init__(self, username):
#         self.username = username
# 
# Path: bot/utilities/tools.py
# def sanitize_user_name(username):
#     """Format user name.
# 
#     Remove the @ if a string starts with it.
#     """
#     if username.startswith("@"):
#         username = username[1:]  # remove "@"
#     return username.lower()
# 
# 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


from bot.commands.abstract.command import Command
from bot.error_classes import UserNotFoundError
from bot.utilities.permission import Permission
from bot.utilities.tools import sanitize_user_name, replace_vars
    perm = Permission.User

    def __init__(self, _):
        """Initialize variables."""
        self.responses = {}

    def match(self, bot, user, msg, tag_info):
        """Match if message is !rank or starts with !rank and has one argument."""
        if msg.lower() == "!rank":
            return True
        elif msg.startswith("!rank ") and len(msg.split(" ")) == 2:
            return True
        else:
            return False

    def run(self, bot, user, msg, tag_info):
        """Calculate rank of user.

        0-19: Rank 25, 20-39: Rank 24,..., 480-499: Rank 1
        >= LEGENDP: Legend
        """

        self.responses = bot.config.responses["Rank"]

        split_msg = msg.split(" ")
        if len(split_msg) == 2:
            # !rank <name>
            user = sanitize_user_name(split_msg[1])
        else:
            # !rank

# 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/error_classes/error_classes.py
# class UserNotFoundError(ValueError):
#     """Raised when a username is not found."""
# 
#     def __init__(self, username):
#         self.username = username
# 
# Path: bot/utilities/tools.py
# def sanitize_user_name(username):
#     """Format user name.
# 
#     Remove the @ if a string starts with it.
#     """
#     if username.startswith("@"):
#         username = username[1:]  # remove "@"
#     return username.lower()
# 
# 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/rank.py
from bot.commands.abstract.command import Command
from bot.error_classes import UserNotFoundError
from bot.utilities.permission import Permission
from bot.utilities.tools import sanitize_user_name, replace_vars

    perm = Permission.User

    def __init__(self, _):
        """Initialize variables."""
        self.responses = {}

    def match(self, bot, user, msg, tag_info):
        """Match if message is !rank or starts with !rank and has one argument."""
        if msg.lower() == "!rank":
            return True
        elif msg.startswith("!rank ") and len(msg.split(" ")) == 2:
            return True
        else:
            return False

    def run(self, bot, user, msg, tag_info):
        """Calculate rank of user.

        0-19: Rank 25, 20-39: Rank 24,..., 480-499: Rank 1
        >= LEGENDP: Legend
        """

        self.responses = bot.config.responses["Rank"]

        split_msg = msg.split(" ")
        if len(split_msg) == 2:
            # !rank <name>
            user = sanitize_user_name(split_msg[1])
        else:
            # !rank

            user = sanitize_user_name(user)