def trim_long_text(text, max_lines):
    """
    Trim a potentially long multi-line message at the given number of lines.
    :param text: the input text
    :param max_lines: maximum number of lines
    :return: the trimmed message
    """
    max_lines = max(max_lines, 3)
    lines = text.splitlines()
    if len(lines) <= max_lines:
        return text
    lines_to_keep_at_each_end = int((max_lines - 1) / 2)
    num_lines_skipped = len(lines) - lines_to_keep_at_each_end * 2
    if num_lines_skipped <= 0:
        return text
    return '\n'.join(lines[:lines_to_keep_at_each_end] + [
        '({} lines skipped)'.format(num_lines_skipped)] + lines[-
        lines_to_keep_at_each_end:])
