import re


def generate_ban_mask(ban_target: str) -> str:
    """
    Generates a user mask based on the parameters given in a MODE +b command.
    Any part of the user mask not provided by the user is added as a wildcard ("*").

    >>> generate_ban_mask("Foo")
    'Foo!*@*'
    >>> generate_ban_mask("Foo!Bar")
    'Foo!Bar@*'
    >>> generate_ban_mask("Foo!Bar@Baz")
    'Foo!Bar@Baz'
    >>> generate_ban_mask("Bar@Baz")
    '*!Bar@Baz'
    >>> generate_ban_mask("@Baz")
    '*!*@Baz'
    """
    if "!" in ban_target and "@" in ban_target:
        ban_mask_regex = r"([^!]*)!(.*)@(.*)"
        ban_match = re.fullmatch(ban_mask_regex, ban_target)
        if not ban_match:
            # @ before ! (corner case)
            ban_mask_regex = r"(.*)@(.*)!(.*)"
            ban_match = re.fullmatch(ban_mask_regex, ban_target)

        assert ban_match is not None  # Keeps mypy silent
        nick, user, host = ban_match.groups()

    elif "!" in ban_target:
        nick, user = ban_target.split("!", 1)
        host = "*"

    elif "@" in ban_target:
        user, host = ban_target.split("@", 1)
        nick = "*"

    else:
        nick = ban_target
        user = "*"
        host = "*"

    if not nick:
        nick = "*"
    if not user:
        user = "*"
    if not host:
        host = "*"

    return f"{nick}!{user}@{host}"