await instead of creating task for deletion

This commit is contained in:
udf 2019-01-17 11:33:13 +02:00
parent 1756ebad66
commit 787660b16f
Signed by: kate
GPG Key ID: F17AECB58C3A3096
1 changed files with 5 additions and 8 deletions

View File

@ -1,12 +1,9 @@
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import asyncio
from telethon import events, utils from telethon import events, utils
from telethon.tl import types from telethon.tl import types
loop = asyncio.get_event_loop()
TYPE_TEXT = 0 TYPE_TEXT = 0
TYPE_PHOTO = 1 TYPE_PHOTO = 1
TYPE_DOCUMENT = 2 TYPE_DOCUMENT = 2
@ -18,7 +15,7 @@ snips = storage.snips or {}
@borg.on(events.NewMessage(pattern=r'\.snip (\S+)', outgoing=True)) @borg.on(events.NewMessage(pattern=r'\.snip (\S+)', outgoing=True))
async def on_snip(event): async def on_snip(event):
loop.create_task(event.delete()) await event.delete()
name = event.pattern_match.group(1) name = event.pattern_match.group(1)
if name not in snips: if name not in snips:
return return
@ -38,7 +35,7 @@ async def on_snip(event):
@borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True)) @borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True))
async def on_snip_save(event): async def on_snip_save(event):
loop.create_task(event.delete()) await event.delete()
name = event.pattern_match.group(1) name = event.pattern_match.group(1)
msg = await event.get_reply_message() msg = await event.get_reply_message()
if not msg: if not msg:
@ -64,20 +61,20 @@ async def on_snip_save(event):
@borg.on(events.NewMessage(pattern=r'\.snipl', outgoing=True)) @borg.on(events.NewMessage(pattern=r'\.snipl', outgoing=True))
async def on_snip_list(event): async def on_snip_list(event):
loop.create_task(event.delete()) await event.delete()
await event.respond('available snips: ' + ', '.join(snips.keys())) await event.respond('available snips: ' + ', '.join(snips.keys()))
@borg.on(events.NewMessage(pattern=r'\.snipd (\S+)', outgoing=True)) @borg.on(events.NewMessage(pattern=r'\.snipd (\S+)', outgoing=True))
async def on_snip_delete(event): async def on_snip_delete(event):
loop.create_task(event.delete()) await event.delete()
snips.pop(event.pattern_match.group(1), None) snips.pop(event.pattern_match.group(1), None)
storage.snips = snips storage.snips = snips
@borg.on(events.NewMessage(pattern=r'\.snipr (\S+)\s+(\S+)', outgoing=True)) @borg.on(events.NewMessage(pattern=r'\.snipr (\S+)\s+(\S+)', outgoing=True))
async def on_snip_rename(event): async def on_snip_rename(event):
loop.create_task(event.delete()) await event.delete()
snip = snips.pop(event.pattern_match.group(1), None) snip = snips.pop(event.pattern_match.group(1), None)
if snip: if snip:
snips[event.pattern_match.group(2)] = snip snips[event.pattern_match.group(2)] = snip