mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[ADD] Add a router and a way for a user to delete styles.
I should work soon on the Lilypond part of things.
This commit is contained in:
parent
dff9dd2683
commit
5ed3e6743c
2 changed files with 44 additions and 0 deletions
16
router.py
Normal file
16
router.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from nio import RoomMessageText
|
||||||
|
import typing
|
||||||
|
|
||||||
|
routes = {}
|
||||||
|
helptxt = {}
|
||||||
|
|
||||||
|
def add_route(cmd: str, hlp: str, func: typing.Callable) -> None:
|
||||||
|
if cmd not in routes.keys():
|
||||||
|
routes[cmd] = func
|
||||||
|
helptxt[cmd] = hlp
|
||||||
|
|
||||||
|
async def handle_command(command: str, room: str, event: RoomMessageText, args: list):
|
||||||
|
import utils
|
||||||
|
if command in routes.keys():
|
||||||
|
await routes[command](utils.get_client(), room, event, args)
|
||||||
|
|
28
routes.py
Normal file
28
routes.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from nio import *
|
||||||
|
|
||||||
|
async def route_help(client: Client, room: str, event: RoomMessageText, args: list) -> None:
|
||||||
|
import router
|
||||||
|
import utils
|
||||||
|
|
||||||
|
txt = "Commands for TeXLily:\n"
|
||||||
|
|
||||||
|
for cmd in router.routes.keys():
|
||||||
|
txt += f"\ttxt!{cmd}: {router.helptxt[cmd]}\n"
|
||||||
|
|
||||||
|
await utils.send_msg(client, room, txt)
|
||||||
|
|
||||||
|
async def route_delete(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
|
Loading…
Add table
Reference in a new issue