TexLiLy/routes.py
2023-06-14 19:36:13 +02:00

47 lines
1.5 KiB
Python

from router import Router
from nio import *
async def route_help(r: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
import router
import utils
txt = "Commands for TeXLily:\n"
print(r)
for cmd in r.routes:
txt += f" {r.name}!{cmd}: {r.helptxt[cmd]}\n"
await utils.send_msg(client, room, txt)
async def route_delete(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
if len(args) == 1:
import utils
import os
directory = utils.create_user_dir(event.sender)
file = os.path.join(directory, args[0] + ".sty")
try:
os.remove(file)
await utils.send_msg(client, room, "Deleted!")
except FileNotFoundError:
await utils.send_msg(client, room, f"Couldn't delete style {args[0]}")
pass
async def route_lshow(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
import lilypond
import utils
if len(args) == 1:
try:
file = lilypond.render("", args[0])
await utils.send_png(room, file)
except FileNotFoundError as e:
content = {
"msgtype": "m.text",
"body": f"Couldn't parse LilyPond correctly.\n```{e.args[0]}\n```",
"formatted_body": f"Couldn't parse LilyPond correctly.<br><code><pre>{e.args[0]}</pre></code>",
}
await client.room_send(room, message_type="m.room.message", content=content)