async function convertCurlyBracketString(
    str,
    memberID,
    memberName,
    serverName,
    members
): Promise<string> {
    const memberCount = (await members.fetch()).size;
    const bots = (await members.fetch()).filter((m) => m.user.bot).size;
    str = str
        .replace(
            "{member:mention}",
            memberID ? `<@${memberID}>` : "{member:mention}"
        )
        .replace(
            "{member:name}",
            memberName ? `${memberName}` : "{member:name}"
        )
        .replace("{serverName}", serverName ? `${serverName}` : "{serverName}")
        .replace(
            "{memberCount}",
            memberCount ? `${memberCount}` : "{memberCount}"
        )
        .replace("{memberCount:bots}", bots ? `${bots}` : "{memberCount:bots}")
        .replace(
            "{memberCount:humans}",
            memberCount && bots
                ? `${memberCount - bots}`
                : "{memberCount:humans}"
        );

    return str;
}

export default convertCurlyBracketString;
