Add snipl and snipd commands

This commit is contained in:
Lonami Exo 2018-04-23 14:09:46 +02:00
parent 882fcfe471
commit ec50e689b4
1 changed files with 14 additions and 1 deletions

View File

@ -20,10 +20,11 @@ def remove_snip(name):
os.remove(text) os.remove(text)
except Exception as e: except Exception as e:
print('failed to remove', snip, 'due to', e, file=sys.stderr) print('failed to remove', snip, 'due to', e, file=sys.stderr)
del snips[name]
@borg.on(events.NewMessage(pattern=r'.snip (\w+)')) @borg.on(events.NewMessage(pattern=r'.snip (\w+)'))
async def on_message(event): async def on_snip(event):
msg = await event.reply_message msg = await event.reply_message
name = event.pattern_match.group(1) name = event.pattern_match.group(1)
if msg: if msg:
@ -43,3 +44,15 @@ async def on_message(event):
await borg.send_message(await event.input_chat, text) await borg.send_message(await event.input_chat, text)
await event.delete() 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()