2018-04-08 12:43:23 +00:00
|
|
|
# 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
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from telethon import events
|
2018-11-21 21:24:33 +00:00
|
|
|
from telethon.tl.types import InputPeerSelf
|
2018-04-08 12:43:23 +00:00
|
|
|
import telethon.utils
|
|
|
|
|
|
|
|
from uniborg import util
|
|
|
|
|
2018-04-08 14:53:21 +00:00
|
|
|
|
2018-04-08 12:43:23 +00:00
|
|
|
async def await_read(chat, message):
|
2018-11-21 21:24:33 +00:00
|
|
|
if isinstance(chat, InputPeerSelf):
|
|
|
|
return
|
2018-04-08 12:43:23 +00:00
|
|
|
chat = telethon.utils.get_peer_id(chat)
|
2018-04-08 14:44:09 +00:00
|
|
|
|
2018-04-08 12:43:23 +00:00
|
|
|
async def read_filter(read_event):
|
2018-06-22 08:46:39 +00:00
|
|
|
return (read_event.chat_id == chat
|
2018-04-08 14:44:09 +00:00
|
|
|
and read_event.is_read(message))
|
2018-04-08 12:43:23 +00:00
|
|
|
fut = borg.await_event(events.MessageRead(inbox=False), read_filter)
|
|
|
|
|
|
|
|
if await util.is_read(borg, chat, message):
|
|
|
|
fut.cancel()
|
|
|
|
return
|
|
|
|
|
|
|
|
await fut
|
|
|
|
|
2018-04-08 14:44:09 +00:00
|
|
|
|
2018-04-08 14:53:21 +00:00
|
|
|
@borg.on(util.admin_cmd(r"^\.(del)(?:ete)?$"))
|
2018-04-08 15:07:05 +00:00
|
|
|
@borg.on(util.admin_cmd(r"^\.(edit)(?:\s+(.*))?$"))
|
2018-04-08 12:43:23 +00:00
|
|
|
async def delete(event):
|
|
|
|
await event.delete()
|
2018-04-08 14:53:21 +00:00
|
|
|
command = event.pattern_match.group(1)
|
|
|
|
if command == 'edit':
|
2018-04-08 17:07:12 +00:00
|
|
|
text = event.pattern_match.group(2)
|
2018-04-08 14:53:21 +00:00
|
|
|
if not text:
|
|
|
|
return
|
2018-11-24 15:19:23 +00:00
|
|
|
target = await util.get_target_message(borg, event)
|
2018-04-08 12:43:23 +00:00
|
|
|
if target:
|
2018-06-22 08:46:39 +00:00
|
|
|
chat = await event.get_input_chat()
|
2018-04-08 12:43:23 +00:00
|
|
|
await await_read(chat, target)
|
|
|
|
await asyncio.sleep(.5)
|
2018-04-08 14:53:21 +00:00
|
|
|
if command == 'edit':
|
|
|
|
await borg.edit_message(chat, target, text)
|
|
|
|
else:
|
|
|
|
await borg.delete_messages(chat, target)
|