From ec50e689b449ba7127d6f9ff7441e918a6456df8 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 23 Apr 2018 14:09:46 +0200 Subject: [PATCH] Add snipl and snipd commands --- stdplugins/snip.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stdplugins/snip.py b/stdplugins/snip.py index b131f04..d51d903 100644 --- a/stdplugins/snip.py +++ b/stdplugins/snip.py @@ -20,10 +20,11 @@ def remove_snip(name): os.remove(text) except Exception as e: print('failed to remove', snip, 'due to', e, file=sys.stderr) + del snips[name] @borg.on(events.NewMessage(pattern=r'.snip (\w+)')) -async def on_message(event): +async def on_snip(event): msg = await event.reply_message name = event.pattern_match.group(1) if msg: @@ -43,3 +44,15 @@ async def on_message(event): await borg.send_message(await event.input_chat, text) await event.delete() + + +@borg.on(events.NewMessage(pattern=r'.snipl')) +async def on_snip_list(event): + await event.respond('available snips: ' + ', '.join(snips.keys())) + await event.delete() + + +@borg.on(events.NewMessage(pattern=r'.snipd (\w+)')) +async def on_snip_delete(event): + remove_snip(event.pattern_match.group(1)) + await event.delete()