Add snip rename method

This commit is contained in:
Lonami Exo 2018-04-23 16:14:08 +02:00
parent 32acefa991
commit bdb402e645
1 changed files with 13 additions and 3 deletions

View File

@ -17,7 +17,7 @@ TYPE_DOCUMENT = 2
snips = storage.snips or {} snips = storage.snips or {}
@borg.on(events.NewMessage(pattern=r'.snip (.+)')) @borg.on(events.NewMessage(pattern=r'.snip (\S+)'))
async def on_snip(event): async def on_snip(event):
name = event.pattern_match.group(1) name = event.pattern_match.group(1)
if name in snips: if name in snips:
@ -36,7 +36,7 @@ async def on_snip(event):
await event.delete() await event.delete()
@borg.on(events.NewMessage(pattern=r'.snips (.+)')) @borg.on(events.NewMessage(pattern=r'.snips (\S+)'))
async def on_snip_save(event): async def on_snip_save(event):
name = event.pattern_match.group(1) name = event.pattern_match.group(1)
msg = await event.reply_message msg = await event.reply_message
@ -67,7 +67,17 @@ async def on_snip_list(event):
await event.delete() await event.delete()
@borg.on(events.NewMessage(pattern=r'.snipd (.+)')) @borg.on(events.NewMessage(pattern=r'.snipd (\S+)'))
async def on_snip_delete(event): async def on_snip_delete(event):
snips.pop(event.pattern_match.group(1), None) snips.pop(event.pattern_match.group(1), None)
await event.delete() await event.delete()
@borg.on(events.NewMessage(pattern=r'.snipr (\S+)\s+(\S+)'))
async def on_snip_rename(event):
snip = snips.pop(event.pattern_match.group(1), None)
if snip:
snips[event.pattern_match.group(2)] = snip
storage.snips = snips
await event.delete()