2018-04-07 22:09:02 +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 re
|
|
|
|
|
|
|
|
from telethon import events
|
2018-04-08 12:43:23 +00:00
|
|
|
from telethon.tl.functions.messages import GetPeerDialogsRequest
|
2018-04-07 22:09:02 +00:00
|
|
|
|
|
|
|
def admin_cmd(pattern):
|
|
|
|
return events.NewMessage(outgoing=True, pattern=re.compile(pattern))
|
2018-04-08 12:43:23 +00:00
|
|
|
|
|
|
|
async def is_read(borg, entity, message, is_out=None):
|
|
|
|
"""
|
|
|
|
Returns True if the given message (or id) has been read
|
|
|
|
if a id is given, is_out needs to be a bool
|
|
|
|
"""
|
|
|
|
is_out = getattr(message, 'out', is_out)
|
|
|
|
if not isinstance(is_out, bool):
|
|
|
|
raise ValueError('Message was id but is_out not provided or not a bool')
|
|
|
|
message_id = getattr(message, 'id', message)
|
|
|
|
if not isinstance(message_id, int):
|
|
|
|
raise ValueError('Failed to extract id from message')
|
|
|
|
|
|
|
|
dialog = (await borg(GetPeerDialogsRequest([entity]))).dialogs[0]
|
|
|
|
max_id = dialog.read_outbox_max_id if is_out else dialog.read_inbox_max_id
|
|
|
|
return message_id <= max_id
|