From 24182f373956e95447362ec412a8794c64ecc61b Mon Sep 17 00:00:00 2001 From: LoaD Accumulator Date: Thu, 15 Jun 2023 08:10:36 +0200 Subject: [PATCH] [ADD] Add custom version for inline .ly expressions --- lilypond.py | 8 ++++++-- routes.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lilypond.py b/lilypond.py index 8d08bb4..dd7b7f3 100644 --- a/lilypond.py +++ b/lilypond.py @@ -1,4 +1,5 @@ template = r""" +{version] \header {{ tagline = "" }} @@ -6,13 +7,16 @@ template = r""" """ -def render(user: str, source: str, png: bool = True, template: bool = False) -> str: +def render(user: str, source: str, png: bool = True, version: str = None, template: bool = False) -> str: import tempfile import subprocess import utils import os + versionstr = "" + if version is not None: + versionstr = r'\version "{version}"'.format(version=version) - fmt = template.format(content=source) if template else source + fmt = template.format(content=source, version=versionstr) if template else source tmp = tempfile.NamedTemporaryFile(delete=False) tmp.write(bytes(fmt, encoding="utf8")) diff --git a/routes.py b/routes.py index 3c351ad..eeaf6b5 100644 --- a/routes.py +++ b/routes.py @@ -34,9 +34,13 @@ async def route_delete(router: Router, client: Client, room: str, event: RoomMes async def route_lshow(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None: import lilypond import utils - if len(args) == 1: + if len(args) >= 1: try: - file = lilypond.render("", args[0]) + version = None + if len(args) == 2: + version = args[1] + + file = lilypond.render("", args[0], version=version) await utils.send_png(room, file) except FileNotFoundError as e: content = {