uniborg/stdplugins/fixreply.py

28 lines
802 B
Python
Raw Normal View History

2019-02-27 12:20:24 +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
2019-03-04 07:05:40 +00:00
_last_messages = {}
2019-02-27 12:20:24 +00:00
@borg.on(events.NewMessage(outgoing=True))
async def _(event):
2019-03-04 07:05:40 +00:00
_last_messages[event.chat_id] = event.message
2019-02-27 12:20:24 +00:00
@borg.on(events.NewMessage(pattern=r"\.(fix)?reply", outgoing=True))
async def _(event):
2019-03-04 07:05:40 +00:00
if not event.is_reply or event.chat_id not in _last_messages:
2019-02-27 12:20:24 +00:00
return
2019-03-04 07:05:40 +00:00
message = _last_messages[event.chat_id]
2019-02-27 12:20:24 +00:00
chat = await event.get_input_chat()
await asyncio.wait([
2019-03-04 07:05:40 +00:00
borg.delete_messages(chat, [event.id, message.id]),
borg.send_message(chat, message, reply_to=event.reply_to_msg_id)
2019-02-27 12:20:24 +00:00
])