def _try_find_target(irc, nick):
    """
    Tries to find the target UID for the given nick, raising LookupError if it doesn't exist or is ambiguous.
    """
    try:
        int_u = int(nick)
    except:
        int_u = None
    if int_u and int_u in irc.users:
        return int_u
    elif nick in irc.users:
        return nick
    potential_targets = irc.nick_to_uid(nick, multi=True)
    if not potential_targets:
        raise LookupError('No such target %r.' % nick)
    elif len(potential_targets) > 1:
        raise LookupError(
            'Multiple users with the nick %r found: please select the right UID: %s'
             % (nick, str(potential_targets)))
    else:
        return potential_targets[0]
