def commit_profiles(profiles: dict) -> None:
    """Commits the given profiles in the database.

    Parameters
    ----------
    profiles : dict
        profiles of all players
    """
    with OpenJson(PLAYERS_DATA_PATH + "profiles.json") as profiles_file:
        profiles_file.dump(profiles, indent=4)
def get_profiles() -> dict:
    """Returns the profiles of all players.

    Returns
    -------
    dict
        profiles of the players
    """
    with OpenJson(PLAYERS_DATA_PATH + "profiles.json") as profiles_file:
        profiles = profiles_file.load()
        return profiles
def get_custom() -> dict:
    """Returns the custom effects.

    Returns
    -------
    dict
        custom effects
    """
    if CacheData.custom == {}:
        with OpenJson(PLAYERS_DATA_PATH + "custom.json") as custom_file:
            custom = custom_file.load()
        return custom
    return CacheData.custom
def commit_roles(data: dict) -> None:
    """Commits the roles in database.

    Parameters
    ----------
    data : dict
        data to be commited
    """
    if not data:
        return

    with OpenJson(PLAYERS_DATA_PATH + "roles.json") as roles_file:
        roles_file.format(data)
def get_roles() -> dict:
    """Returns the roles.

    Returns
    -------
    dict
        roles
    """
    if CacheData.roles == {}:
        with OpenJson(PLAYERS_DATA_PATH + "roles.json") as roles_file:
            roles = roles_file.load()
            CacheData.roles = roles
        return roles
    return CacheData.roles
def get_info(account_id: str) -> dict | None:
    """Returns the information about player.

    Parameters
    ----------
    account_id : str
        account_id of the client

    Returns
    -------
    dict | None
        information of client
    """
    with OpenJson(PLAYERS_DATA_PATH + "profiles.json") as profiles_file:
        profiles = profiles_file.load()
        if account_id in profiles:
            return profiles[account_id]
    return None
def add_profile(
    account_id: str,
    display_string: str,
    current_name: str,
    account_age: int,
) -> None:
    """Adds the profile in database.

    Parameters
    ----------
    account_id : str
        account id of the client
    display_string : str
        display string of the client
    current_name : str
        name of the client
    account_age : int
        account_age of the account
    """
    with OpenJson(PLAYERS_DATA_PATH + "profiles.json") as profiles_file:
        profiles = profiles_file.load()
        profiles[account_id] = {
            "display_string": display_string,
            "profiles": [],
            "name": current_name,
            "isBan": False,
            "isMuted": False,
            "accountAge": account_age,
            "registerOn": time.time(),
            "canStartKickVote": True,
            "spamCount": 0,
            "lastSpam": time.time(),
            "totaltimeplayer": 0,
            "lastseen": 0,
        }
    commit_profiles(profiles)

    serverdata.clients[account_id] = profiles[account_id]
    serverdata.clients[account_id]["warnCount"] = 0
    serverdata.clients[account_id]["lastWarned"] = time.time()
    serverdata.clients[account_id]["verified"] = False
    serverdata.clients[account_id]["rejoincount"] = 1
    serverdata.clients[account_id]["lastJoin"] = time.time()
def update_profile(
    account_id: str,
    display_string: str = None,
    allprofiles: list[str] = None,
    name: str = None,
) -> None:
    """Updates the profile of client.

    Parameters
    ----------
    account_id : str
        account id of the client
    display_string : str, optional
        display string of the account, by default None
    allprofiles : list[str], optional
        all profiles of the client, by default None
    name : str, optional
        name to be updated, by default None
    """
    with OpenJson(PLAYERS_DATA_PATH + "profiles.json") as profiles_file:
        profiles = profiles_file.load()

        if profiles is None:
            return

        if account_id in profiles and display_string is not None:
            if display_string not in profiles[account_id]["display_string"]:
                profiles[account_id]["display_string"].append(display_string)

        if allprofiles is not None:
            for profile in allprofiles:
                if profile not in profiles[account_id]["profiles"]:
                    profiles[account_id]["profiles"].append(profile)

        if name is not None:
            profiles[account_id]["name"] = name

        commit_profiles(profiles)
def load_white_list() -> None:
    """Loads the whitelist."""
    with OpenJson(PLAYERS_DATA_PATH + "whitelist.json") as whitelist_file:
        data = whitelist_file.load()
        for account_id in data:
            CacheData.whitelist.append(account_id)
def commit_c():
    """Commits the custom data into the custom.json."""
    with OpenJson(PLAYERS_DATA_PATH + "custom.json") as custom_file:
        custom_file.dump(CacheData.custom, indent=4)