mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-10 18:59:33 +00:00
Replace most raw API usage with new location
This commit is contained in:
@@ -3,9 +3,7 @@ import time
|
||||
import weakref
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
from ..tl.custom.sendergetter import SenderGetter
|
||||
from .. import utils, _tl
|
||||
|
||||
_IGNORE_MAX_SIZE = 100 # len()
|
||||
_IGNORE_MAX_AGE = 5 # seconds
|
||||
@@ -101,8 +99,8 @@ class Album(EventBuilder):
|
||||
return # We only care about albums which come inside the same Updates
|
||||
|
||||
if isinstance(update,
|
||||
(types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
||||
if not isinstance(update.message, types.Message):
|
||||
(_tl.UpdateNewMessage, _tl.UpdateNewChannelMessage)):
|
||||
if not isinstance(update.message, _tl.Message):
|
||||
return # We don't care about MessageService's here
|
||||
|
||||
group = update.message.grouped_id
|
||||
@@ -130,8 +128,8 @@ class Album(EventBuilder):
|
||||
# Figure out which updates share the same group and use those
|
||||
return cls.Event([
|
||||
u.message for u in others
|
||||
if (isinstance(u, (types.UpdateNewMessage, types.UpdateNewChannelMessage))
|
||||
and isinstance(u.message, types.Message)
|
||||
if (isinstance(u, (_tl.UpdateNewMessage, _tl.UpdateNewChannelMessage))
|
||||
and isinstance(u.message, _tl.Message)
|
||||
and u.message.grouped_id == group)
|
||||
])
|
||||
|
||||
@@ -140,7 +138,7 @@ class Album(EventBuilder):
|
||||
if len(event.messages) > 1:
|
||||
return super().filter(event)
|
||||
|
||||
class Event(EventCommon, SenderGetter):
|
||||
class Event(EventCommon, _tl.custom.sendergetter.SenderGetter):
|
||||
"""
|
||||
Represents the event of a new album.
|
||||
|
||||
@@ -150,7 +148,7 @@ class Album(EventBuilder):
|
||||
"""
|
||||
def __init__(self, messages):
|
||||
message = messages[0]
|
||||
if not message.out and isinstance(message.peer_id, types.PeerUser):
|
||||
if not message.out and isinstance(message.peer_id, _tl.PeerUser):
|
||||
# Incoming message (e.g. from a bot) has peer_id=us, and
|
||||
# from_id=bot (the actual "chat" from a user's perspective).
|
||||
chat_peer = message.from_id
|
||||
@@ -160,7 +158,7 @@ class Album(EventBuilder):
|
||||
super().__init__(chat_peer=chat_peer,
|
||||
msg_id=message.id, broadcast=bool(message.post))
|
||||
|
||||
SenderGetter.__init__(self, message.sender_id)
|
||||
_tl.custom.sendergetter.SenderGetter.__init__(self, message.sender_id)
|
||||
self.messages = messages
|
||||
|
||||
def _set_client(self, client):
|
||||
|
@@ -2,9 +2,7 @@ import re
|
||||
import struct
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types, functions
|
||||
from ..tl.custom.sendergetter import SenderGetter
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -88,13 +86,13 @@ class CallbackQuery(EventBuilder):
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, types.UpdateBotCallbackQuery):
|
||||
if isinstance(update, _tl.UpdateBotCallbackQuery):
|
||||
return cls.Event(update, update.peer, update.msg_id)
|
||||
elif isinstance(update, types.UpdateInlineBotCallbackQuery):
|
||||
elif isinstance(update, _tl.UpdateInlineBotCallbackQuery):
|
||||
# See https://github.com/LonamiWebs/Telethon/pull/1005
|
||||
# The long message ID is actually just msg_id + peer_id
|
||||
mid, pid = struct.unpack('<ii', struct.pack('<q', update.msg_id.id))
|
||||
peer = types.PeerChannel(-pid) if pid < 0 else types.PeerUser(pid)
|
||||
peer = _tl.PeerChannel(-pid) if pid < 0 else _tl.PeerUser(pid)
|
||||
return cls.Event(update, peer, mid)
|
||||
|
||||
def filter(self, event):
|
||||
@@ -123,7 +121,7 @@ class CallbackQuery(EventBuilder):
|
||||
return self.func(event)
|
||||
return True
|
||||
|
||||
class Event(EventCommon, SenderGetter):
|
||||
class Event(EventCommon, _tl.custom.sendergetter.SenderGetter):
|
||||
"""
|
||||
Represents the event of a new callback query.
|
||||
|
||||
@@ -141,7 +139,7 @@ class CallbackQuery(EventBuilder):
|
||||
"""
|
||||
def __init__(self, query, peer, msg_id):
|
||||
super().__init__(peer, msg_id=msg_id)
|
||||
SenderGetter.__init__(self, query.user_id)
|
||||
_tl.custom.sendergetter.SenderGetter.__init__(self, query.user_id)
|
||||
self.query = query
|
||||
self.data_match = None
|
||||
self.pattern_match = None
|
||||
@@ -242,7 +240,7 @@ class CallbackQuery(EventBuilder):
|
||||
|
||||
self._answered = True
|
||||
return await self._client(
|
||||
functions.messages.SetBotCallbackAnswerRequest(
|
||||
_tl.fn.messages.SetBotCallbackAnswerRequest(
|
||||
query_id=self.query.query_id,
|
||||
cache_time=cache_time,
|
||||
alert=alert,
|
||||
@@ -264,7 +262,7 @@ class CallbackQuery(EventBuilder):
|
||||
chat, so methods like `respond` or `delete` won't work (but
|
||||
`edit` will always work).
|
||||
"""
|
||||
return isinstance(self.query, types.UpdateInlineBotCallbackQuery)
|
||||
return isinstance(self.query, _tl.UpdateInlineBotCallbackQuery)
|
||||
|
||||
async def respond(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -312,7 +310,7 @@ class CallbackQuery(EventBuilder):
|
||||
since the message object is normally not present.
|
||||
"""
|
||||
self._client.loop.create_task(self.answer())
|
||||
if isinstance(self.query.msg_id, types.InputBotInlineMessageID):
|
||||
if isinstance(self.query.msg_id, _tl.InputBotInlineMessageID):
|
||||
return await self._client.edit_message(
|
||||
self.query.msg_id, *args, **kwargs
|
||||
)
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -36,23 +35,23 @@ class ChatAction(EventBuilder):
|
||||
# Rely on specific pin updates for unpins, but otherwise ignore them
|
||||
# for new pins (we'd rather handle the new service message with pin,
|
||||
# so that we can act on that message').
|
||||
if isinstance(update, types.UpdatePinnedChannelMessages) and not update.pinned:
|
||||
return cls.Event(types.PeerChannel(update.channel_id),
|
||||
if isinstance(update, _tl.UpdatePinnedChannelMessages) and not update.pinned:
|
||||
return cls.Event(_tl.PeerChannel(update.channel_id),
|
||||
pin_ids=update.messages,
|
||||
pin=update.pinned)
|
||||
|
||||
elif isinstance(update, types.UpdatePinnedMessages) and not update.pinned:
|
||||
elif isinstance(update, _tl.UpdatePinnedMessages) and not update.pinned:
|
||||
return cls.Event(update.peer,
|
||||
pin_ids=update.messages,
|
||||
pin=update.pinned)
|
||||
|
||||
elif isinstance(update, types.UpdateChatParticipantAdd):
|
||||
return cls.Event(types.PeerChat(update.chat_id),
|
||||
elif isinstance(update, _tl.UpdateChatParticipantAdd):
|
||||
return cls.Event(_tl.PeerChat(update.chat_id),
|
||||
added_by=update.inviter_id or True,
|
||||
users=update.user_id)
|
||||
|
||||
elif isinstance(update, types.UpdateChatParticipantDelete):
|
||||
return cls.Event(types.PeerChat(update.chat_id),
|
||||
elif isinstance(update, _tl.UpdateChatParticipantDelete):
|
||||
return cls.Event(_tl.PeerChat(update.chat_id),
|
||||
kicked_by=True,
|
||||
users=update.user_id)
|
||||
|
||||
@@ -61,50 +60,50 @@ class ChatAction(EventBuilder):
|
||||
# better not to rely on this. Rely only in MessageActionChatDeleteUser.
|
||||
|
||||
elif (isinstance(update, (
|
||||
types.UpdateNewMessage, types.UpdateNewChannelMessage))
|
||||
and isinstance(update.message, types.MessageService)):
|
||||
_tl.UpdateNewMessage, _tl.UpdateNewChannelMessage))
|
||||
and isinstance(update.message, _tl.MessageService)):
|
||||
msg = update.message
|
||||
action = update.message.action
|
||||
if isinstance(action, types.MessageActionChatJoinedByLink):
|
||||
if isinstance(action, _tl.MessageActionChatJoinedByLink):
|
||||
return cls.Event(msg,
|
||||
added_by=True,
|
||||
users=msg.from_id)
|
||||
elif isinstance(action, types.MessageActionChatAddUser):
|
||||
elif isinstance(action, _tl.MessageActionChatAddUser):
|
||||
# If a user adds itself, it means they joined via the public chat username
|
||||
added_by = ([msg.sender_id] == action.users) or msg.from_id
|
||||
return cls.Event(msg,
|
||||
added_by=added_by,
|
||||
users=action.users)
|
||||
elif isinstance(action, types.MessageActionChatDeleteUser):
|
||||
elif isinstance(action, _tl.MessageActionChatDeleteUser):
|
||||
return cls.Event(msg,
|
||||
kicked_by=utils.get_peer_id(msg.from_id) if msg.from_id else True,
|
||||
users=action.user_id)
|
||||
elif isinstance(action, types.MessageActionChatCreate):
|
||||
elif isinstance(action, _tl.MessageActionChatCreate):
|
||||
return cls.Event(msg,
|
||||
users=action.users,
|
||||
created=True,
|
||||
new_title=action.title)
|
||||
elif isinstance(action, types.MessageActionChannelCreate):
|
||||
elif isinstance(action, _tl.MessageActionChannelCreate):
|
||||
return cls.Event(msg,
|
||||
created=True,
|
||||
users=msg.from_id,
|
||||
new_title=action.title)
|
||||
elif isinstance(action, types.MessageActionChatEditTitle):
|
||||
elif isinstance(action, _tl.MessageActionChatEditTitle):
|
||||
return cls.Event(msg,
|
||||
users=msg.from_id,
|
||||
new_title=action.title)
|
||||
elif isinstance(action, types.MessageActionChatEditPhoto):
|
||||
elif isinstance(action, _tl.MessageActionChatEditPhoto):
|
||||
return cls.Event(msg,
|
||||
users=msg.from_id,
|
||||
new_photo=action.photo)
|
||||
elif isinstance(action, types.MessageActionChatDeletePhoto):
|
||||
elif isinstance(action, _tl.MessageActionChatDeletePhoto):
|
||||
return cls.Event(msg,
|
||||
users=msg.from_id,
|
||||
new_photo=True)
|
||||
elif isinstance(action, types.MessageActionPinMessage) and msg.reply_to:
|
||||
elif isinstance(action, _tl.MessageActionPinMessage) and msg.reply_to:
|
||||
return cls.Event(msg,
|
||||
pin_ids=[msg.reply_to_msg_id])
|
||||
elif isinstance(action, types.MessageActionGameScore):
|
||||
elif isinstance(action, _tl.MessageActionGameScore):
|
||||
return cls.Event(msg,
|
||||
new_score=action.score)
|
||||
|
||||
@@ -142,7 +141,7 @@ class ChatAction(EventBuilder):
|
||||
|
||||
new_title (`str`, optional):
|
||||
The new title string for the chat, if applicable.
|
||||
|
||||
|
||||
new_score (`str`, optional):
|
||||
The new score string for the game, if applicable.
|
||||
|
||||
@@ -153,7 +152,7 @@ class ChatAction(EventBuilder):
|
||||
def __init__(self, where, new_photo=None,
|
||||
added_by=None, kicked_by=None, created=None,
|
||||
users=None, new_title=None, pin_ids=None, pin=None, new_score=None):
|
||||
if isinstance(where, types.MessageService):
|
||||
if isinstance(where, _tl.MessageService):
|
||||
self.action_message = where
|
||||
where = where.peer_id
|
||||
else:
|
||||
@@ -169,7 +168,7 @@ class ChatAction(EventBuilder):
|
||||
|
||||
self.new_photo = new_photo is not None
|
||||
self.photo = \
|
||||
new_photo if isinstance(new_photo, types.Photo) else None
|
||||
new_photo if isinstance(new_photo, _tl.Photo) else None
|
||||
|
||||
self._added_by = None
|
||||
self._kicked_by = None
|
||||
@@ -283,7 +282,7 @@ class ChatAction(EventBuilder):
|
||||
"""
|
||||
The user who added ``users``, if applicable (`None` otherwise).
|
||||
"""
|
||||
if self._added_by and not isinstance(self._added_by, types.User):
|
||||
if self._added_by and not isinstance(self._added_by, _tl.User):
|
||||
aby = self._entities.get(utils.get_peer_id(self._added_by))
|
||||
if aby:
|
||||
self._added_by = aby
|
||||
@@ -304,7 +303,7 @@ class ChatAction(EventBuilder):
|
||||
"""
|
||||
The user who kicked ``users``, if applicable (`None` otherwise).
|
||||
"""
|
||||
if self._kicked_by and not isinstance(self._kicked_by, types.User):
|
||||
if self._kicked_by and not isinstance(self._kicked_by, _tl.User):
|
||||
kby = self._entities.get(utils.get_peer_id(self._kicked_by))
|
||||
if kby:
|
||||
self._kicked_by = kby
|
||||
@@ -393,7 +392,7 @@ class ChatAction(EventBuilder):
|
||||
await self.action_message._reload_message()
|
||||
self._users = [
|
||||
u for u in self.action_message.action_entities
|
||||
if isinstance(u, (types.User, types.UserEmpty))]
|
||||
if isinstance(u, (_tl.User, _tl.UserEmpty))]
|
||||
|
||||
return self._users
|
||||
|
||||
@@ -433,7 +432,7 @@ class ChatAction(EventBuilder):
|
||||
self._input_users = [
|
||||
utils.get_input_peer(u)
|
||||
for u in self.action_message.action_entities
|
||||
if isinstance(u, (types.User, types.UserEmpty))]
|
||||
if isinstance(u, (_tl.User, _tl.UserEmpty))]
|
||||
|
||||
return self._input_users or []
|
||||
|
||||
|
@@ -2,9 +2,7 @@ import abc
|
||||
import asyncio
|
||||
import warnings
|
||||
|
||||
from .. import utils
|
||||
from ..tl import TLObject, types
|
||||
from ..tl.custom.chatgetter import ChatGetter
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
async def _into_id_set(client, chats):
|
||||
@@ -22,16 +20,16 @@ async def _into_id_set(client, chats):
|
||||
result.add(chat) # Explicitly marked IDs are negative
|
||||
else:
|
||||
result.update({ # Support all valid types of peers
|
||||
utils.get_peer_id(types.PeerUser(chat)),
|
||||
utils.get_peer_id(types.PeerChat(chat)),
|
||||
utils.get_peer_id(types.PeerChannel(chat)),
|
||||
utils.get_peer_id(_tl.PeerUser(chat)),
|
||||
utils.get_peer_id(_tl.PeerChat(chat)),
|
||||
utils.get_peer_id(_tl.PeerChannel(chat)),
|
||||
})
|
||||
elif isinstance(chat, TLObject) and chat.SUBCLASS_OF_ID == 0x2d45687:
|
||||
elif isinstance(chat, _tl.TLObject) and chat.SUBCLASS_OF_ID == 0x2d45687:
|
||||
# 0x2d45687 == crc32(b'Peer')
|
||||
result.add(utils.get_peer_id(chat))
|
||||
else:
|
||||
chat = await client.get_input_entity(chat)
|
||||
if isinstance(chat, types.InputPeerSelf):
|
||||
if isinstance(chat, _tl.InputPeerSelf):
|
||||
chat = await client.get_me(input_peer=True)
|
||||
result.add(utils.get_peer_id(chat))
|
||||
|
||||
@@ -166,10 +164,10 @@ class EventCommon(ChatGetter, abc.ABC):
|
||||
return self._client
|
||||
|
||||
def __str__(self):
|
||||
return TLObject.pretty_format(self.to_dict())
|
||||
return _tl.TLObject.pretty_format(self.to_dict())
|
||||
|
||||
def stringify(self):
|
||||
return TLObject.pretty_format(self.to_dict(), indent=0)
|
||||
return _tl.TLObject.pretty_format(self.to_dict(), indent=0)
|
||||
|
||||
def to_dict(self):
|
||||
d = {k: v for k, v in self.__dict__.items() if k[0] != '_'}
|
||||
|
@@ -4,9 +4,7 @@ import re
|
||||
import asyncio
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types, functions, custom
|
||||
from ..tl.custom.sendergetter import SenderGetter
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -62,7 +60,7 @@ class InlineQuery(EventBuilder):
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, types.UpdateBotInlineQuery):
|
||||
if isinstance(update, _tl.UpdateBotInlineQuery):
|
||||
return cls.Event(update)
|
||||
|
||||
def filter(self, event):
|
||||
@@ -74,7 +72,7 @@ class InlineQuery(EventBuilder):
|
||||
|
||||
return super().filter(event)
|
||||
|
||||
class Event(EventCommon, SenderGetter):
|
||||
class Event(EventCommon, _tl.custom.sendergetter.SenderGetter):
|
||||
"""
|
||||
Represents the event of a new callback query.
|
||||
|
||||
@@ -90,8 +88,8 @@ class InlineQuery(EventBuilder):
|
||||
function, which is ``re.compile(...).match`` by default.
|
||||
"""
|
||||
def __init__(self, query):
|
||||
super().__init__(chat_peer=types.PeerUser(query.user_id))
|
||||
SenderGetter.__init__(self, query.user_id)
|
||||
super().__init__(chat_peer=_tl.PeerUser(query.user_id))
|
||||
_tl.custom.sendergetter.SenderGetter.__init__(self, query.user_id)
|
||||
self.query = query
|
||||
self.pattern_match = None
|
||||
self._answered = False
|
||||
@@ -223,10 +221,10 @@ class InlineQuery(EventBuilder):
|
||||
results = []
|
||||
|
||||
if switch_pm:
|
||||
switch_pm = types.InlineBotSwitchPM(switch_pm, switch_pm_param)
|
||||
switch_pm = _tl.InlineBotSwitchPM(switch_pm, switch_pm_param)
|
||||
|
||||
return await self._client(
|
||||
functions.messages.SetInlineBotResultsRequest(
|
||||
_tl.fn.messages.SetInlineBotResults(
|
||||
query_id=self.query.query_id,
|
||||
results=results,
|
||||
cache_time=cache_time,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from ..tl import types
|
||||
from .. import _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -37,15 +37,15 @@ class MessageDeleted(EventBuilder):
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, types.UpdateDeleteMessages):
|
||||
if isinstance(update, _tl.UpdateDeleteMessages):
|
||||
return cls.Event(
|
||||
deleted_ids=update.messages,
|
||||
peer=None
|
||||
)
|
||||
elif isinstance(update, types.UpdateDeleteChannelMessages):
|
||||
elif isinstance(update, _tl.UpdateDeleteChannelMessages):
|
||||
return cls.Event(
|
||||
deleted_ids=update.messages,
|
||||
peer=types.PeerChannel(update.channel_id)
|
||||
peer=_tl.PeerChannel(update.channel_id)
|
||||
)
|
||||
|
||||
class Event(EventCommon):
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from .common import name_inner_event
|
||||
from .newmessage import NewMessage
|
||||
from ..tl import types
|
||||
from .. import _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -44,8 +44,8 @@ class MessageEdited(NewMessage):
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, (types.UpdateEditMessage,
|
||||
types.UpdateEditChannelMessage)):
|
||||
if isinstance(update, (_tl.UpdateEditMessage,
|
||||
_tl.UpdateEditChannelMessage)):
|
||||
return cls.Event(update.message)
|
||||
|
||||
class Event(NewMessage.Event):
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -36,21 +35,21 @@ class MessageRead(EventBuilder):
|
||||
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, types.UpdateReadHistoryInbox):
|
||||
if isinstance(update, _tl.UpdateReadHistoryInbox):
|
||||
return cls.Event(update.peer, update.max_id, False)
|
||||
elif isinstance(update, types.UpdateReadHistoryOutbox):
|
||||
elif isinstance(update, _tl.UpdateReadHistoryOutbox):
|
||||
return cls.Event(update.peer, update.max_id, True)
|
||||
elif isinstance(update, types.UpdateReadChannelInbox):
|
||||
return cls.Event(types.PeerChannel(update.channel_id),
|
||||
elif isinstance(update, _tl.UpdateReadChannelInbox):
|
||||
return cls.Event(_tl.PeerChannel(update.channel_id),
|
||||
update.max_id, False)
|
||||
elif isinstance(update, types.UpdateReadChannelOutbox):
|
||||
return cls.Event(types.PeerChannel(update.channel_id),
|
||||
elif isinstance(update, _tl.UpdateReadChannelOutbox):
|
||||
return cls.Event(_tl.PeerChannel(update.channel_id),
|
||||
update.max_id, True)
|
||||
elif isinstance(update, types.UpdateReadMessagesContents):
|
||||
elif isinstance(update, _tl.UpdateReadMessagesContents):
|
||||
return cls.Event(message_ids=update.messages,
|
||||
contents=True)
|
||||
elif isinstance(update, types.UpdateChannelReadMessagesContents):
|
||||
return cls.Event(types.PeerChannel(update.channel_id),
|
||||
elif isinstance(update, _tl.UpdateChannelReadMessagesContents):
|
||||
return cls.Event(_tl.PeerChannel(update.channel_id),
|
||||
message_ids=update.messages,
|
||||
contents=True)
|
||||
|
||||
|
@@ -1,8 +1,7 @@
|
||||
import re
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event, _into_id_set
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
@name_inner_event
|
||||
@@ -96,19 +95,19 @@ class NewMessage(EventBuilder):
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update,
|
||||
(types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
||||
if not isinstance(update.message, types.Message):
|
||||
(_tl.UpdateNewMessage, _tl.UpdateNewChannelMessage)):
|
||||
if not isinstance(update.message, _tl.Message):
|
||||
return # We don't care about MessageService's here
|
||||
event = cls.Event(update.message)
|
||||
elif isinstance(update, types.UpdateShortMessage):
|
||||
event = cls.Event(types.Message(
|
||||
elif isinstance(update, _tl.UpdateShortMessage):
|
||||
event = cls.Event(_tl.Message(
|
||||
out=update.out,
|
||||
mentioned=update.mentioned,
|
||||
media_unread=update.media_unread,
|
||||
silent=update.silent,
|
||||
id=update.id,
|
||||
peer_id=types.PeerUser(update.user_id),
|
||||
from_id=types.PeerUser(self_id if update.out else update.user_id),
|
||||
peer_id=_tl.PeerUser(update.user_id),
|
||||
from_id=_tl.PeerUser(self_id if update.out else update.user_id),
|
||||
message=update.message,
|
||||
date=update.date,
|
||||
fwd_from=update.fwd_from,
|
||||
@@ -117,15 +116,15 @@ class NewMessage(EventBuilder):
|
||||
entities=update.entities,
|
||||
ttl_period=update.ttl_period
|
||||
))
|
||||
elif isinstance(update, types.UpdateShortChatMessage):
|
||||
event = cls.Event(types.Message(
|
||||
elif isinstance(update, _tl.UpdateShortChatMessage):
|
||||
event = cls.Event(_tl.Message(
|
||||
out=update.out,
|
||||
mentioned=update.mentioned,
|
||||
media_unread=update.media_unread,
|
||||
silent=update.silent,
|
||||
id=update.id,
|
||||
from_id=types.PeerUser(self_id if update.out else update.from_id),
|
||||
peer_id=types.PeerChat(update.chat_id),
|
||||
from_id=_tl.PeerUser(self_id if update.out else update.from_id),
|
||||
peer_id=_tl.PeerChat(update.chat_id),
|
||||
message=update.message,
|
||||
date=update.date,
|
||||
fwd_from=update.fwd_from,
|
||||
|
@@ -2,9 +2,7 @@ import datetime
|
||||
import functools
|
||||
|
||||
from .common import EventBuilder, EventCommon, name_inner_event
|
||||
from .. import utils
|
||||
from ..tl import types
|
||||
from ..tl.custom.sendergetter import SenderGetter
|
||||
from .. import utils, _tl
|
||||
|
||||
|
||||
# TODO Either the properties are poorly named or they should be
|
||||
@@ -50,22 +48,22 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
@classmethod
|
||||
def build(cls, update, others=None, self_id=None):
|
||||
if isinstance(update, types.UpdateUserStatus):
|
||||
return cls.Event(types.PeerUser(update.user_id),
|
||||
if isinstance(update, _tl.UpdateUserStatus):
|
||||
return cls.Event(_tl.PeerUser(update.user_id),
|
||||
status=update.status)
|
||||
elif isinstance(update, types.UpdateChannelUserTyping):
|
||||
elif isinstance(update, _tl.UpdateChannelUserTyping):
|
||||
return cls.Event(update.from_id,
|
||||
chat_peer=types.PeerChannel(update.channel_id),
|
||||
chat_peer=_tl.PeerChannel(update.channel_id),
|
||||
typing=update.action)
|
||||
elif isinstance(update, types.UpdateChatUserTyping):
|
||||
elif isinstance(update, _tl.UpdateChatUserTyping):
|
||||
return cls.Event(update.from_id,
|
||||
chat_peer=types.PeerChat(update.chat_id),
|
||||
chat_peer=_tl.PeerChat(update.chat_id),
|
||||
typing=update.action)
|
||||
elif isinstance(update, types.UpdateUserTyping):
|
||||
elif isinstance(update, _tl.UpdateUserTyping):
|
||||
return cls.Event(update.user_id,
|
||||
typing=update.action)
|
||||
|
||||
class Event(EventCommon, SenderGetter):
|
||||
class Event(EventCommon, _tl.custom.sendergetter.SenderGetter):
|
||||
"""
|
||||
Represents the event of a user update
|
||||
such as gone online, started typing, etc.
|
||||
@@ -87,7 +85,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
def __init__(self, peer, *, status=None, chat_peer=None, typing=None):
|
||||
super().__init__(chat_peer or peer)
|
||||
SenderGetter.__init__(self, utils.get_peer_id(peer))
|
||||
_tl.custom.sendergetter.SenderGetter.__init__(self, utils.get_peer_id(peer))
|
||||
|
||||
self.status = status
|
||||
self.action = typing
|
||||
@@ -126,7 +124,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if the action is typing a message.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageTypingAction)
|
||||
return isinstance(self.action, _tl.SendMessageTypingAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -135,13 +133,13 @@ class UserUpdate(EventBuilder):
|
||||
`True` if the action is uploading something.
|
||||
"""
|
||||
return isinstance(self.action, (
|
||||
types.SendMessageChooseContactAction,
|
||||
types.SendMessageChooseStickerAction,
|
||||
types.SendMessageUploadAudioAction,
|
||||
types.SendMessageUploadDocumentAction,
|
||||
types.SendMessageUploadPhotoAction,
|
||||
types.SendMessageUploadRoundAction,
|
||||
types.SendMessageUploadVideoAction
|
||||
_tl.SendMessageChooseContactAction,
|
||||
_tl.SendMessageChooseStickerAction,
|
||||
_tl.SendMessageUploadAudioAction,
|
||||
_tl.SendMessageUploadDocumentAction,
|
||||
_tl.SendMessageUploadPhotoAction,
|
||||
_tl.SendMessageUploadRoundAction,
|
||||
_tl.SendMessageUploadVideoAction
|
||||
))
|
||||
|
||||
@property
|
||||
@@ -151,9 +149,9 @@ class UserUpdate(EventBuilder):
|
||||
`True` if the action is recording something.
|
||||
"""
|
||||
return isinstance(self.action, (
|
||||
types.SendMessageRecordAudioAction,
|
||||
types.SendMessageRecordRoundAction,
|
||||
types.SendMessageRecordVideoAction
|
||||
_tl.SendMessageRecordAudioAction,
|
||||
_tl.SendMessageRecordRoundAction,
|
||||
_tl.SendMessageRecordVideoAction
|
||||
))
|
||||
|
||||
@property
|
||||
@@ -162,7 +160,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if the action is playing a game.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageGamePlayAction)
|
||||
return isinstance(self.action, _tl.SendMessageGamePlayAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -170,7 +168,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if the action was cancelling other actions.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageCancelAction)
|
||||
return isinstance(self.action, _tl.SendMessageCancelAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -178,7 +176,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if what's being uploaded is a geo.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageGeoLocationAction)
|
||||
return isinstance(self.action, _tl.SendMessageGeoLocationAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -187,8 +185,8 @@ class UserUpdate(EventBuilder):
|
||||
`True` if what's being recorded/uploaded is an audio.
|
||||
"""
|
||||
return isinstance(self.action, (
|
||||
types.SendMessageRecordAudioAction,
|
||||
types.SendMessageUploadAudioAction
|
||||
_tl.SendMessageRecordAudioAction,
|
||||
_tl.SendMessageUploadAudioAction
|
||||
))
|
||||
|
||||
@property
|
||||
@@ -198,8 +196,8 @@ class UserUpdate(EventBuilder):
|
||||
`True` if what's being recorded/uploaded is a round video.
|
||||
"""
|
||||
return isinstance(self.action, (
|
||||
types.SendMessageRecordRoundAction,
|
||||
types.SendMessageUploadRoundAction
|
||||
_tl.SendMessageRecordRoundAction,
|
||||
_tl.SendMessageUploadRoundAction
|
||||
))
|
||||
|
||||
@property
|
||||
@@ -209,8 +207,8 @@ class UserUpdate(EventBuilder):
|
||||
`True` if what's being recorded/uploaded is an video.
|
||||
"""
|
||||
return isinstance(self.action, (
|
||||
types.SendMessageRecordVideoAction,
|
||||
types.SendMessageUploadVideoAction
|
||||
_tl.SendMessageRecordVideoAction,
|
||||
_tl.SendMessageUploadVideoAction
|
||||
))
|
||||
|
||||
@property
|
||||
@@ -219,7 +217,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if what's being uploaded (selected) is a contact.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageChooseContactAction)
|
||||
return isinstance(self.action, _tl.SendMessageChooseContactAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -227,7 +225,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if what's being uploaded is document.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageUploadDocumentAction)
|
||||
return isinstance(self.action, _tl.SendMessageUploadDocumentAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -235,7 +233,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if what's being uploaded is a sticker.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageChooseStickerAction)
|
||||
return isinstance(self.action, _tl.SendMessageChooseStickerAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -243,7 +241,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
`True` if what's being uploaded is a photo.
|
||||
"""
|
||||
return isinstance(self.action, types.SendMessageUploadPhotoAction)
|
||||
return isinstance(self.action, _tl.SendMessageUploadPhotoAction)
|
||||
|
||||
@property
|
||||
@_requires_action
|
||||
@@ -251,7 +249,7 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
Exact `datetime.datetime` when the user was last seen if known.
|
||||
"""
|
||||
if isinstance(self.status, types.UserStatusOffline):
|
||||
if isinstance(self.status, _tl.UserStatusOffline):
|
||||
return self.status.was_online
|
||||
|
||||
@property
|
||||
@@ -260,19 +258,19 @@ class UserUpdate(EventBuilder):
|
||||
"""
|
||||
The `datetime.datetime` until when the user should appear online.
|
||||
"""
|
||||
if isinstance(self.status, types.UserStatusOnline):
|
||||
if isinstance(self.status, _tl.UserStatusOnline):
|
||||
return self.status.expires
|
||||
|
||||
def _last_seen_delta(self):
|
||||
if isinstance(self.status, types.UserStatusOffline):
|
||||
if isinstance(self.status, _tl.UserStatusOffline):
|
||||
return datetime.datetime.now(tz=datetime.timezone.utc) - self.status.was_online
|
||||
elif isinstance(self.status, types.UserStatusOnline):
|
||||
elif isinstance(self.status, _tl.UserStatusOnline):
|
||||
return datetime.timedelta(days=0)
|
||||
elif isinstance(self.status, types.UserStatusRecently):
|
||||
elif isinstance(self.status, _tl.UserStatusRecently):
|
||||
return datetime.timedelta(days=1)
|
||||
elif isinstance(self.status, types.UserStatusLastWeek):
|
||||
elif isinstance(self.status, _tl.UserStatusLastWeek):
|
||||
return datetime.timedelta(days=7)
|
||||
elif isinstance(self.status, types.UserStatusLastMonth):
|
||||
elif isinstance(self.status, _tl.UserStatusLastMonth):
|
||||
return datetime.timedelta(days=30)
|
||||
else:
|
||||
return datetime.timedelta(days=365)
|
||||
|
Reference in New Issue
Block a user