forked from kate/uniborg
revert title if message is deleted before natural revert
This commit is contained in:
parent
785b215c90
commit
23b6f78cbd
|
@ -31,6 +31,16 @@ async def edit_title(title):
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
async def wait_for_delete(deleted_fut, timeout):
|
||||||
|
try:
|
||||||
|
await asyncio.wait_for(deleted_fut, timeout)
|
||||||
|
await edit_title(DEFAULT_TITLE)
|
||||||
|
return True
|
||||||
|
except (asyncio.TimeoutError, asyncio.CancelledError):
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@borg.on(events.NewMessage(
|
@borg.on(events.NewMessage(
|
||||||
pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=CHANNEL_ID))
|
pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=CHANNEL_ID))
|
||||||
async def on_name(event):
|
async def on_name(event):
|
||||||
|
@ -44,9 +54,13 @@ async def on_name(event):
|
||||||
|
|
||||||
with (await lock):
|
with (await lock):
|
||||||
await edit_title(new_title)
|
await edit_title(new_title)
|
||||||
await asyncio.sleep(MULTI_EDIT_TIMEOUT)
|
deleted_fut = asyncio.shield(borg.await_event(events.MessageDeleted(
|
||||||
await asyncio.sleep(REVERT_TIMEOUT)
|
chats=CHANNEL_ID,
|
||||||
if lock.locked():
|
func=lambda e: e.deleted_id == event.message.id
|
||||||
|
)))
|
||||||
|
if await wait_for_delete(deleted_fut, MULTI_EDIT_TIMEOUT):
|
||||||
|
return
|
||||||
|
if await wait_for_delete(deleted_fut, MULTI_EDIT_TIMEOUT) or lock.locked():
|
||||||
return
|
return
|
||||||
with (await lock):
|
with (await lock):
|
||||||
await edit_title(DEFAULT_TITLE)
|
await edit_title(DEFAULT_TITLE)
|
||||||
|
|
Loading…
Reference in New Issue