[ADD] Add custom version for inline .ly expressions

This commit is contained in:
LoaD Accumulator 2023-06-15 08:10:36 +02:00
parent 4d4aa7d5ab
commit 24182f3739
No known key found for this signature in database
GPG key ID: 6898757653ABE3E6
2 changed files with 12 additions and 4 deletions

View file

@ -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"))

View file

@ -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 = {