2018-11-24 21:22:44 +00:00
|
|
|
"""
|
|
|
|
Reply to a message with .e to make a draft of it (with '\n.e' appended)
|
|
|
|
Reply to your own message with <text>.e to edit the message to <text>
|
|
|
|
if <text> is ".", the message is edited to empty/deleted
|
|
|
|
"""
|
2018-11-24 21:14:04 +00:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from telethon.errors import MessageEmptyError
|
|
|
|
from telethon.tl.functions.messages import SaveDraftRequest
|
|
|
|
from telethon.tl.functions.messages import EditMessageRequest
|
|
|
|
|
|
|
|
from stdplugins.kbass_core import self_reply_cmd
|
|
|
|
|
|
|
|
|
|
|
|
@self_reply_cmd(borg, r"^\.e$")
|
|
|
|
async def on_edit_start(event, target):
|
|
|
|
await borg(SaveDraftRequest(
|
|
|
|
peer=await event.get_input_chat(),
|
|
|
|
message=(target.message or '.') + '\n.e',
|
|
|
|
entities=target.entities,
|
|
|
|
no_webpage=not target.media,
|
|
|
|
reply_to_msg_id=target.id
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2018-11-28 13:09:29 +00:00
|
|
|
@self_reply_cmd(borg, r'(?ms)^(.+)\n\.e$')
|
2018-11-24 21:14:04 +00:00
|
|
|
async def on_edit_end(event, target):
|
|
|
|
text = event.pattern_match.group(1)
|
|
|
|
message = event.message.message[:-2]
|
|
|
|
if message.strip() == '.':
|
|
|
|
message = ''
|
2018-12-07 13:54:11 +00:00
|
|
|
chat = await event.get_input_chat()
|
2018-11-24 21:14:04 +00:00
|
|
|
try:
|
|
|
|
await borg(EditMessageRequest(
|
2018-12-07 13:54:11 +00:00
|
|
|
peer=chat,
|
2018-11-24 21:14:04 +00:00
|
|
|
id=target.id,
|
|
|
|
no_webpage=not target.media,
|
|
|
|
message=message,
|
|
|
|
entities=event.message.entities
|
|
|
|
))
|
|
|
|
except MessageEmptyError:
|
|
|
|
# Can't make text message empty, so delete it
|
|
|
|
await borg.delete_messages(chat, target)
|