mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Add enumerations
This commit is contained in:
parent
9661b804b6
commit
bbad58a83f
8
docs/source/api/enums/ChatAction.rst
Normal file
8
docs/source/api/enums/ChatAction.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ChatAction
|
||||
==========
|
||||
|
||||
.. autoclass:: pyrogram.enums.ChatAction()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/ChatEventAction.rst
Normal file
8
docs/source/api/enums/ChatEventAction.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ChatEventAction
|
||||
===============
|
||||
|
||||
.. autoclass:: pyrogram.enums.ChatEventAction()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/ChatMemberStatus.rst
Normal file
8
docs/source/api/enums/ChatMemberStatus.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ChatMemberStatus
|
||||
================
|
||||
|
||||
.. autoclass:: pyrogram.enums.ChatMemberStatus()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/ChatMembersFilter.rst
Normal file
8
docs/source/api/enums/ChatMembersFilter.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ChatMembersFilter
|
||||
=================
|
||||
|
||||
.. autoclass:: pyrogram.enums.ChatMembersFilter()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/ChatType.rst
Normal file
8
docs/source/api/enums/ChatType.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ChatType
|
||||
========
|
||||
|
||||
.. autoclass:: pyrogram.enums.ChatType()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/MessageEntityType.rst
Normal file
8
docs/source/api/enums/MessageEntityType.rst
Normal file
@ -0,0 +1,8 @@
|
||||
MessageEntityType
|
||||
=================
|
||||
|
||||
.. autoclass:: pyrogram.enums.MessageEntityType()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/MessageMedia.rst
Normal file
8
docs/source/api/enums/MessageMedia.rst
Normal file
@ -0,0 +1,8 @@
|
||||
MessageMedia
|
||||
============
|
||||
|
||||
.. autoclass:: pyrogram.enums.MessageMedia()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/MessageService.rst
Normal file
8
docs/source/api/enums/MessageService.rst
Normal file
@ -0,0 +1,8 @@
|
||||
MessageService
|
||||
==============
|
||||
|
||||
.. autoclass:: pyrogram.enums.MessageService()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/MessagesFilter.rst
Normal file
8
docs/source/api/enums/MessagesFilter.rst
Normal file
@ -0,0 +1,8 @@
|
||||
MessagesFilter
|
||||
==============
|
||||
|
||||
.. autoclass:: pyrogram.enums.MessagesFilter()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/ParseMode.rst
Normal file
8
docs/source/api/enums/ParseMode.rst
Normal file
@ -0,0 +1,8 @@
|
||||
ParseMode
|
||||
=========
|
||||
|
||||
.. autoclass:: pyrogram.enums.ParseMode()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/PollType.rst
Normal file
8
docs/source/api/enums/PollType.rst
Normal file
@ -0,0 +1,8 @@
|
||||
PollType
|
||||
========
|
||||
|
||||
.. autoclass:: pyrogram.enums.PollType()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/SentCodeType.rst
Normal file
8
docs/source/api/enums/SentCodeType.rst
Normal file
@ -0,0 +1,8 @@
|
||||
SentCodeType
|
||||
============
|
||||
|
||||
.. autoclass:: pyrogram.enums.SentCodeType()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
8
docs/source/api/enums/UserStatus.rst
Normal file
8
docs/source/api/enums/UserStatus.rst
Normal file
@ -0,0 +1,8 @@
|
||||
UserStatus
|
||||
==========
|
||||
|
||||
.. autoclass:: pyrogram.enums.UserStatus()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
9
docs/source/api/enums/cleanup.html
Normal file
9
docs/source/api/enums/cleanup.html
Normal file
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
document
|
||||
.querySelectorAll("em.property")
|
||||
.forEach((elem, i) => i !== 0 ? elem.remove() : true)
|
||||
|
||||
document
|
||||
.querySelectorAll("a.headerlink")
|
||||
.forEach((elem, i) => [0, 1].includes(i) ? true : elem.remove())
|
||||
</script>
|
45
docs/source/api/enums/index.rst
Normal file
45
docs/source/api/enums/index.rst
Normal file
@ -0,0 +1,45 @@
|
||||
Enumerations
|
||||
============
|
||||
|
||||
This page is about Pyrogram enumerations.
|
||||
Enumerations are types that hold a group of related values to be used whenever a constant value is required.
|
||||
They will help you deal with those values in a type-safe way and also enable code completion so that you can be sure
|
||||
to apply only a valid value among the expected ones.
|
||||
|
||||
-----
|
||||
|
||||
.. currentmodule:: pyrogram.enums
|
||||
|
||||
.. autosummary::
|
||||
:nosignatures:
|
||||
|
||||
ChatAction
|
||||
ChatEventAction
|
||||
ChatMemberStatus
|
||||
ChatMembersFilter
|
||||
ChatType
|
||||
MessageEntityType
|
||||
MessageMedia
|
||||
MessageService
|
||||
MessagesFilter
|
||||
ParseMode
|
||||
PollType
|
||||
SentCodeType
|
||||
UserStatus
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
ChatAction
|
||||
ChatEventAction
|
||||
ChatMemberStatus
|
||||
ChatMembersFilter
|
||||
ChatType
|
||||
MessageEntityType
|
||||
MessageMedia
|
||||
MessageService
|
||||
MessagesFilter
|
||||
ParseMode
|
||||
PollType
|
||||
SentCodeType
|
||||
UserStatus
|
@ -92,6 +92,7 @@ API Reference
|
||||
- :doc:`Pyrogram Client <api/client>`: Reference details about the Client class.
|
||||
- :doc:`Available Methods <api/methods/index>`: List of available high-level methods.
|
||||
- :doc:`Available Types <api/types/index>`: List of available high-level types.
|
||||
- :doc:`Enumerations <api/enums/index>`: List of available enumerations.
|
||||
- :doc:`Bound Methods <api/bound-methods/index>`: List of convenient bound methods.
|
||||
|
||||
Meta
|
||||
@ -130,6 +131,7 @@ Meta
|
||||
api/methods/index
|
||||
api/types/index
|
||||
api/bound-methods/index
|
||||
api/enums/index
|
||||
api/handlers
|
||||
api/decorators
|
||||
api/errors/index
|
||||
|
@ -37,7 +37,7 @@ class ContinuePropagation(StopAsyncIteration):
|
||||
|
||||
import asyncio
|
||||
|
||||
from . import raw, types, filters, handlers, emoji
|
||||
from . import raw, types, filters, handlers, emoji, enums
|
||||
from .client import Client
|
||||
from .sync import idle
|
||||
|
||||
|
@ -33,6 +33,7 @@ from typing import Union, List, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import __version__, __license__
|
||||
from pyrogram import enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import utils
|
||||
from pyrogram.crypto import aes
|
||||
@ -146,7 +147,7 @@ class Client(Methods, Scaffold):
|
||||
Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*.
|
||||
This is an alternative way to setup plugins if you don't want to use the *config.ini* file.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
The parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
|
||||
to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser
|
||||
completely.
|
||||
@ -197,7 +198,7 @@ class Client(Methods, Scaffold):
|
||||
workdir: str = Scaffold.WORKDIR,
|
||||
config_file: str = Scaffold.CONFIG_FILE,
|
||||
plugins: dict = None,
|
||||
parse_mode: str = Scaffold.PARSE_MODES[0],
|
||||
parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
|
||||
no_updates: bool = None,
|
||||
takeout: bool = None,
|
||||
sleep_threshold: int = Session.SLEEP_THRESHOLD,
|
||||
@ -394,44 +395,21 @@ class Client(Methods, Scaffold):
|
||||
|
||||
return signed_up
|
||||
|
||||
@property
|
||||
def parse_mode(self):
|
||||
return self._parse_mode
|
||||
|
||||
@parse_mode.setter
|
||||
def parse_mode(self, parse_mode: Optional[str] = "combined"):
|
||||
if isinstance(parse_mode, str):
|
||||
parse_mode = parse_mode.lower()
|
||||
|
||||
if parse_mode not in self.PARSE_MODES:
|
||||
raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
|
||||
", ".join(f'"{m}"' for m in self.PARSE_MODES[:-1]),
|
||||
parse_mode
|
||||
))
|
||||
|
||||
self._parse_mode = parse_mode
|
||||
|
||||
# TODO: redundant, remove in next major version
|
||||
def set_parse_mode(self, parse_mode: Optional[str] = "combined"):
|
||||
def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]):
|
||||
"""Set the parse mode to be used globally by the client.
|
||||
|
||||
When setting the parse mode with this method, all other methods having a *parse_mode* parameter will follow the
|
||||
global value by default. The default value *"combined"* enables both Markdown and HTML styles to be used and
|
||||
combined together.
|
||||
global value by default.
|
||||
|
||||
Parameters:
|
||||
parse_mode (``str``):
|
||||
The new parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
|
||||
to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser
|
||||
completely.
|
||||
|
||||
Raises:
|
||||
ValueError: In case the provided *parse_mode* is not a valid parse mode.
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import Client
|
||||
from pyrogram import Client, enums
|
||||
|
||||
app = Client("my_account")
|
||||
|
||||
@ -440,19 +418,19 @@ class Client(Methods, Scaffold):
|
||||
app.send_message("me", "1. **markdown** and <i>html</i>")
|
||||
|
||||
# Force Markdown-only, HTML is disabled
|
||||
app.set_parse_mode("markdown")
|
||||
app.set_parse_mode(enums.ParseMode.MARKDOWN)
|
||||
app.send_message("me", "2. **markdown** and <i>html</i>")
|
||||
|
||||
# Force HTML-only, Markdown is disabled
|
||||
app.set_parse_mode("html")
|
||||
app.set_parse_mode(enums.ParseMode.HTML)
|
||||
app.send_message("me", "3. **markdown** and <i>html</i>")
|
||||
|
||||
# Disable the parser completely
|
||||
app.set_parse_mode(None)
|
||||
app.set_parse_mode(enums.ParseMode.DISABLED)
|
||||
app.send_message("me", "4. **markdown** and <i>html</i>")
|
||||
|
||||
# Bring back the default combined mode
|
||||
app.set_parse_mode()
|
||||
app.set_parse_mode(enums.ParseMode.DEFAULT)
|
||||
app.send_message("me", "5. **markdown** and <i>html</i>")
|
||||
"""
|
||||
|
||||
|
31
pyrogram/enums/__init__.py
Normal file
31
pyrogram/enums/__init__.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .chat_action import ChatAction
|
||||
from .chat_event_action import ChatEventAction
|
||||
from .chat_member_status import ChatMemberStatus
|
||||
from .chat_members_filter import ChatMembersFilter
|
||||
from .chat_type import ChatType
|
||||
from .message_entity_type import MessageEntityType
|
||||
from .message_media import MessageMedia
|
||||
from .message_service import MessageService
|
||||
from .messages_filter import MessagesFilter
|
||||
from .parse_mode import ParseMode
|
||||
from .poll_type import PollType
|
||||
from .sent_code_type import SentCodeType
|
||||
from .user_status import UserStatus
|
24
pyrogram/enums/auto_name.py
Normal file
24
pyrogram/enums/auto_name.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class AutoName(Enum):
|
||||
def _generate_next_value_(self, *args):
|
||||
return self.lower()
|
72
pyrogram/enums/chat_action.py
Normal file
72
pyrogram/enums/chat_action.py
Normal file
@ -0,0 +1,72 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ChatAction(AutoName):
|
||||
"""Chat action enumeration used in :obj:`~pyrogram.types.ChatEvent`."""
|
||||
|
||||
TYPING = raw.types.SendMessageTypingAction
|
||||
"Typing text message"
|
||||
|
||||
UPLOAD_PHOTO = raw.types.SendMessageUploadPhotoAction
|
||||
"Uploading photo"
|
||||
|
||||
RECORD_VIDEO = raw.types.SendMessageRecordVideoAction
|
||||
"Recording video"
|
||||
|
||||
UPLOAD_VIDEO = raw.types.SendMessageUploadVideoAction
|
||||
"Uploading video"
|
||||
|
||||
RECORD_AUDIO = raw.types.SendMessageRecordAudioAction
|
||||
"Recording audio"
|
||||
|
||||
UPLOAD_AUDIO = raw.types.SendMessageUploadAudioAction
|
||||
"Uploading audio"
|
||||
|
||||
UPLOAD_DOCUMENT = raw.types.SendMessageUploadDocumentAction
|
||||
"Uploading document"
|
||||
|
||||
FIND_LOCATION = raw.types.SendMessageGeoLocationAction
|
||||
"Finding location"
|
||||
|
||||
RECORD_VIDEO_NOTE = raw.types.SendMessageRecordRoundAction
|
||||
"Recording video note"
|
||||
|
||||
UPLOAD_VIDEO_NOTE = raw.types.SendMessageUploadRoundAction
|
||||
"Uploading video note"
|
||||
|
||||
PLAYING = raw.types.SendMessageGamePlayAction
|
||||
"Playing game"
|
||||
|
||||
CHOOSE_CONTACT = raw.types.SendMessageChooseContactAction
|
||||
"Choosing contact"
|
||||
|
||||
SPEAKING = raw.types.SpeakingInGroupCallAction
|
||||
"Speaking in group call"
|
||||
|
||||
IMPORT_HISTORY = raw.types.SendMessageHistoryImportAction
|
||||
"Importing history"
|
||||
|
||||
CHOOSE_STICKER = raw.types.SendMessageChooseStickerAction
|
||||
"Choosing sticker"
|
||||
|
||||
CANCEL = raw.types.SendMessageCancelAction
|
||||
"Cancel ongoing chat action"
|
127
pyrogram/enums/chat_event_action.py
Normal file
127
pyrogram/enums/chat_event_action.py
Normal file
@ -0,0 +1,127 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ChatEventAction(AutoName):
|
||||
"""Chat event action enumeration used in :meth:`~pyrogram.Client.get_chat_event_log`."""
|
||||
|
||||
DESCRIPTION_CHANGED = auto()
|
||||
"The chat description has been changed (see ``old_description`` and ``new_description``)"
|
||||
|
||||
HISTORY_TTL_CHANGED = auto()
|
||||
"The history time-to-live has been changed (see ``old_history_ttl`` and ``new_history_ttl``)"
|
||||
|
||||
LINKED_CHAT_CHANGED = auto()
|
||||
"The linked chat has been changed (see ``old_linked_chat`` and ``new_linked_chat``)"
|
||||
|
||||
# LOCATION_CHANGED = auto()
|
||||
""
|
||||
|
||||
PHOTO_CHANGED = auto()
|
||||
"The chat photo has been changed (see ``old_photo`` and ``new_photo``)"
|
||||
|
||||
# STICKER_SET_CHANGED = auto()
|
||||
""
|
||||
|
||||
TITLE_CHANGED = auto()
|
||||
"the chat title has been changed (see ``old_title`` and ``new_title``)"
|
||||
|
||||
USERNAME_CHANGED = auto()
|
||||
"the chat username has been changed (see ``old_username`` and ``new_username``)"
|
||||
|
||||
CHAT_PERMISSIONS_CHANGED = auto()
|
||||
"the default chat permissions has been changed (see ``old_chat_permissions`` and ``new_chat_permissions``)"
|
||||
|
||||
MESSAGE_DELETED = auto()
|
||||
"a message has been deleted (see ``deleted_message``)"
|
||||
|
||||
# VOICE_CHAT_DISCARDED = auto()
|
||||
""
|
||||
|
||||
MESSAGE_EDITED = auto()
|
||||
"a message has been edited (see ``old_message`` and ``new_message``)"
|
||||
|
||||
INVITE_LINK_EDITED = auto()
|
||||
"An invite link has been edited (see ``old_invite_link`` and ``new_invite`` link)"
|
||||
|
||||
INVITE_LINK_REVOKED = auto()
|
||||
"An invite link has been revoked (see ``revoked_invite_link``)"
|
||||
|
||||
INVITE_LINK_DELETED = auto()
|
||||
"An invite link has been deleted (see ``deleted_invite_link``)"
|
||||
|
||||
MEMBER_INVITED = auto()
|
||||
"a member has been invited by someone (see ``invited_member``)"
|
||||
|
||||
MEMBER_JOINED = auto()
|
||||
"a member joined by themselves. (see ``user``)"
|
||||
|
||||
# MEMBER_JOINED_BY_LINK = auto()
|
||||
""
|
||||
|
||||
MEMBER_LEFT = auto()
|
||||
"a member left by themselves. (see ``user``)"
|
||||
|
||||
# MEMBER_MUTED = auto()
|
||||
""
|
||||
|
||||
ADMINISTRATOR_PRIVILEGES_CHANGED = auto()
|
||||
"a chat member has been promoted/demoted or their administrator privileges has changed (see ``old_administrator_privileges`` and ``new_administrator_privileges``)"
|
||||
|
||||
MEMBER_PERMISSIONS_CHANGED = auto()
|
||||
"a chat member has been restricted/unrestricted or banned/unbanned, or their permissions has changed (see ``old_member_permissions`` and ``new_member_permissions``)"
|
||||
|
||||
# MEMBER_UNMUTED = auto()
|
||||
""
|
||||
|
||||
# MEMBER_VOLUME_CHANGED = auto()
|
||||
""
|
||||
|
||||
# VOICE_CHAT_STARTED = auto()
|
||||
""
|
||||
|
||||
POLL_STOPPED = auto()
|
||||
"a poll has been stopped (see ``stopped_poll``)"
|
||||
|
||||
# VOICE_CHAT_SETTINGS_CHANGED = auto()
|
||||
""
|
||||
|
||||
INVITES_ENABLED = auto()
|
||||
"the chat invitation has been enabled or disabled (see ``invites_enabled``)"
|
||||
|
||||
HISTORY_HIDDEN = auto()
|
||||
"the chat history has been hidden or unhidden (see ``history_hidden``)"
|
||||
|
||||
SIGNATURES_ENABLED = auto()
|
||||
"the message signatures have been enabled or disabled (see ``signatures_enabled``)"
|
||||
|
||||
SLOW_MODE_CHANGED = auto()
|
||||
"the slow mode has been changes (see ``old_slow_mode`` and ``new_slow_mode``)"
|
||||
|
||||
MESSAGE_PINNED = auto()
|
||||
"a message has been pinned (see ``pinned_message``)"
|
||||
|
||||
MESSAGE_UNPINNED = auto()
|
||||
"a message has been unpinned (see ``unpinned_message``)"
|
||||
|
||||
UNKNOWN = auto()
|
||||
"Unknown chat event action"
|
43
pyrogram/enums/chat_member_status.py
Normal file
43
pyrogram/enums/chat_member_status.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ChatMemberStatus(AutoName):
|
||||
"""Chat member status enumeration used in :obj:`~pyrogram.types.ChatMember`."""
|
||||
|
||||
OWNER = auto()
|
||||
"Chat owner"
|
||||
|
||||
ADMINISTRATOR = auto()
|
||||
"Chat administrator"
|
||||
|
||||
MEMBER = auto()
|
||||
"Chat member"
|
||||
|
||||
RESTRICTED = auto()
|
||||
"Restricted chat member"
|
||||
|
||||
LEFT = auto()
|
||||
"Left chat member"
|
||||
|
||||
BANNED = auto()
|
||||
"Banned chat member"
|
42
pyrogram/enums/chat_members_filter.py
Normal file
42
pyrogram/enums/chat_members_filter.py
Normal file
@ -0,0 +1,42 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ChatMembersFilter(AutoName):
|
||||
"""Chat members filter enumeration used in :meth:`~pyrogram.Client.get_chat_members`"""
|
||||
|
||||
ANY = raw.types.ChannelParticipantsSearch
|
||||
"Any kind of member"
|
||||
|
||||
BANNED = raw.types.ChannelParticipantsKicked
|
||||
"Banned members"
|
||||
|
||||
RESTRICTED = raw.types.ChannelParticipantsBanned
|
||||
"Restricted members"
|
||||
|
||||
BOTS = raw.types.ChannelParticipantsBots
|
||||
"Bots"
|
||||
|
||||
RECENT = raw.types.ChannelParticipantsRecent
|
||||
"Recently active members"
|
||||
|
||||
ADMINISTRATORS = raw.types.ChannelParticipantsAdmins
|
||||
"Administrators"
|
40
pyrogram/enums/chat_type.py
Normal file
40
pyrogram/enums/chat_type.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ChatType(AutoName):
|
||||
"""Chat type enumeration used in :obj:`~pyrogram.types.Chat`."""
|
||||
|
||||
PRIVATE = auto()
|
||||
"Chat is a private chat with a user"
|
||||
|
||||
BOT = auto()
|
||||
"Chat is a private chat with a bot"
|
||||
|
||||
GROUP = auto()
|
||||
"Chat is a basic group"
|
||||
|
||||
SUPERGROUP = auto()
|
||||
"Chat is a supergroup"
|
||||
|
||||
CHANNEL = auto()
|
||||
"Chat is a channel"
|
81
pyrogram/enums/message_entity_type.py
Normal file
81
pyrogram/enums/message_entity_type.py
Normal file
@ -0,0 +1,81 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class MessageEntityType(AutoName):
|
||||
"""Message entity type enumeration used in :obj:`~pyrogram.types.MessageEntity`."""
|
||||
|
||||
MENTION = raw.types.MessageEntityMention
|
||||
"``@username``"
|
||||
|
||||
HASHTAG = raw.types.MessageEntityHashtag
|
||||
"``#hashtag``"
|
||||
|
||||
CASHTAG = raw.types.MessageEntityCashtag
|
||||
"``$USD``"
|
||||
|
||||
BOT_COMMAND = raw.types.MessageEntityBotCommand
|
||||
"``/start@pyrogrambot``"
|
||||
|
||||
URL = raw.types.MessageEntityUrl
|
||||
"``https://pyrogram.org`` (see ``url``)"
|
||||
|
||||
EMAIL = raw.types.MessageEntityEmail
|
||||
"``do-not-reply@pyrogram.org``"
|
||||
|
||||
PHONE_NUMBER = raw.types.MessageEntityPhone
|
||||
"``+1-123-456-7890``"
|
||||
|
||||
BOLD = raw.types.MessageEntityBold
|
||||
"Bold text"
|
||||
|
||||
ITALIC = raw.types.MessageEntityItalic
|
||||
"Italic text"
|
||||
|
||||
UNDERLINE = raw.types.MessageEntityUnderline
|
||||
"Underlined text"
|
||||
|
||||
STRIKETHROUGH = raw.types.MessageEntityStrike
|
||||
"Strikethrough text"
|
||||
|
||||
SPOILER = raw.types.MessageEntitySpoiler
|
||||
"Spoiler text"
|
||||
|
||||
CODE = raw.types.MessageEntityCode
|
||||
"Monowidth string"
|
||||
|
||||
PRE = raw.types.MessageEntityPre
|
||||
"Monowidth block (see ``language``)"
|
||||
|
||||
BLOCKQUOTE = raw.types.MessageEntityBlockquote
|
||||
"Blockquote text"
|
||||
|
||||
TEXT_LINK = raw.types.MessageEntityTextUrl
|
||||
"For clickable text URLs"
|
||||
|
||||
TEXT_MENTION = raw.types.MessageEntityMentionName
|
||||
"for users without usernames (see ``user``)"
|
||||
|
||||
BANK_CARD = raw.types.MessageEntityBankCard
|
||||
"Bank card text"
|
||||
|
||||
UNKNOWN = raw.types.MessageEntityUnknown
|
||||
"Unknown message entity type"
|
70
pyrogram/enums/message_media.py
Normal file
70
pyrogram/enums/message_media.py
Normal file
@ -0,0 +1,70 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class MessageMedia(AutoName):
|
||||
"""Message media enumeration used in :obj:`~pyrogram.types.Message`."""
|
||||
|
||||
AUDIO = auto()
|
||||
"Audio media"
|
||||
|
||||
DOCUMENT = auto()
|
||||
"Document media"
|
||||
|
||||
PHOTO = auto()
|
||||
"Photo media"
|
||||
|
||||
STICKER = auto()
|
||||
"Sticker media"
|
||||
|
||||
VIDEO = auto()
|
||||
"Video media"
|
||||
|
||||
ANIMATION = auto()
|
||||
"Animation media"
|
||||
|
||||
VOICE = auto()
|
||||
"Voice media"
|
||||
|
||||
VIDEO_NOTE = auto()
|
||||
"Video note media"
|
||||
|
||||
CONTACT = auto()
|
||||
"Contact media"
|
||||
|
||||
LOCATION = auto()
|
||||
"Location media"
|
||||
|
||||
VENUE = auto()
|
||||
"Venue media"
|
||||
|
||||
POLL = auto()
|
||||
"Poll media"
|
||||
|
||||
WEB_PAGE = auto()
|
||||
"Web page media"
|
||||
|
||||
DICE = auto()
|
||||
"Dice media"
|
||||
|
||||
GAME = auto()
|
||||
"Game media"
|
70
pyrogram/enums/message_service.py
Normal file
70
pyrogram/enums/message_service.py
Normal file
@ -0,0 +1,70 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class MessageService(AutoName):
|
||||
"""Message service enumeration used in :obj:`~pyrogram.types.Message`."""
|
||||
|
||||
NEW_CHAT_MEMBERS = auto()
|
||||
"New members join"
|
||||
|
||||
LEFT_CHAT_MEMBERS = auto()
|
||||
"Left chat members"
|
||||
|
||||
NEW_CHAT_TITLE = auto()
|
||||
"New chat title"
|
||||
|
||||
NEW_CHAT_PHOTO = auto()
|
||||
"New chat photo"
|
||||
|
||||
DELETE_CHAT_PHOTO = auto()
|
||||
"Deleted chat photo"
|
||||
|
||||
GROUP_CHAT_CREATED = auto()
|
||||
"Group chat created"
|
||||
|
||||
CHANNEL_CHAT_CREATED = auto()
|
||||
"Channel chat created"
|
||||
|
||||
MIGRATE_TO_CHAT_ID = auto()
|
||||
"Migrated to chat id"
|
||||
|
||||
MIGRATE_FROM_CHAT_ID = auto()
|
||||
"Migrated from chat id"
|
||||
|
||||
PINNED_MESSAGE = auto()
|
||||
"Pinned message"
|
||||
|
||||
GAME_HIGH_SCORE = auto()
|
||||
"Game high score"
|
||||
|
||||
VOICE_CHAT_STARTED = auto()
|
||||
"Voice chat started"
|
||||
|
||||
VOICE_CHAT_ENDED = auto()
|
||||
"Voice chat ended"
|
||||
|
||||
VOICE_CHAT_SCHEDULED = auto()
|
||||
"Voice chat scheduled"
|
||||
|
||||
VOICE_CHAT_MEMBERS_INVITED = auto()
|
||||
"Voice chat members invited"
|
75
pyrogram/enums/messages_filter.py
Normal file
75
pyrogram/enums/messages_filter.py
Normal file
@ -0,0 +1,75 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class MessagesFilter(AutoName):
|
||||
"""Messages filter enumeration used in used in :meth:`~pyrogram.Client.search_messages` and used in :meth:`~pyrogram.Client.search_global`"""
|
||||
|
||||
ANY = raw.types.InputMessagesFilterEmpty
|
||||
"Any kind of message"
|
||||
|
||||
PHOTO = raw.types.InputMessagesFilterPhotos
|
||||
"Photo messages"
|
||||
|
||||
VIDEO = raw.types.InputMessagesFilterVideo
|
||||
"Video messages"
|
||||
|
||||
PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo
|
||||
"Photo and video messages"
|
||||
|
||||
DOCUMENT = raw.types.InputMessagesFilterDocument
|
||||
"Document messages"
|
||||
|
||||
URL = raw.types.InputMessagesFilterUrl
|
||||
"Messages containing URLs"
|
||||
|
||||
ANIMATION = raw.types.InputMessagesFilterGif
|
||||
"Animation messages"
|
||||
|
||||
VOICE_NOTE = raw.types.InputMessagesFilterVoice
|
||||
"Voice note messages"
|
||||
|
||||
VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo
|
||||
"Video note messages"
|
||||
|
||||
AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo
|
||||
"Audio and video note messages"
|
||||
|
||||
AUDIO = raw.types.InputMessagesFilterMusic
|
||||
"Audio messages (music)"
|
||||
|
||||
CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos
|
||||
"Chat photo messages"
|
||||
|
||||
PHONE_CALL = raw.types.InputMessagesFilterPhoneCalls
|
||||
"Phone call messages"
|
||||
|
||||
MENTION = raw.types.InputMessagesFilterMyMentions
|
||||
"Messages containing mentions"
|
||||
|
||||
LOCATION = raw.types.InputMessagesFilterGeo
|
||||
"Location messages"
|
||||
|
||||
CONTACT = raw.types.InputMessagesFilterContacts
|
||||
"Contact messages"
|
||||
|
||||
PINNED = raw.types.InputMessagesFilterPinned
|
||||
"Pinned messages"
|
37
pyrogram/enums/parse_mode.py
Normal file
37
pyrogram/enums/parse_mode.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ParseMode(AutoName):
|
||||
"""Parse mode enumeration used in various places to set a specific parse mode"""
|
||||
|
||||
DEFAULT = auto()
|
||||
"Default mode. Markdown and HTML combined"
|
||||
|
||||
MARKDOWN = auto()
|
||||
"Markdown only mode"
|
||||
|
||||
HTML = auto()
|
||||
"HTML only mode"
|
||||
|
||||
DISABLED = auto()
|
||||
"Disabled mode"
|
31
pyrogram/enums/poll_type.py
Normal file
31
pyrogram/enums/poll_type.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class PollType(AutoName):
|
||||
"""Poll type enumeration used in :obj:`~pyrogram.types.Poll`."""
|
||||
|
||||
QUIZ = auto()
|
||||
"Quiz poll"
|
||||
|
||||
REGULAR = auto()
|
||||
"Regular poll"
|
39
pyrogram/enums/sent_code_type.py
Normal file
39
pyrogram/enums/sent_code_type.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class SentCodeType(AutoName):
|
||||
"""Sent code type enumeration used in :obj:`~pyrogram.types.SentCode`."""
|
||||
|
||||
APP = raw.types.auth.SentCodeTypeApp
|
||||
"The code was sent through the telegram app."
|
||||
|
||||
CALL = raw.types.auth.SentCodeTypeCall
|
||||
"The code will be sent via a phone call. A synthesized voice will tell the user which verification code to input."
|
||||
|
||||
FLASH_CALL = raw.types.auth.SentCodeTypeFlashCall
|
||||
"The code will be sent via a flash phone call, that will be closed immediately."
|
||||
|
||||
MISSED_CALL = raw.types.auth.SentCodeTypeMissedCall
|
||||
"Missed call"
|
||||
|
||||
SMS = raw.types.auth.SentCodeTypeSms
|
||||
"The code was sent via SMS."
|
43
pyrogram/enums/user_status.py
Normal file
43
pyrogram/enums/user_status.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class UserStatus(AutoName):
|
||||
"""User status enumeration used in :obj:`~pyrogram.types.User`."""
|
||||
|
||||
ONLINE = auto()
|
||||
"""User is online"""
|
||||
|
||||
OFFLINE = auto()
|
||||
"""User is offline"""
|
||||
|
||||
RECENTLY = auto()
|
||||
"""User was seen recently"""
|
||||
|
||||
LAST_WEEK = auto()
|
||||
"""User was seen last week"""
|
||||
|
||||
LAST_MONTH = auto()
|
||||
"""User was seen last month"""
|
||||
|
||||
LONG_AGO = auto()
|
||||
"""User was seen long ago"""
|
@ -21,6 +21,7 @@ import re
|
||||
from typing import Callable, Union, List, Pattern
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import enums
|
||||
from pyrogram.types import Message, CallbackQuery, InlineQuery, InlineKeyboardMarkup, ReplyKeyboardMarkup, Update
|
||||
|
||||
|
||||
@ -438,7 +439,7 @@ dice = create(dice_filter)
|
||||
|
||||
# region private_filter
|
||||
async def private_filter(_, __, m: Message):
|
||||
return bool(m.chat and m.chat.type in {"private", "bot"})
|
||||
return bool(m.chat and m.chat.type in {enums.ChatType.PRIVATE, enums.ChatType.BOT})
|
||||
|
||||
|
||||
private = create(private_filter)
|
||||
@ -449,7 +450,7 @@ private = create(private_filter)
|
||||
|
||||
# region group_filter
|
||||
async def group_filter(_, __, m: Message):
|
||||
return bool(m.chat and m.chat.type in {"group", "supergroup"})
|
||||
return bool(m.chat and m.chat.type in {enums.ChatType.GROUP, enums.ChatType.SUPERGROUP})
|
||||
|
||||
|
||||
group = create(group_filter)
|
||||
@ -460,7 +461,7 @@ group = create(group_filter)
|
||||
|
||||
# region channel_filter
|
||||
async def channel_filter(_, __, m: Message):
|
||||
return bool(m.chat and m.chat.type == "channel")
|
||||
return bool(m.chat and m.chat.type == enums.ChatType.CHANNEL)
|
||||
|
||||
|
||||
channel = create(channel_filter)
|
||||
|
@ -19,22 +19,12 @@
|
||||
import logging
|
||||
from typing import Union, List
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import raw, types, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Filters:
|
||||
ALL = "all"
|
||||
BANNED = "banned"
|
||||
RESTRICTED = "restricted"
|
||||
BOTS = "bots"
|
||||
RECENT = "recent"
|
||||
ADMINISTRATORS = "administrators"
|
||||
|
||||
|
||||
class GetChatMembers(Scaffold):
|
||||
async def get_chat_members(
|
||||
self,
|
||||
@ -42,7 +32,7 @@ class GetChatMembers(Scaffold):
|
||||
offset: int = 0,
|
||||
limit: int = 200,
|
||||
query: str = "",
|
||||
filter: str = Filters.RECENT
|
||||
filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
|
||||
) -> List["types.ChatMember"]:
|
||||
"""Get a chunk of the members list of a chat.
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
import logging
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from pyrogram import types
|
||||
from pyrogram import types, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -32,7 +32,7 @@ class CopyMessage(Scaffold):
|
||||
from_chat_id: Union[int, str],
|
||||
message_id: int,
|
||||
caption: str = None,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
@ -69,12 +69,9 @@ class CopyMessage(Scaffold):
|
||||
If not specified, the original caption is kept.
|
||||
Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the new caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pyrogram import types
|
||||
from pyrogram import types, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ class EditInlineCaption(Scaffold):
|
||||
self,
|
||||
inline_message_id: str,
|
||||
caption: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> bool:
|
||||
"""Edit the caption of inline media messages.
|
||||
@ -39,12 +39,9 @@ class EditInlineCaption(Scaffold):
|
||||
caption (``str``):
|
||||
New caption of the media message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||
An InlineKeyboardMarkup object.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.scaffold import Scaffold
|
||||
@ -30,7 +30,7 @@ class EditInlineText(Scaffold):
|
||||
self,
|
||||
inline_message_id: str,
|
||||
text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> bool:
|
||||
@ -43,12 +43,9 @@ class EditInlineText(Scaffold):
|
||||
text (``str``):
|
||||
New text of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
disable_web_page_preview (``bool``, *optional*):
|
||||
Disables link previews for links in this message.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from pyrogram import types
|
||||
from pyrogram import types, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ class EditMessageCaption(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
message_id: int,
|
||||
caption: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> "types.Message":
|
||||
@ -46,12 +46,9 @@ class EditMessageCaption(Scaffold):
|
||||
caption (``str``):
|
||||
New caption of the media message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.scaffold import Scaffold
|
||||
@ -30,7 +30,7 @@ class EditMessageText(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
message_id: int,
|
||||
text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
entities: List["types.MessageEntity"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
@ -49,12 +49,9 @@ class EditMessageText(Scaffold):
|
||||
text (``str``):
|
||||
New text of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
|
||||
|
@ -18,37 +18,17 @@
|
||||
|
||||
from typing import AsyncGenerator, Optional
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
class Filters:
|
||||
EMPTY = raw.types.InputMessagesFilterEmpty()
|
||||
PHOTO = raw.types.InputMessagesFilterPhotos()
|
||||
VIDEO = raw.types.InputMessagesFilterVideo()
|
||||
PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo()
|
||||
DOCUMENT = raw.types.InputMessagesFilterDocument()
|
||||
URL = raw.types.InputMessagesFilterUrl()
|
||||
ANIMATION = raw.types.InputMessagesFilterGif()
|
||||
VOICE_NOTE = raw.types.InputMessagesFilterVoice()
|
||||
AUDIO = raw.types.InputMessagesFilterMusic()
|
||||
CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos()
|
||||
AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
|
||||
VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
|
||||
LOCATION = raw.types.InputMessagesFilterGeo()
|
||||
CONTACT = raw.types.InputMessagesFilterContacts()
|
||||
|
||||
|
||||
POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), Filters.__dict__.keys())))
|
||||
|
||||
|
||||
class SearchGlobal(Scaffold):
|
||||
async def search_global(
|
||||
self,
|
||||
query: str = "",
|
||||
filter: str = "empty",
|
||||
filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
|
||||
limit: int = 0,
|
||||
) -> Optional[AsyncGenerator["types.Message", None]]:
|
||||
"""Search messages globally from all of your chats.
|
||||
@ -65,23 +45,9 @@ class SearchGlobal(Scaffold):
|
||||
Text query string.
|
||||
Use "@" to search for mentions.
|
||||
|
||||
filter (``str``, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only:
|
||||
|
||||
- ``"empty"``: Search for all kind of messages (default).
|
||||
- ``"photo"``: Search for photos.
|
||||
- ``"video"``: Search for video.
|
||||
- ``"photo_video"``: Search for either photo or video.
|
||||
- ``"document"``: Search for documents (generic files).
|
||||
- ``"url"``: Search for messages containing URLs (web links).
|
||||
- ``"animation"``: Search for animations (GIFs).
|
||||
- ``"voice_note"``: Search for voice notes.
|
||||
- ``"audio"``: Search for audio files (music).
|
||||
- ``"chat_photo"``: Search for chat photos.
|
||||
- ``"audio_video_note"``: Search for either audio or video notes.
|
||||
- ``"video_note"``: Search for video notes.
|
||||
- ``"location"``: Search for location messages.
|
||||
- ``"contact"``: Search for contact messages.
|
||||
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only.
|
||||
Defaults to any message (no filter).
|
||||
|
||||
limit (``int``, *optional*):
|
||||
Limits the number of messages to be retrieved.
|
||||
@ -101,11 +67,6 @@ class SearchGlobal(Scaffold):
|
||||
for message in app.search_global(filter="photo", limit=20):
|
||||
print(message.photo)
|
||||
"""
|
||||
try:
|
||||
filter = Filters.__dict__[filter.upper()]
|
||||
except KeyError:
|
||||
raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
|
||||
filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
|
||||
current = 0
|
||||
# There seems to be an hard limit of 10k, beyond which Telegram starts spitting one message at a time.
|
||||
total = abs(limit) or (1 << 31)
|
||||
@ -121,7 +82,7 @@ class SearchGlobal(Scaffold):
|
||||
await self.send(
|
||||
raw.functions.messages.SearchGlobal(
|
||||
q=query,
|
||||
filter=filter,
|
||||
filter=filter.value(),
|
||||
min_date=0,
|
||||
max_date=0,
|
||||
offset_rate=offset_date,
|
||||
|
@ -16,16 +16,15 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
from .search_messages import Filters, POSSIBLE_VALUES
|
||||
|
||||
|
||||
class SearchGlobalCount(Scaffold):
|
||||
async def search_global_count(
|
||||
self,
|
||||
query: str = "",
|
||||
filter: str = "empty",
|
||||
filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
|
||||
) -> int:
|
||||
"""Get the count of messages resulting from a global search.
|
||||
|
||||
@ -36,37 +35,16 @@ class SearchGlobalCount(Scaffold):
|
||||
Text query string.
|
||||
Use "@" to search for mentions.
|
||||
|
||||
filter (``str``, *optional*):
|
||||
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only:
|
||||
|
||||
- ``"empty"``: Search for all kind of messages (default).
|
||||
- ``"photo"``: Search for photos.
|
||||
- ``"video"``: Search for video.
|
||||
- ``"photo_video"``: Search for either photo or video.
|
||||
- ``"document"``: Search for documents (generic files).
|
||||
- ``"url"``: Search for messages containing URLs (web links).
|
||||
- ``"animation"``: Search for animations (GIFs).
|
||||
- ``"voice_note"``: Search for voice notes.
|
||||
- ``"audio"``: Search for audio files (music).
|
||||
- ``"chat_photo"``: Search for chat photos.
|
||||
- ``"audio_video_note"``: Search for either audio or video notes.
|
||||
- ``"video_note"``: Search for video notes.
|
||||
- ``"location"``: Search for location messages.
|
||||
- ``"contact"``: Search for contact messages.
|
||||
|
||||
Returns:
|
||||
``int``: On success, the messages count is returned.
|
||||
"""
|
||||
try:
|
||||
filter = Filters.__dict__[filter.upper()]
|
||||
except KeyError:
|
||||
raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
|
||||
filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
|
||||
|
||||
r = await self.send(
|
||||
raw.functions.messages.SearchGlobal(
|
||||
q=query,
|
||||
filter=filter,
|
||||
filter=filter.value(),
|
||||
min_date=0,
|
||||
max_date=0,
|
||||
offset_rate=0,
|
||||
|
@ -18,56 +18,25 @@
|
||||
|
||||
from typing import Union, List, AsyncGenerator, Optional
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
class Filters:
|
||||
EMPTY = raw.types.InputMessagesFilterEmpty()
|
||||
PHOTO = raw.types.InputMessagesFilterPhotos()
|
||||
VIDEO = raw.types.InputMessagesFilterVideo()
|
||||
PHOTO_VIDEO = raw.types.InputMessagesFilterPhotoVideo()
|
||||
DOCUMENT = raw.types.InputMessagesFilterDocument()
|
||||
URL = raw.types.InputMessagesFilterUrl()
|
||||
ANIMATION = raw.types.InputMessagesFilterGif()
|
||||
VOICE_NOTE = raw.types.InputMessagesFilterVoice()
|
||||
AUDIO = raw.types.InputMessagesFilterMusic()
|
||||
CHAT_PHOTO = raw.types.InputMessagesFilterChatPhotos()
|
||||
PHONE_CALL = raw.types.InputMessagesFilterPhoneCalls()
|
||||
AUDIO_VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
|
||||
VIDEO_NOTE = raw.types.InputMessagesFilterRoundVideo()
|
||||
MENTION = raw.types.InputMessagesFilterMyMentions()
|
||||
LOCATION = raw.types.InputMessagesFilterGeo()
|
||||
CONTACT = raw.types.InputMessagesFilterContacts()
|
||||
PINNED = raw.types.InputMessagesFilterPinned()
|
||||
|
||||
|
||||
POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), Filters.__dict__.keys())))
|
||||
|
||||
|
||||
# noinspection PyShadowingBuiltins
|
||||
async def get_chunk(
|
||||
client: Scaffold,
|
||||
chat_id: Union[int, str],
|
||||
query: str = "",
|
||||
filter: str = "empty",
|
||||
filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
|
||||
offset: int = 0,
|
||||
limit: int = 100,
|
||||
from_user: Union[int, str] = None
|
||||
) -> List["types.Message"]:
|
||||
try:
|
||||
filter = Filters.__dict__[filter.upper()]
|
||||
except KeyError:
|
||||
raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
|
||||
filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
|
||||
|
||||
r = await client.send(
|
||||
raw.functions.messages.Search(
|
||||
peer=await client.resolve_peer(chat_id),
|
||||
q=query,
|
||||
filter=filter,
|
||||
filter=filter.value(),
|
||||
min_date=0,
|
||||
max_date=0,
|
||||
offset_id=0,
|
||||
@ -95,7 +64,7 @@ class SearchMessages(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
query: str = "",
|
||||
offset: int = 0,
|
||||
filter: str = "empty",
|
||||
filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
|
||||
limit: int = 0,
|
||||
from_user: Union[int, str] = None
|
||||
) -> Optional[AsyncGenerator["types.Message", None]]:
|
||||
@ -119,26 +88,9 @@ class SearchMessages(Scaffold):
|
||||
Sequential number of the first message to be returned.
|
||||
Defaults to 0.
|
||||
|
||||
filter (``str``, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only:
|
||||
|
||||
- ``"empty"``: Search for all kind of messages (default).
|
||||
- ``"photo"``: Search for photos.
|
||||
- ``"video"``: Search for video.
|
||||
- ``"photo_video"``: Search for either photo or video.
|
||||
- ``"document"``: Search for documents (generic files).
|
||||
- ``"url"``: Search for messages containing URLs (web links).
|
||||
- ``"animation"``: Search for animations (GIFs).
|
||||
- ``"voice_note"``: Search for voice notes.
|
||||
- ``"audio"``: Search for audio files (music).
|
||||
- ``"chat_photo"``: Search for chat photos.
|
||||
- ``"phone_call"``: Search for phone calls.
|
||||
- ``"audio_video_note"``: Search for either audio or video notes.
|
||||
- ``"video_note"``: Search for video notes.
|
||||
- ``"mention"``: Search for messages containing mentions to yourself.
|
||||
- ``"location"``: Search for location messages.
|
||||
- ``"contact"``: Search for contact messages.
|
||||
- ``"pinned"``: Search for pinned messages.
|
||||
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only.
|
||||
Defaults to any message (no filter).
|
||||
|
||||
limit (``int``, *optional*):
|
||||
Limits the number of messages to be retrieved.
|
||||
@ -153,18 +105,21 @@ class SearchMessages(Scaffold):
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import enums
|
||||
|
||||
# Search for text messages in chat. Get the last 120 results
|
||||
for message in app.search_messages(chat_id, query="hello", limit=120):
|
||||
print(message.text)
|
||||
|
||||
# Search for pinned messages in chat
|
||||
for message in app.search_messages(chat_id, filter="pinned"):
|
||||
for message in app.search_messages(chat_id, filter=enums.MessagesFilter.PINNED):
|
||||
print(message.text)
|
||||
|
||||
# Search for messages containing "hello" sent by yourself in chat
|
||||
for message in app.search_messages(chat, "hello", from_user="me"):
|
||||
print(message.text)
|
||||
"""
|
||||
|
||||
current = 0
|
||||
total = abs(limit) or (1 << 31) - 1
|
||||
limit = min(100, total)
|
||||
|
@ -18,9 +18,8 @@
|
||||
|
||||
from typing import Union
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
from .search_messages import Filters, POSSIBLE_VALUES
|
||||
|
||||
|
||||
class SearchMessagesCount(Scaffold):
|
||||
@ -28,7 +27,7 @@ class SearchMessagesCount(Scaffold):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
query: str = "",
|
||||
filter: str = "empty",
|
||||
filter: "enums.MessagesFilter" = enums.MessagesFilter.ANY,
|
||||
from_user: Union[int, str] = None
|
||||
) -> int:
|
||||
"""Get the count of messages resulting from a search inside a chat.
|
||||
@ -47,44 +46,20 @@ class SearchMessagesCount(Scaffold):
|
||||
When passed while searching for media messages, the query will be applied to captions.
|
||||
Defaults to "" (empty string).
|
||||
|
||||
filter (``str``, *optional*):
|
||||
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
|
||||
Pass a filter in order to search for specific kind of messages only:
|
||||
|
||||
- ``"empty"``: Search for all kind of messages (default).
|
||||
- ``"photo"``: Search for photos.
|
||||
- ``"video"``: Search for video.
|
||||
- ``"photo_video"``: Search for either photo or video.
|
||||
- ``"document"``: Search for documents (generic files).
|
||||
- ``"url"``: Search for messages containing URLs (web links).
|
||||
- ``"animation"``: Search for animations (GIFs).
|
||||
- ``"voice_note"``: Search for voice notes.
|
||||
- ``"audio"``: Search for audio files (music).
|
||||
- ``"chat_photo"``: Search for chat photos.
|
||||
- ``"phone_call"``: Search for phone calls.
|
||||
- ``"audio_video_note"``: Search for either audio or video notes.
|
||||
- ``"video_note"``: Search for video notes.
|
||||
- ``"mention"``: Search for messages containing mentions to yourself.
|
||||
- ``"location"``: Search for location messages.
|
||||
- ``"contact"``: Search for contact messages.
|
||||
- ``"pinned"``: Search for pinned messages.
|
||||
|
||||
from_user (``int`` | ``str``, *optional*):
|
||||
Unique identifier (int) or username (str) of the target user you want to search for messages from.
|
||||
|
||||
Returns:
|
||||
``int``: On success, the messages count is returned.
|
||||
"""
|
||||
try:
|
||||
filter = Filters.__dict__[filter.upper()]
|
||||
except KeyError:
|
||||
raise ValueError('Invalid filter "{}". Possible values are: {}'.format(
|
||||
filter, ", ".join(f'"{v}"' for v in POSSIBLE_VALUES))) from None
|
||||
|
||||
r = await self.send(
|
||||
raw.functions.messages.Search(
|
||||
peer=await self.resolve_peer(chat_id),
|
||||
q=query,
|
||||
filter=filter,
|
||||
filter=filter.value(),
|
||||
min_date=0,
|
||||
max_date=0,
|
||||
offset_id=0,
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
from pyrogram import StopTransmission
|
||||
from pyrogram import StopTransmission, enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
@ -36,7 +36,7 @@ class SendAnimation(Scaffold):
|
||||
animation: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
unsave: bool = False,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
width: int = 0,
|
||||
@ -78,12 +78,9 @@ class SendAnimation(Scaffold):
|
||||
By default, the server will save into your own collection any new animation you send.
|
||||
Pass True to automatically unsave the sent animation. Defaults to False.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
from pyrogram import StopTransmission
|
||||
from pyrogram import StopTransmission, enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
@ -35,7 +35,7 @@ class SendAudio(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
audio: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
performer: str = None,
|
||||
@ -75,12 +75,9 @@ class SendAudio(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Audio caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.scaffold import Scaffold
|
||||
@ -30,7 +30,7 @@ class SendCachedMedia(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
file_id: str,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
@ -62,12 +62,9 @@ class SendCachedMedia(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Media caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -16,37 +16,19 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
from typing import Union
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
class ChatAction:
|
||||
TYPING = raw.types.SendMessageTypingAction
|
||||
UPLOAD_PHOTO = raw.types.SendMessageUploadPhotoAction
|
||||
RECORD_VIDEO = raw.types.SendMessageRecordVideoAction
|
||||
UPLOAD_VIDEO = raw.types.SendMessageUploadVideoAction
|
||||
RECORD_AUDIO = raw.types.SendMessageRecordAudioAction
|
||||
UPLOAD_AUDIO = raw.types.SendMessageUploadAudioAction
|
||||
UPLOAD_DOCUMENT = raw.types.SendMessageUploadDocumentAction
|
||||
FIND_LOCATION = raw.types.SendMessageGeoLocationAction
|
||||
RECORD_VIDEO_NOTE = raw.types.SendMessageRecordRoundAction
|
||||
UPLOAD_VIDEO_NOTE = raw.types.SendMessageUploadRoundAction
|
||||
PLAYING = raw.types.SendMessageGamePlayAction
|
||||
CHOOSE_CONTACT = raw.types.SendMessageChooseContactAction
|
||||
SPEAKING = raw.types.SpeakingInGroupCallAction
|
||||
IMPORT_HISTORY = raw.types.SendMessageHistoryImportAction
|
||||
CHOOSE_STICKER = raw.types.SendMessageChooseStickerAction
|
||||
CANCEL = raw.types.SendMessageCancelAction
|
||||
|
||||
|
||||
POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), ChatAction.__dict__.keys())))
|
||||
|
||||
|
||||
class SendChatAction(Scaffold):
|
||||
async def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
|
||||
async def send_chat_action(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
action: "pyrogram.enums.ChatAction"
|
||||
) -> bool:
|
||||
"""Tell the other party that something is happening on your side.
|
||||
|
||||
Parameters:
|
||||
@ -55,14 +37,8 @@ class SendChatAction(Scaffold):
|
||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||
|
||||
action (``str``):
|
||||
Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
|
||||
text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
|
||||
*"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
|
||||
*"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
|
||||
*"choose_contact"* for contacts, *"playing"* for games, *"speaking"* for speaking in group calls or
|
||||
*"import_history"* for importing history, *"choose_sticker"* for stickers or
|
||||
*"cancel"* to cancel any chat action currently displayed.
|
||||
action (:obj:`~pyrogram.enums.ChatAction`):
|
||||
Type of action to broadcast.
|
||||
|
||||
Returns:
|
||||
``bool``: On success, True is returned.
|
||||
@ -73,29 +49,27 @@ class SendChatAction(Scaffold):
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import enums
|
||||
|
||||
# Send "typing" chat action
|
||||
app.send_chat_action(chat_id, "typing")
|
||||
app.send_chat_action(chat_id, enums.ChatAction.TYPING)
|
||||
|
||||
# Send "upload_video" chat action
|
||||
app.send_chat_action(chat_id, "upload_video")
|
||||
app.send_chat_action(chat_id, enums.ChatAction.UPLOAD_VIDEO)
|
||||
|
||||
# Send "playing" chat action
|
||||
app.send_chat_action(chat_id, "playing")
|
||||
app.send_chat_action(chat_id, enums.ChatAction.PLAYING)
|
||||
|
||||
# Cancel any current chat action
|
||||
app.send_chat_action(chat_id, "cancel")
|
||||
app.send_chat_action(chat_id, enums.ChatAction.CANCEL)
|
||||
"""
|
||||
|
||||
try:
|
||||
action = ChatAction.__dict__[action.upper()]
|
||||
except KeyError:
|
||||
raise ValueError("Invalid chat action '{}'. Possible values are: {}".format(
|
||||
action, json.dumps(POSSIBLE_VALUES, indent=4))) from None
|
||||
action_name = action.name.lower()
|
||||
|
||||
if "Upload" in action.__name__ or "History" in action.__name__:
|
||||
action = action(progress=0)
|
||||
if "upload" in action_name or "history" in action_name:
|
||||
action = action.value(progress=0)
|
||||
else:
|
||||
action = action()
|
||||
action = action.value()
|
||||
|
||||
return await self.send(
|
||||
raw.functions.messages.SetTyping(
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
from pyrogram import StopTransmission
|
||||
from pyrogram import StopTransmission, enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
@ -36,7 +36,7 @@ class SendDocument(Scaffold):
|
||||
document: Union[str, BinaryIO],
|
||||
thumb: Union[str, BinaryIO] = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
file_name: str = None,
|
||||
force_document: bool = None,
|
||||
@ -77,12 +77,9 @@ class SendDocument(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Document caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from pyrogram import raw, utils
|
||||
from pyrogram import raw, utils, enums
|
||||
from pyrogram import types
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
@ -28,7 +28,7 @@ class SendMessage(Scaffold):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
entities: List["types.MessageEntity"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
disable_notification: bool = None,
|
||||
@ -53,12 +53,9 @@ class SendMessage(Scaffold):
|
||||
text (``str``):
|
||||
Text of the message to be sent.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
|
||||
|
@ -21,7 +21,7 @@ import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.errors import FilePartMissing
|
||||
@ -35,7 +35,7 @@ class SendPhoto(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
photo: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
ttl_seconds: int = None,
|
||||
disable_notification: bool = None,
|
||||
@ -69,12 +69,9 @@ class SendPhoto(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Photo caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Union, List
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import types, enums
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class SendPoll(Scaffold):
|
||||
options: List[str],
|
||||
is_anonymous: bool = True,
|
||||
allows_multiple_answers: bool = None,
|
||||
type: str = "regular",
|
||||
type: "enums.PollType" = enums.PollType.REGULAR,
|
||||
correct_option_id: int = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
@ -62,9 +62,9 @@ class SendPoll(Scaffold):
|
||||
True, if the poll needs to be anonymous.
|
||||
Defaults to True.
|
||||
|
||||
type (``str``, *optional*):
|
||||
Poll type, "quiz" or "regular".
|
||||
Defaults to "regular"
|
||||
type (:obj`~pyrogram.enums.PollType`, *optional*):
|
||||
Poll type, :obj:`~pyrogram.enums.PollType.QUIZ` or :obj:`~pyrogram.enums.PollType.REGULAR`.
|
||||
Defaults to :obj:`~pyrogram.enums.PollType.REGULAR`.
|
||||
|
||||
allows_multiple_answers (``bool``, *optional*):
|
||||
True, if the poll allows multiple answers, ignored for polls in quiz mode.
|
||||
@ -112,7 +112,7 @@ class SendPoll(Scaffold):
|
||||
],
|
||||
multiple_choice=allows_multiple_answers or None,
|
||||
public_voters=not is_anonymous or None,
|
||||
quiz=type == "quiz" or None
|
||||
quiz=type == enums.PollType.QUIZ or None
|
||||
),
|
||||
correct_answers=None if correct_option_id is None else [bytes([correct_option_id])]
|
||||
),
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
from pyrogram import StopTransmission
|
||||
from pyrogram import StopTransmission, enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
@ -35,7 +35,7 @@ class SendVideo(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
video: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
ttl_seconds: int = None,
|
||||
duration: int = 0,
|
||||
@ -75,12 +75,9 @@ class SendVideo(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Video caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
from typing import Union, BinaryIO, List, Optional
|
||||
|
||||
from pyrogram import StopTransmission
|
||||
from pyrogram import StopTransmission, enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
@ -35,7 +35,7 @@ class SendVoice(Scaffold):
|
||||
chat_id: Union[int, str],
|
||||
voice: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
disable_notification: bool = None,
|
||||
@ -69,12 +69,9 @@ class SendVoice(Scaffold):
|
||||
caption (``str``, *optional*):
|
||||
Voice message caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -174,13 +174,13 @@ class HTML:
|
||||
|
||||
entities_offsets.append((start_tag, start,))
|
||||
entities_offsets.append((end_tag, end,))
|
||||
|
||||
|
||||
entities_offsets = map(
|
||||
lambda x: x[1],
|
||||
sorted(
|
||||
enumerate(entities_offsets),
|
||||
key = lambda x: (x[1][1], x[0]),
|
||||
reverse = True
|
||||
key=lambda x: (x[1][1], x[0]),
|
||||
reverse=True
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -147,8 +147,14 @@ class Markdown:
|
||||
entities_offsets.append((start_tag, start,))
|
||||
entities_offsets.append((end_tag, end,))
|
||||
|
||||
# sorting by offset (desc)
|
||||
entities_offsets.sort(key=lambda x: -x[1])
|
||||
entities_offsets = map(
|
||||
lambda x: x[1],
|
||||
sorted(
|
||||
enumerate(entities_offsets),
|
||||
key=lambda x: (x[1][1], x[0]),
|
||||
reverse=True
|
||||
)
|
||||
)
|
||||
|
||||
for entity, offset in entities_offsets:
|
||||
text = text[:offset] + entity + text[offset:]
|
||||
|
@ -16,10 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import enums
|
||||
from .html import HTML
|
||||
from .markdown import Markdown
|
||||
|
||||
@ -30,36 +30,26 @@ class Parser:
|
||||
self.html = HTML(client)
|
||||
self.markdown = Markdown(client)
|
||||
|
||||
async def parse(self, text: str, mode: Optional[str] = object):
|
||||
async def parse(self, text: str, mode: Optional[str] = None):
|
||||
text = str(text if text else "").strip()
|
||||
|
||||
if mode == object:
|
||||
if mode is None:
|
||||
if self.client:
|
||||
mode = self.client.parse_mode
|
||||
else:
|
||||
mode = "combined"
|
||||
mode = enums.ParseMode.DEFAULT
|
||||
|
||||
if mode is None:
|
||||
return OrderedDict([
|
||||
("message", text),
|
||||
("entities", [])
|
||||
])
|
||||
|
||||
mode = mode.lower()
|
||||
|
||||
if mode == "combined":
|
||||
if mode == enums.ParseMode.DEFAULT:
|
||||
return await self.markdown.parse(text)
|
||||
|
||||
if mode in ["markdown", "md"]:
|
||||
if mode == enums.ParseMode.MARKDOWN:
|
||||
return await self.markdown.parse(text, True)
|
||||
|
||||
if mode == "html":
|
||||
if mode == enums.ParseMode.HTML:
|
||||
return await self.html.parse(text)
|
||||
|
||||
raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
|
||||
", ".join(f'"{m}"' for m in pyrogram.Client.PARSE_MODES[:-1]),
|
||||
mode
|
||||
))
|
||||
if mode == enums.ParseMode.DISABLED:
|
||||
return {"message": text, "entities": []}
|
||||
|
||||
@staticmethod
|
||||
def unparse(text: str, entities: list, is_html: bool):
|
||||
|
@ -26,7 +26,7 @@ from mimetypes import MimeTypes
|
||||
from pathlib import Path
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import __version__
|
||||
from pyrogram import __version__, enums
|
||||
from pyrogram.parser import Parser
|
||||
from pyrogram.session.internals import MsgId
|
||||
from .mime_types import mime_types
|
||||
@ -46,8 +46,6 @@ class Scaffold:
|
||||
WORKDIR = PARENT_DIR
|
||||
CONFIG_FILE = PARENT_DIR / "config.ini"
|
||||
|
||||
PARSE_MODES = ["combined", "markdown", "md", "html", None]
|
||||
|
||||
mimetypes = MimeTypes()
|
||||
mimetypes.readfp(StringIO(mime_types))
|
||||
|
||||
@ -90,7 +88,7 @@ class Scaffold:
|
||||
self.rnd_id = MsgId
|
||||
|
||||
self.parser = Parser(self)
|
||||
self.parse_mode = "combined"
|
||||
self.parse_mode = enums.ParseMode.DEFAULT
|
||||
|
||||
self.session = None
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from ..object import Object
|
||||
|
||||
|
||||
@ -24,29 +24,25 @@ class SentCode(Object):
|
||||
"""Contains info on a sent confirmation code.
|
||||
|
||||
Parameters:
|
||||
type (``str``):
|
||||
type (:obj:`~pyrogram.enums.SentCodeType`):
|
||||
Type of the current sent code.
|
||||
Can be *"app"* (code sent via Telegram), *"sms"* (code sent via SMS), *"call"* (code sent via voice call) or
|
||||
*"flash_call"* (code is in the last 5 digits of the caller's phone number).
|
||||
|
||||
phone_code_hash (``str``):
|
||||
Confirmation code identifier useful for the next authorization steps (either
|
||||
:meth:`~pyrogram.Client.sign_in` or :meth:`~pyrogram.Client.sign_up`).
|
||||
|
||||
next_type (``str``):
|
||||
next_type (:obj:`~pyrogram.enums.SentCodeType`, *optional*):
|
||||
Type of the next code to be sent with :meth:`~pyrogram.Client.resend_code`.
|
||||
Can be *"sms"* (code will be sent via SMS), *"call"* (code will be sent via voice call) or *"flash_call"*
|
||||
(code will be in the last 5 digits of caller's phone number).
|
||||
|
||||
timeout (``int``):
|
||||
timeout (``int``, *optional*):
|
||||
Delay in seconds before calling :meth:`~pyrogram.Client.resend_code`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, *,
|
||||
type: str,
|
||||
type: "enums.SentCodeType",
|
||||
phone_code_hash: str,
|
||||
next_type: str = None,
|
||||
next_type: "enums.SentCodeType" = None,
|
||||
timeout: int = None
|
||||
):
|
||||
super().__init__()
|
||||
@ -58,29 +54,9 @@ class SentCode(Object):
|
||||
|
||||
@staticmethod
|
||||
def _parse(sent_code: raw.types.auth.SentCode) -> "SentCode":
|
||||
type = sent_code.type
|
||||
|
||||
if isinstance(type, raw.types.auth.SentCodeTypeApp):
|
||||
type = "app"
|
||||
elif isinstance(type, raw.types.auth.SentCodeTypeSms):
|
||||
type = "sms"
|
||||
elif isinstance(type, raw.types.auth.SentCodeTypeCall):
|
||||
type = "call"
|
||||
elif isinstance(type, raw.types.auth.SentCodeTypeFlashCall):
|
||||
type = "flash_call"
|
||||
|
||||
next_type = sent_code.next_type
|
||||
|
||||
if isinstance(next_type, raw.types.auth.CodeTypeSms):
|
||||
next_type = "sms"
|
||||
elif isinstance(next_type, raw.types.auth.CodeTypeCall):
|
||||
next_type = "call"
|
||||
elif isinstance(next_type, raw.types.auth.CodeTypeFlashCall):
|
||||
next_type = "flash_call"
|
||||
|
||||
return SentCode(
|
||||
type=type,
|
||||
type=enums.SentCodeType(type(sent_code.type)),
|
||||
phone_code_hash=sent_code.phone_code_hash,
|
||||
next_type=next_type,
|
||||
next_type=enums.SentCodeType(type(sent_code.next_type)) if sent_code.next_type else None,
|
||||
timeout=sent_code.timeout
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ from struct import pack
|
||||
from typing import Union, List, Match, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
@ -171,7 +171,7 @@ class CallbackQuery(Object, Update):
|
||||
async def edit_message_text(
|
||||
self,
|
||||
text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> Union["types.Message", bool]:
|
||||
@ -183,12 +183,9 @@ class CallbackQuery(Object, Update):
|
||||
text (``str``):
|
||||
New text of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
disable_web_page_preview (``bool``, *optional*):
|
||||
Disables link previews for links in this message.
|
||||
@ -224,7 +221,7 @@ class CallbackQuery(Object, Update):
|
||||
async def edit_message_caption(
|
||||
self,
|
||||
caption: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> Union["types.Message", bool]:
|
||||
"""Edit the caption of media messages attached to callback queries.
|
||||
@ -235,12 +232,9 @@ class CallbackQuery(Object, Update):
|
||||
caption (``str``):
|
||||
New caption of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||
An InlineKeyboardMarkup object.
|
||||
|
@ -32,7 +32,7 @@ class GameHighScore(Object):
|
||||
score (``int``):
|
||||
Score.
|
||||
|
||||
position (``position``, *optional*):
|
||||
position (``int``, *optional*):
|
||||
Position in high score table for the game.
|
||||
"""
|
||||
|
||||
|
@ -43,7 +43,7 @@ class InlineKeyboardButton(Object):
|
||||
An HTTP URL used to automatically authorize the user. Can be used as a replacement for
|
||||
the `Telegram Login Widget <https://core.telegram.org/widgets/login>`_.
|
||||
|
||||
user_id (``id``, *optional*):
|
||||
user_id (``int``, *optional*):
|
||||
User id, for links to the user profile.
|
||||
|
||||
switch_inline_query (``str``, *optional*):
|
||||
|
@ -20,7 +20,7 @@ from typing import List, Match
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from pyrogram import types, enums
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
@ -43,11 +43,8 @@ class InlineQuery(Object, Update):
|
||||
offset (``str``):
|
||||
Offset of the results to be returned, can be controlled by the bot.
|
||||
|
||||
chat_type (``str``, *optional*):
|
||||
chat_type (:obj:`~pyrogram.enums.ChatType`, *optional*):
|
||||
Type of the chat, from which the inline query was sent.
|
||||
Can be either "sender" for a private chat with the inline query sender, "private", "group", "supergroup", or
|
||||
"channel". The chat type should be always known for requests sent from official clients and most
|
||||
third-party clients, unless the request was sent from a secret chat.
|
||||
|
||||
location (:obj:`~pyrogram.types.Location`. *optional*):
|
||||
Sender location, only for bots that request user location.
|
||||
@ -65,7 +62,7 @@ class InlineQuery(Object, Update):
|
||||
from_user: "types.User",
|
||||
query: str,
|
||||
offset: str,
|
||||
chat_type: str,
|
||||
chat_type: "enums.ChatType",
|
||||
location: "types.Location" = None,
|
||||
matches: List[Match] = None
|
||||
):
|
||||
@ -85,15 +82,15 @@ class InlineQuery(Object, Update):
|
||||
chat_type = None
|
||||
|
||||
if isinstance(peer_type, raw.types.InlineQueryPeerTypeSameBotPM):
|
||||
chat_type = "sender"
|
||||
chat_type = enums.ChatType.BOT
|
||||
elif isinstance(peer_type, raw.types.InlineQueryPeerTypePM):
|
||||
chat_type = "private"
|
||||
chat_type = enums.ChatType.PRIVATE
|
||||
elif isinstance(peer_type, raw.types.InlineQueryPeerTypeChat):
|
||||
chat_type = "group"
|
||||
chat_type = enums.ChatType.GROUP
|
||||
elif isinstance(peer_type, raw.types.InlineQueryPeerTypeMegagroup):
|
||||
chat_type = "supergroup"
|
||||
chat_type = enums.ChatType.SUPERGROUP
|
||||
elif isinstance(peer_type, raw.types.InlineQueryPeerTypeBroadcast):
|
||||
chat_type = "channel"
|
||||
chat_type = enums.ChatType.CHANNEL
|
||||
|
||||
return InlineQuery(
|
||||
id=str(inline_query.query_id),
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Optional, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from .inline_query_result import InlineQueryResult
|
||||
|
||||
|
||||
@ -52,12 +52,9 @@ class InlineQueryResultAnimation(InlineQueryResult):
|
||||
caption (``str``, *optional*):
|
||||
Caption of the photo to be sent, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -77,7 +74,7 @@ class InlineQueryResultAnimation(InlineQueryResult):
|
||||
title: str = None,
|
||||
description: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||
input_message_content: "types.InputMessageContent" = None
|
||||
|
@ -16,10 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Union, List
|
||||
from typing import Union, List, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from .inline_query_result import InlineQueryResult
|
||||
|
||||
|
||||
@ -50,13 +50,10 @@ class InlineQueryResultAudio(InlineQueryResult):
|
||||
caption (``str``, *optional*):
|
||||
Caption of the audio to be sent, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
|
||||
@ -75,7 +72,7 @@ class InlineQueryResultAudio(InlineQueryResult):
|
||||
performer: str = "",
|
||||
audio_duration: int = 0,
|
||||
caption: str = "",
|
||||
parse_mode: Union[str, None] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||
input_message_content: "types.InputMessageContent" = None
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Optional, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from .inline_query_result import InlineQueryResult
|
||||
|
||||
|
||||
@ -52,12 +52,9 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
||||
caption (``str``, *optional*):
|
||||
Caption of the photo to be sent, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -77,7 +74,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
||||
title: str = None,
|
||||
description: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||
input_message_content: "types.InputMessageContent" = None
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Optional, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from .inline_query_result import InlineQueryResult
|
||||
|
||||
|
||||
@ -63,12 +63,9 @@ class InlineQueryResultVideo(InlineQueryResult):
|
||||
caption (``str``, *optional*):
|
||||
Caption of the video to be sent, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -93,7 +90,7 @@ class InlineQueryResultVideo(InlineQueryResult):
|
||||
video_duration: int = 0,
|
||||
description: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||
input_message_content: "types.InputMessageContent" = None
|
||||
|
@ -20,6 +20,7 @@ from typing import Optional, List, Union, BinaryIO
|
||||
|
||||
from .input_media import InputMedia
|
||||
from ..messages_and_media import MessageEntity
|
||||
from ... import enums
|
||||
|
||||
|
||||
class InputMediaAnimation(InputMedia):
|
||||
@ -43,12 +44,9 @@ class InputMediaAnimation(InputMedia):
|
||||
Caption of the animation to be sent, 0-1024 characters.
|
||||
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -68,7 +66,7 @@ class InputMediaAnimation(InputMedia):
|
||||
media: Union[str, BinaryIO],
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List[MessageEntity] = None,
|
||||
width: int = 0,
|
||||
height: int = 0,
|
||||
|
@ -20,6 +20,7 @@ from typing import Optional, List, BinaryIO, Union
|
||||
|
||||
from .input_media import InputMedia
|
||||
from ..messages_and_media import MessageEntity
|
||||
from ... import enums
|
||||
|
||||
|
||||
class InputMediaAudio(InputMedia):
|
||||
@ -45,12 +46,9 @@ class InputMediaAudio(InputMedia):
|
||||
Caption of the audio to be sent, 0-1024 characters.
|
||||
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -70,7 +68,7 @@ class InputMediaAudio(InputMedia):
|
||||
media: Union[str, BinaryIO],
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List[MessageEntity] = None,
|
||||
duration: int = 0,
|
||||
performer: str = "",
|
||||
|
@ -20,6 +20,7 @@ from typing import Optional, List, Union, BinaryIO
|
||||
|
||||
from .input_media import InputMedia
|
||||
from ..messages_and_media import MessageEntity
|
||||
from ... import enums
|
||||
|
||||
|
||||
class InputMediaDocument(InputMedia):
|
||||
@ -43,12 +44,9 @@ class InputMediaDocument(InputMedia):
|
||||
Caption of the document to be sent, 0-1024 characters.
|
||||
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -59,7 +57,7 @@ class InputMediaDocument(InputMedia):
|
||||
media: Union[str, BinaryIO],
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List[MessageEntity] = None
|
||||
):
|
||||
super().__init__(media, caption, parse_mode, caption_entities)
|
||||
|
@ -20,6 +20,7 @@ from typing import Optional, List, Union, BinaryIO
|
||||
|
||||
from .input_media import InputMedia
|
||||
from ..messages_and_media import MessageEntity
|
||||
from ... import enums
|
||||
|
||||
|
||||
class InputMediaPhoto(InputMedia):
|
||||
@ -38,12 +39,9 @@ class InputMediaPhoto(InputMedia):
|
||||
Caption of the photo to be sent, 0-1024 characters.
|
||||
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -53,7 +51,7 @@ class InputMediaPhoto(InputMedia):
|
||||
self,
|
||||
media: Union[str, BinaryIO],
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List[MessageEntity] = None
|
||||
):
|
||||
super().__init__(media, caption, parse_mode, caption_entities)
|
||||
|
@ -20,6 +20,7 @@ from typing import Optional, List, Union, BinaryIO
|
||||
|
||||
from .input_media import InputMedia
|
||||
from ..messages_and_media import MessageEntity
|
||||
from ... import enums
|
||||
|
||||
|
||||
class InputMediaVideo(InputMedia):
|
||||
@ -44,12 +45,9 @@ class InputMediaVideo(InputMedia):
|
||||
Caption of the video to be sent, 0-1024 characters.
|
||||
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -72,7 +70,7 @@ class InputMediaVideo(InputMedia):
|
||||
media: Union[str, BinaryIO],
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List[MessageEntity] = None,
|
||||
width: int = 0,
|
||||
height: int = 0,
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Optional, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from .input_message_content import InputMessageContent
|
||||
|
||||
|
||||
@ -30,12 +30,9 @@ class InputTextMessageContent(InputMessageContent):
|
||||
message_text (``str``):
|
||||
Text of the message to be sent, 1-4096 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
|
||||
@ -47,7 +44,7 @@ class InputTextMessageContent(InputMessageContent):
|
||||
def __init__(
|
||||
self,
|
||||
message_text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
entities: List["types.MessageEntity"] = None,
|
||||
disable_web_page_preview: bool = None
|
||||
):
|
||||
|
@ -21,7 +21,7 @@ from functools import partial
|
||||
from typing import List, Match, Union, BinaryIO, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from pyrogram.errors import MessageIdsEmpty, PeerIdInvalid
|
||||
@ -112,17 +112,15 @@ class Message(Object, Update):
|
||||
The message is empty.
|
||||
A message can be empty in case it was deleted or you tried to retrieve a message that doesn't exist yet.
|
||||
|
||||
service (``str``, *optional*):
|
||||
The message is a service message. This field will contain the name of the service message.
|
||||
A service message has one and only one of these fields set: new_chat_members, left_chat_member,
|
||||
new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, channel_chat_created,
|
||||
migrate_to_chat_id, migrate_from_chat_id, pinned_message, game_high_score, voice_chat_started,
|
||||
voice_chat_ended, voice_chat_scheduled, voice_chat_members_invited.
|
||||
service (:obj:`~pyrogram.enums.MessageService`, *optional*):
|
||||
The message is a service message.
|
||||
This field will contain the enumeration type of the service message.
|
||||
You can use ``service = getattr(message, message.service.value)`` to access the service message.
|
||||
|
||||
media (``str``, *optional*):
|
||||
The message is a media message. This field will contain the name of the media message.
|
||||
A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation,
|
||||
voice, video_note, contact, location, venue, poll, web_page, dice, game.
|
||||
media (:obj:`~pyrogram.enums.MessageMedia`, *optional*):
|
||||
The message is a media message.
|
||||
This field will contain the enumeration type of the media message.
|
||||
You can use ``media = getattr(message, message.media.value)`` to access the media message.
|
||||
|
||||
edit_date (``int``, *optional*):
|
||||
Date the message was last edited in Unix time.
|
||||
@ -319,7 +317,7 @@ class Message(Object, Update):
|
||||
reply_to_message: "Message" = None,
|
||||
mentioned: bool = None,
|
||||
empty: bool = None,
|
||||
service: str = None,
|
||||
service: "enums.MessageService" = None,
|
||||
scheduled: bool = None,
|
||||
from_scheduled: bool = None,
|
||||
media: str = None,
|
||||
@ -497,47 +495,47 @@ class Message(Object, Update):
|
||||
|
||||
if isinstance(action, raw.types.MessageActionChatAddUser):
|
||||
new_chat_members = [types.User._parse(client, users[i]) for i in action.users]
|
||||
service_type = "new_chat_members"
|
||||
service_type = enums.MessageService.NEW_CHAT_MEMBERS
|
||||
elif isinstance(action, raw.types.MessageActionChatJoinedByLink):
|
||||
new_chat_members = [types.User._parse(client, users[utils.get_raw_peer_id(message.from_id)])]
|
||||
service_type = "new_chat_members"
|
||||
service_type = enums.MessageService.NEW_CHAT_MEMBERS
|
||||
elif isinstance(action, raw.types.MessageActionChatDeleteUser):
|
||||
left_chat_member = types.User._parse(client, users[action.user_id])
|
||||
service_type = "left_chat_member"
|
||||
service_type = enums.MessageService.LEFT_CHAT_MEMBERS
|
||||
elif isinstance(action, raw.types.MessageActionChatEditTitle):
|
||||
new_chat_title = action.title
|
||||
service_type = "new_chat_title"
|
||||
service_type = enums.MessageService.NEW_CHAT_TITLE
|
||||
elif isinstance(action, raw.types.MessageActionChatDeletePhoto):
|
||||
delete_chat_photo = True
|
||||
service_type = "delete_chat_photo"
|
||||
service_type = enums.MessageService.DELETE_CHAT_PHOTO
|
||||
elif isinstance(action, raw.types.MessageActionChatMigrateTo):
|
||||
migrate_to_chat_id = action.channel_id
|
||||
service_type = "migrate_to_chat_id"
|
||||
service_type = enums.MessageService.MIGRATE_TO_CHAT_ID
|
||||
elif isinstance(action, raw.types.MessageActionChannelMigrateFrom):
|
||||
migrate_from_chat_id = action.chat_id
|
||||
service_type = "migrate_from_chat_id"
|
||||
service_type = enums.MessageService.MIGRATE_FROM_CHAT_ID
|
||||
elif isinstance(action, raw.types.MessageActionChatCreate):
|
||||
group_chat_created = True
|
||||
service_type = "group_chat_created"
|
||||
service_type = enums.MessageService.GROUP_CHAT_CREATED
|
||||
elif isinstance(action, raw.types.MessageActionChannelCreate):
|
||||
channel_chat_created = True
|
||||
service_type = "channel_chat_created"
|
||||
service_type = enums.MessageService.CHANNEL_CHAT_CREATED
|
||||
elif isinstance(action, raw.types.MessageActionChatEditPhoto):
|
||||
new_chat_photo = types.Photo._parse(client, action.photo)
|
||||
service_type = "new_chat_photo"
|
||||
service_type = enums.MessageService.NEW_CHAT_PHOTO
|
||||
elif isinstance(action, raw.types.MessageActionGroupCallScheduled):
|
||||
voice_chat_scheduled = types.VoiceChatScheduled._parse(action)
|
||||
service_type = "voice_chat_scheduled"
|
||||
service_type = enums.MessageService.VOICE_CHAT_SCHEDULED
|
||||
elif isinstance(action, raw.types.MessageActionGroupCall):
|
||||
if action.duration:
|
||||
voice_chat_ended = types.VoiceChatEnded._parse(action)
|
||||
service_type = "voice_chat_ended"
|
||||
service_type = enums.MessageService.VOICE_CHAT_ENDED
|
||||
else:
|
||||
voice_chat_started = types.VoiceChatStarted()
|
||||
service_type = "voice_chat_started"
|
||||
service_type = enums.MessageService.VOICE_CHAT_STARTED
|
||||
elif isinstance(action, raw.types.MessageActionInviteToGroupCall):
|
||||
voice_chat_members_invited = types.VoiceChatMembersInvited._parse(client, action, users)
|
||||
service_type = "voice_chat_members_invited"
|
||||
service_type = enums.MessageService.VOICE_CHAT_MEMBERS_INVITED
|
||||
|
||||
from_user = types.User._parse(client, users.get(user_id, None))
|
||||
sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
|
||||
@ -574,7 +572,7 @@ class Message(Object, Update):
|
||||
replies=0
|
||||
)
|
||||
|
||||
parsed_message.service = "pinned_message"
|
||||
parsed_message.service = enums.MessageService.PINNED_MESSAGE
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
|
||||
@ -589,7 +587,7 @@ class Message(Object, Update):
|
||||
replies=0
|
||||
)
|
||||
|
||||
parsed_message.service = "game_high_score"
|
||||
parsed_message.service = enums.MessageService.GAME_HIGH_SCORE
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
|
||||
@ -646,19 +644,19 @@ class Message(Object, Update):
|
||||
if media:
|
||||
if isinstance(media, raw.types.MessageMediaPhoto):
|
||||
photo = types.Photo._parse(client, media.photo, media.ttl_seconds)
|
||||
media_type = "photo"
|
||||
media_type = enums.MessageMedia.PHOTO
|
||||
elif isinstance(media, raw.types.MessageMediaGeo):
|
||||
location = types.Location._parse(client, media.geo)
|
||||
media_type = "location"
|
||||
media_type = enums.MessageMedia.LOCATION
|
||||
elif isinstance(media, raw.types.MessageMediaContact):
|
||||
contact = types.Contact._parse(client, media)
|
||||
media_type = "contact"
|
||||
media_type = enums.MessageMedia.CONTACT
|
||||
elif isinstance(media, raw.types.MessageMediaVenue):
|
||||
venue = types.Venue._parse(client, media)
|
||||
media_type = "venue"
|
||||
media_type = enums.MessageMedia.VENUE
|
||||
elif isinstance(media, raw.types.MessageMediaGame):
|
||||
game = types.Game._parse(client, message)
|
||||
media_type = "game"
|
||||
media_type = enums.MessageMedia.GAME
|
||||
elif isinstance(media, raw.types.MessageMediaDocument):
|
||||
doc = media.document
|
||||
|
||||
@ -676,14 +674,14 @@ class Message(Object, Update):
|
||||
|
||||
if audio_attributes.voice:
|
||||
voice = types.Voice._parse(client, doc, audio_attributes)
|
||||
media_type = "voice"
|
||||
media_type = enums.MessageMedia.VOICE
|
||||
else:
|
||||
audio = types.Audio._parse(client, doc, audio_attributes, file_name)
|
||||
media_type = "audio"
|
||||
media_type = enums.MessageMedia.AUDIO
|
||||
elif raw.types.DocumentAttributeAnimated in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
animation = types.Animation._parse(client, doc, video_attributes, file_name)
|
||||
media_type = "animation"
|
||||
media_type = enums.MessageMedia.ANIMATION
|
||||
elif raw.types.DocumentAttributeSticker in attributes:
|
||||
sticker = await types.Sticker._parse(
|
||||
client, doc,
|
||||
@ -691,31 +689,31 @@ class Message(Object, Update):
|
||||
attributes[raw.types.DocumentAttributeSticker],
|
||||
file_name
|
||||
)
|
||||
media_type = "sticker"
|
||||
media_type = enums.MessageMedia.STICKER
|
||||
elif raw.types.DocumentAttributeVideo in attributes:
|
||||
video_attributes = attributes[raw.types.DocumentAttributeVideo]
|
||||
|
||||
if video_attributes.round_message:
|
||||
video_note = types.VideoNote._parse(client, doc, video_attributes)
|
||||
media_type = "video_note"
|
||||
media_type = enums.MessageMedia.VIDEO_NOTE
|
||||
else:
|
||||
video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
|
||||
media_type = "video"
|
||||
media_type = enums.MessageMedia.VIDEO
|
||||
else:
|
||||
document = types.Document._parse(client, doc, file_name)
|
||||
media_type = "document"
|
||||
media_type = enums.MessageMedia.DOCUMENT
|
||||
elif isinstance(media, raw.types.MessageMediaWebPage):
|
||||
if isinstance(media.webpage, raw.types.WebPage):
|
||||
web_page = types.WebPage._parse(client, media.webpage)
|
||||
media_type = "web_page"
|
||||
media_type = enums.MessageMedia.WEB_PAGE
|
||||
else:
|
||||
media = None
|
||||
elif isinstance(media, raw.types.MessageMediaPoll):
|
||||
poll = types.Poll._parse(client, media)
|
||||
media_type = "poll"
|
||||
media_type = enums.MessageMedia.POLL
|
||||
elif isinstance(media, raw.types.MessageMediaDice):
|
||||
dice = types.Dice._parse(client, media)
|
||||
media_type = "dice"
|
||||
media_type = enums.MessageMedia.DICE
|
||||
else:
|
||||
media = None
|
||||
|
||||
@ -820,7 +818,10 @@ class Message(Object, Update):
|
||||
|
||||
@property
|
||||
def link(self) -> str:
|
||||
if self.chat.type in ("group", "supergroup", "channel") and self.chat.username:
|
||||
if (
|
||||
self.chat.type in (enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)
|
||||
and self.chat.username
|
||||
):
|
||||
return f"https://t.me/{self.chat.username}/{self.message_id}"
|
||||
else:
|
||||
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.message_id}"
|
||||
@ -858,7 +859,7 @@ class Message(Object, Update):
|
||||
self,
|
||||
text: str,
|
||||
quote: bool = None,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
entities: List["types.MessageEntity"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
disable_notification: bool = None,
|
||||
@ -895,12 +896,9 @@ class Message(Object, Update):
|
||||
If *reply_to_message_id* is passed, this parameter will be ignored.
|
||||
Defaults to ``True`` in group chats and ``False`` in private chats.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
|
||||
@ -957,7 +955,7 @@ class Message(Object, Update):
|
||||
animation: Union[str, BinaryIO],
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
width: int = 0,
|
||||
@ -1005,12 +1003,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Animation caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -1099,7 +1094,7 @@ class Message(Object, Update):
|
||||
audio: Union[str, BinaryIO],
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
performer: str = None,
|
||||
@ -1147,12 +1142,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Audio caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -1241,7 +1233,7 @@ class Message(Object, Update):
|
||||
file_id: str,
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
@ -1281,12 +1273,9 @@ class Message(Object, Update):
|
||||
caption (``bool``, *optional*):
|
||||
Media caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -1454,7 +1443,7 @@ class Message(Object, Update):
|
||||
quote: bool = None,
|
||||
thumb: str = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
file_name: str = None,
|
||||
force_document: bool = None,
|
||||
@ -1507,12 +1496,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Document caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -1867,7 +1853,7 @@ class Message(Object, Update):
|
||||
photo: Union[str, BinaryIO],
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
ttl_seconds: int = None,
|
||||
disable_notification: bool = None,
|
||||
@ -1912,12 +1898,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Photo caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -2295,7 +2278,7 @@ class Message(Object, Update):
|
||||
video: Union[str, BinaryIO],
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
ttl_seconds: int = None,
|
||||
duration: int = 0,
|
||||
@ -2345,12 +2328,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Video caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -2567,7 +2547,7 @@ class Message(Object, Update):
|
||||
voice: Union[str, BinaryIO],
|
||||
quote: bool = None,
|
||||
caption: str = "",
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
duration: int = 0,
|
||||
disable_notification: bool = None,
|
||||
@ -2612,12 +2592,9 @@ class Message(Object, Update):
|
||||
caption (``str``, *optional*):
|
||||
Voice message caption, 0-1024 characters.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -2689,7 +2666,7 @@ class Message(Object, Update):
|
||||
async def edit_text(
|
||||
self,
|
||||
text: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
entities: List["types.MessageEntity"] = None,
|
||||
disable_web_page_preview: bool = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
@ -2717,12 +2694,9 @@ class Message(Object, Update):
|
||||
text (``str``):
|
||||
New text of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
|
||||
@ -2754,7 +2728,7 @@ class Message(Object, Update):
|
||||
async def edit_caption(
|
||||
self,
|
||||
caption: str,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
) -> "Message":
|
||||
@ -2779,12 +2753,9 @@ class Message(Object, Update):
|
||||
caption (``str``):
|
||||
New caption of the message.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||
@ -2938,7 +2909,7 @@ class Message(Object, Update):
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
caption: str = None,
|
||||
parse_mode: Optional[str] = object,
|
||||
parse_mode: Optional["enums.ParseMode"] = None,
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
disable_notification: bool = None,
|
||||
reply_to_message_id: int = None,
|
||||
@ -2979,12 +2950,9 @@ class Message(Object, Update):
|
||||
If not specified, the original caption is kept.
|
||||
Pass "" (empty string) to remove the caption.
|
||||
|
||||
parse_mode (``str``, *optional*):
|
||||
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||
By default, texts are parsed using both Markdown and HTML styles.
|
||||
You can combine both syntaxes together.
|
||||
Pass "markdown" or "md" to enable Markdown-style parsing only.
|
||||
Pass "html" to enable HTML-style parsing only.
|
||||
Pass None to completely disable style parsing.
|
||||
|
||||
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||
List of special entities that appear in the new caption, which can be specified instead of *parse_mode*.
|
||||
|
@ -16,87 +16,22 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from enum import Enum, auto
|
||||
from typing import Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class AutoName(Enum):
|
||||
def _generate_next_value_(self, *args):
|
||||
return self.lower()
|
||||
|
||||
|
||||
class MessageEntityType(AutoName):
|
||||
MENTION = auto()
|
||||
HASHTAG = auto()
|
||||
CASHTAG = auto()
|
||||
BOT_COMMAND = auto()
|
||||
URL = auto()
|
||||
EMAIL = auto()
|
||||
PHONE_NUMBER = auto()
|
||||
BOLD = auto()
|
||||
ITALIC = auto()
|
||||
UNDERLINE = auto()
|
||||
STRIKETHROUGH = auto()
|
||||
SPOILER = auto()
|
||||
CODE = auto()
|
||||
PRE = auto()
|
||||
TEXT_LINK = auto()
|
||||
TEXT_MENTION = auto()
|
||||
BLOCKQUOTE = auto()
|
||||
|
||||
|
||||
RAW_ENTITIES_TO_TYPE = {
|
||||
raw.types.MessageEntityMention: MessageEntityType.MENTION,
|
||||
raw.types.MessageEntityHashtag: MessageEntityType.HASHTAG,
|
||||
raw.types.MessageEntityCashtag: MessageEntityType.CASHTAG,
|
||||
raw.types.MessageEntityBotCommand: MessageEntityType.BOT_COMMAND,
|
||||
raw.types.MessageEntityUrl: MessageEntityType.URL,
|
||||
raw.types.MessageEntityEmail: MessageEntityType.EMAIL,
|
||||
raw.types.MessageEntityBold: MessageEntityType.BOLD,
|
||||
raw.types.MessageEntityItalic: MessageEntityType.ITALIC,
|
||||
raw.types.MessageEntityCode: MessageEntityType.CODE,
|
||||
raw.types.MessageEntityPre: MessageEntityType.PRE,
|
||||
raw.types.MessageEntityUnderline: MessageEntityType.UNDERLINE,
|
||||
raw.types.MessageEntityStrike: MessageEntityType.STRIKETHROUGH,
|
||||
raw.types.MessageEntitySpoiler: MessageEntityType.SPOILER,
|
||||
raw.types.MessageEntityBlockquote: MessageEntityType.BLOCKQUOTE,
|
||||
raw.types.MessageEntityTextUrl: MessageEntityType.TEXT_LINK,
|
||||
raw.types.MessageEntityMentionName: MessageEntityType.TEXT_MENTION,
|
||||
raw.types.MessageEntityPhone: MessageEntityType.PHONE_NUMBER
|
||||
}
|
||||
|
||||
TYPE_TO_RAW_ENTITIES = {v.value: k for k, v in RAW_ENTITIES_TO_TYPE.items()}
|
||||
|
||||
|
||||
class MessageEntity(Object):
|
||||
"""One special entity in a text message.
|
||||
|
||||
For example, hashtags, usernames, URLs, etc.
|
||||
|
||||
Parameters:
|
||||
type (``str``):
|
||||
Type of the entity. Can be:
|
||||
|
||||
- "mention": ``@username``.
|
||||
- "hashtag": ``#hashtag``.
|
||||
- "cashtag": ``$PYRO``.
|
||||
- "bot_command": ``/start@pyrogrambot``.
|
||||
- "url": ``https://pyrogram.org`` (see *url* below).
|
||||
- "email": ``do-not-reply@pyrogram.org``.
|
||||
- "phone_number": ``+1-123-456-7890``.
|
||||
- "bold": **bold text**.
|
||||
- "italic": *italic text*.
|
||||
- "underline": underlined text.
|
||||
- "strikethrough": strikethrough text.
|
||||
- "spoiler": spoiler text.
|
||||
- "code": monowidth string.
|
||||
- "pre": monowidth block (see *language* below).
|
||||
- "text_link": for clickable text URLs.
|
||||
- "text_mention": for users without usernames (see *user* below).
|
||||
type (:obj:`~pyrogram.enums.MessageEntityType`):
|
||||
Type of the entity.
|
||||
|
||||
offset (``int``):
|
||||
Offset in UTF-16 code units to the start of the entity.
|
||||
@ -118,7 +53,7 @@ class MessageEntity(Object):
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
type: str,
|
||||
type: "enums.MessageEntityType",
|
||||
offset: int,
|
||||
length: int,
|
||||
url: str = None,
|
||||
@ -135,14 +70,9 @@ class MessageEntity(Object):
|
||||
self.language = language
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, entity, users: dict) -> Optional["MessageEntity"]:
|
||||
type = RAW_ENTITIES_TO_TYPE.get(entity.__class__, None)
|
||||
|
||||
if type is None:
|
||||
return None
|
||||
|
||||
def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["MessageEntity"]:
|
||||
return MessageEntity(
|
||||
type=type.value,
|
||||
type=enums.MessageEntityType(entity.__class__),
|
||||
offset=entity.offset,
|
||||
length=entity.length,
|
||||
url=getattr(entity, "url", None),
|
||||
@ -166,15 +96,9 @@ class MessageEntity(Object):
|
||||
if self.language is None:
|
||||
args.pop("language")
|
||||
|
||||
try:
|
||||
entity = TYPE_TO_RAW_ENTITIES[self.type]
|
||||
entity = self.type.value
|
||||
|
||||
if entity is raw.types.MessageEntityMentionName:
|
||||
entity = raw.types.InputMessageEntityMentionName
|
||||
except KeyError as e:
|
||||
raise ValueError(f"Invalid message entity type {e}")
|
||||
else:
|
||||
try:
|
||||
return entity(**args)
|
||||
except TypeError as e:
|
||||
raise TypeError(f"{entity.QUALNAME}'s {e}")
|
||||
if entity is raw.types.MessageEntityMentionName:
|
||||
entity = raw.types.InputMessageEntityMentionName
|
||||
|
||||
return entity(**args)
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import List, Union
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
@ -47,8 +47,8 @@ class Poll(Object, Update):
|
||||
is_anonymous (``bool``, *optional*):
|
||||
True, if the poll is anonymous
|
||||
|
||||
type (``str``, *optional*):
|
||||
Poll type, currently can be "regular" or "quiz".
|
||||
type (:obj:`~pyrogram.enums.PollType`, *optional*):
|
||||
Poll type.
|
||||
|
||||
allows_multiple_answers (``bool``, *optional*):
|
||||
True, if the poll allows multiple answers.
|
||||
@ -67,7 +67,7 @@ class Poll(Object, Update):
|
||||
total_voter_count: int,
|
||||
is_closed: bool,
|
||||
is_anonymous: bool = None,
|
||||
type: str = None,
|
||||
type: "enums.PollType" = None,
|
||||
allows_multiple_answers: bool = None,
|
||||
# correct_option_id: int,
|
||||
chosen_option: int = None
|
||||
@ -118,7 +118,7 @@ class Poll(Object, Update):
|
||||
total_voter_count=media_poll.results.total_voters,
|
||||
is_closed=poll.closed,
|
||||
is_anonymous=not poll.public_voters,
|
||||
type="quiz" if poll.quiz else "regular",
|
||||
type=enums.PollType.QUIZ if poll.quiz else enums.PollType.REGULAR,
|
||||
allows_multiple_answers=poll.multiple_choice,
|
||||
chosen_option=chosen_option,
|
||||
client=client
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
import typing
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from json import dumps
|
||||
|
||||
import pyrogram
|
||||
@ -52,6 +53,9 @@ class Object(metaclass=Meta):
|
||||
if isinstance(obj, typing.Match):
|
||||
return repr(obj)
|
||||
|
||||
if isinstance(obj, Enum):
|
||||
return str(obj)
|
||||
|
||||
return {
|
||||
"_": obj.__class__.__name__,
|
||||
**{
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Union, List, Generator, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import utils
|
||||
from ..object import Object
|
||||
@ -32,8 +32,8 @@ class Chat(Object):
|
||||
id (``int``):
|
||||
Unique identifier for this chat.
|
||||
|
||||
type (``str``):
|
||||
Type of chat, can be either "private", "bot", "group", "supergroup" or "channel".
|
||||
type (:obj:`~pyrogram.enums.ChatType`):
|
||||
Type of chat.
|
||||
|
||||
is_verified (``bool``, *optional*):
|
||||
True, if this chat has been verified by Telegram. Supergroups, channels and bots only.
|
||||
@ -135,7 +135,7 @@ class Chat(Object):
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
id: int,
|
||||
type: str,
|
||||
type: "enums.ChatType",
|
||||
is_verified: bool = None,
|
||||
is_restricted: bool = None,
|
||||
is_creator: bool = None,
|
||||
@ -200,7 +200,7 @@ class Chat(Object):
|
||||
|
||||
return Chat(
|
||||
id=peer_id,
|
||||
type="bot" if user.bot else "private",
|
||||
type=enums.ChatType.BOT if user.bot else enums.ChatType.PRIVATE,
|
||||
is_verified=getattr(user, "verified", None),
|
||||
is_restricted=getattr(user, "restricted", None),
|
||||
is_scam=getattr(user, "scam", None),
|
||||
@ -221,7 +221,7 @@ class Chat(Object):
|
||||
|
||||
return Chat(
|
||||
id=peer_id,
|
||||
type="group",
|
||||
type=enums.ChatType.GROUP,
|
||||
title=chat.title,
|
||||
is_creator=getattr(chat, "creator", None),
|
||||
photo=types.ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id, 0),
|
||||
@ -239,7 +239,7 @@ class Chat(Object):
|
||||
|
||||
return Chat(
|
||||
id=peer_id,
|
||||
type="supergroup" if getattr(channel, "megagroup", None) else "channel",
|
||||
type=enums.ChatType.SUPERGROUP if getattr(channel, "megagroup", None) else enums.ChatType.CHANNEL,
|
||||
is_verified=getattr(channel, "verified", None),
|
||||
is_restricted=getattr(channel, "restricted", None),
|
||||
is_creator=getattr(channel, "creator", None),
|
||||
@ -842,7 +842,7 @@ class Chat(Object):
|
||||
offset: int = 0,
|
||||
limit: int = 200,
|
||||
query: str = "",
|
||||
filter: str = "all"
|
||||
filter: "enums.ChatMembersFilter" = enums.ChatMembersFilter.ANY
|
||||
) -> List["types.ChatMember"]:
|
||||
"""Bound method *get_members* of :obj:`~pyrogram.types.Chat`.
|
||||
|
||||
@ -930,17 +930,9 @@ class Chat(Object):
|
||||
Query string to filter members based on their display names and usernames.
|
||||
Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
|
||||
|
||||
filter (``str``, *optional*):
|
||||
filter (:obj:`~pyrogram.enums.ChatMembersFilter`, *optional*):
|
||||
Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
|
||||
and channels. It can be any of the followings:
|
||||
*"all"* - all kind of members,
|
||||
*"banned"* - banned members only,
|
||||
*"restricted"* - restricted members only,
|
||||
*"bots"* - bots only,
|
||||
*"recent"* - recent members only,
|
||||
*"administrators"* - chat administrators only.
|
||||
Only applicable to supergroups and channels.
|
||||
Defaults to *"recent"*.
|
||||
and channels.
|
||||
|
||||
.. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
|
||||
on channels.
|
||||
@ -950,16 +942,18 @@ class Chat(Object):
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import enums
|
||||
|
||||
# Get first 200 recent members
|
||||
for member in chat.get_members():
|
||||
print(member.user.first_name)
|
||||
|
||||
# Get all administrators
|
||||
for member in chat.iter_members(filter="administrators"):
|
||||
for member in chat.iter_members(filter=enums.ChatMembersFilter.ADMINISTRATORS):
|
||||
print(member.user.first_name)
|
||||
|
||||
# Get first 3 bots
|
||||
for member in chat.iter_members(filter="bots", limit=3):
|
||||
for member in chat.iter_members(filter=enums.ChatMembersFilter.BOTS, limit=3):
|
||||
print(member.user.first_name)
|
||||
|
||||
Returns:
|
||||
|
@ -70,6 +70,8 @@ class ChatEventAction(AutoName):
|
||||
class ChatEvent(Object):
|
||||
"""A chat event from the recent actions log (also known as admin log).
|
||||
|
||||
See ``action`` to know which kind of event this is and the relative attributes to get the event content.
|
||||
|
||||
Parameters:
|
||||
id (``int``):
|
||||
Chat event identifier.
|
||||
@ -77,171 +79,99 @@ class ChatEvent(Object):
|
||||
date (``int``):
|
||||
Date of the event. Unix time.
|
||||
|
||||
action (``str``):
|
||||
Event action. Can be:
|
||||
|
||||
- "description_changed": the chat description has been changed
|
||||
(see *old_description* and *new_description* below).
|
||||
|
||||
- "history_ttl_changed": the history time-to-live has been changed
|
||||
(see *old_history_ttl* and *new_history_ttl* below).
|
||||
|
||||
- "linked_chat_changed": the linked chat has been changed
|
||||
(see *old_linked_chat* and *new_linked_chat* below).
|
||||
|
||||
- "photo_changed": the chat photo has been changed
|
||||
(see *old_photo* and *new_photo* below).
|
||||
|
||||
- "title_changed": the chat title has been changed
|
||||
(see *old_title* and *new_title* below).
|
||||
|
||||
- "username_changed": the chat username has been changed
|
||||
(see *old_username* and *new_username* below).
|
||||
|
||||
- "chat_permissions_changed": the default chat permissions has been changed
|
||||
(see *old_chat_permissions* and *new_chat_permissions* below).
|
||||
|
||||
- "message_deleted": a message has been deleted
|
||||
(see *deleted_message* below).
|
||||
|
||||
- "message_edited": a message has been edited
|
||||
(see *old_message* and *new_message* below).
|
||||
|
||||
- "member_invited": a member has been invited by someone
|
||||
(see *invited_member* below).
|
||||
|
||||
- "member_joined": a member joined by themselves.
|
||||
(see *user* below)
|
||||
|
||||
- "member_left": a member left by themselves.
|
||||
(see *user* below).
|
||||
|
||||
- "admin_rights_changed": a chat member has been promoted/demoted or their administrator rights has changed
|
||||
(see *old_admin_rights* and *new_admin_rights* below).
|
||||
|
||||
- "member_permissions_changed": a chat member has been restricted/unrestricted or banned/unbanned, or their
|
||||
permissions has changed (see *old_member_permissions* and *new_member_permissions* below).
|
||||
|
||||
- "poll_stopped": a poll has been stopped
|
||||
(see *stopped_poll* below).
|
||||
|
||||
- "invites_enabled": the chat invitation has been enabled or disabled
|
||||
(see *invites_enabled* below).
|
||||
|
||||
- "history_hidden": the chat history has been hidden or unhidden
|
||||
(see *history_hidden* below).
|
||||
|
||||
- "signatures_enabled": the message signatures have been enabled or disabled
|
||||
(see *signatures_enabled* below).
|
||||
|
||||
- "slow_mode_changed": the slow mode has been changes
|
||||
(see *old_slow_mode* and *new_slow_mode* below).
|
||||
|
||||
- "message_pinned": a message has been pinned
|
||||
(see *pinned_message* below).
|
||||
|
||||
- "message_unpinned": a message has been unpinned
|
||||
(see *unpinned_message* below).
|
||||
|
||||
- "invite_link_edited": an invite link has been edited
|
||||
(see *edited_invite_link* below).
|
||||
|
||||
- "invite_link_revoked": an invite link has been revoked
|
||||
(see *revoked_invite_link* below).
|
||||
|
||||
- "invite_link_deleted": an invite link has been deleted
|
||||
(see *deleted_invite_link* below).
|
||||
action (:obj:`~pyrogram.enums.ChatEventAction`):
|
||||
Event action.
|
||||
|
||||
user (:obj:`~pyrogram.types.User`):
|
||||
User that triggered the event.
|
||||
|
||||
old_description, new_description (``str``, *optional*):
|
||||
Previous and new chat description.
|
||||
For "description_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.DESCRIPTION_CHANGED` action only.
|
||||
|
||||
old_history_ttl, new_history_ttl (``int``, *optional*):
|
||||
Previous and new chat history TTL.
|
||||
For "history_ttl_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.HISTORY_TTL_CHANGED` action only.
|
||||
|
||||
old_linked_chat, new_linked_chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||
Previous and new linked chat.
|
||||
For "linked_chat_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.LINKED_CHAT_CHANGED` action only.
|
||||
|
||||
old_photo, new_photo (:obj:`~pyrogram.types.Photo`, *optional*):
|
||||
Previous and new chat photo.
|
||||
For "photo_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.PHOTO_CHANGED` action only.
|
||||
|
||||
old_title, new_title (``str``, *optional*):
|
||||
Previous and new chat title.
|
||||
For "title_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.TITLE_CHANGED` action only.
|
||||
|
||||
old_username, new_username (``str``, *optional*):
|
||||
Previous and new chat username.
|
||||
For "username_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.USERNAME_CHANGED` action only.
|
||||
|
||||
old_chat_permissions, new_chat_permissions (:obj:`~pyrogram.types.ChatPermissions`, *optional*):
|
||||
Previous and new default chat permissions.
|
||||
For "chat_permissions_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.CHAT_PERMISSIONS_CHANGED` action only.
|
||||
|
||||
deleted_message (:obj:`~pyrogram.types.Message`, *optional*):
|
||||
Deleted message.
|
||||
For "deleted_message" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_DELETED` action only.
|
||||
|
||||
old_message, new_message (:obj:`~pyrogram.types.Message`, *optional*):
|
||||
Previous and new message before it has been edited.
|
||||
For "message_edited" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_EDITED` action only.
|
||||
|
||||
invited_member (:obj:`~pyrogram.types.ChatMember`, *optional*):
|
||||
New invited chat member.
|
||||
For "member_invited" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MEMBER_INVITED` action only.
|
||||
|
||||
old_admin_rights, new_admin_rights (:obj:`~pyrogram.types.ChatMember`, *optional*):
|
||||
Previous and new administrator rights.
|
||||
For "admin_rights_changed" only.
|
||||
old_administrator_privileges, new_administrator_privileges (:obj:`~pyrogram.types.ChatMember`, *optional*):
|
||||
Previous and new administrator privileges.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.ADMINISTRATOR_PRIVILEGES_CHANGED` action only.
|
||||
|
||||
old_member_permissions, new_member_permissions (:obj:`~pyrogram.types.ChatMember`, *optional*):
|
||||
Previous and new member permissions.
|
||||
For "member_permissions_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MEMBER_PERMISSIONS_CHANGED` action only.
|
||||
|
||||
stopped_poll (:obj:`~pyrogram.types.Message`, *optional*):
|
||||
Message containing the stopped poll.
|
||||
For "poll_stopped" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.POLL_STOPPED` action only.
|
||||
|
||||
invites_enabled (``bool``, *optional*):
|
||||
If chat invites were enabled (True) or disabled (False).
|
||||
For "invites_enabled" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.INVITES_ENABLED` action only.
|
||||
|
||||
history_hidden (``bool``, *optional*):
|
||||
If chat history has been hidden (True) or unhidden (False).
|
||||
For "history_hidden" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.HISTORY_HIDDEN` action only.
|
||||
|
||||
signatures_enabled (``bool``, *optional*):
|
||||
If message signatures were enabled (True) or disabled (False).
|
||||
For "signatures_enabled" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.SIGNATURES_ENABLED` action only.
|
||||
|
||||
old_slow_mode, new_slow_mode (``int``, *optional*):
|
||||
Previous and new slow mode value in seconds.
|
||||
For "slow_mode_changed" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.SLOW_MODE_CHANGED` action only.
|
||||
|
||||
pinned_message (:obj:`~pyrogram.types.Message`, *optional*):
|
||||
Pinned message.
|
||||
For "message_pinned" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_PINNED` action only.
|
||||
|
||||
unpinned_message (:obj:`~pyrogram.types.Message`, *optional*):
|
||||
Unpinned message.
|
||||
For "unpinned_message" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.MESSAGE_UNPINNED` action only.
|
||||
|
||||
old_invite_link, new_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
|
||||
Previous and new edited invite link.
|
||||
For "invite_link_edited" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_EDITED` action only.
|
||||
|
||||
revoked_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
|
||||
Revoked invite link.
|
||||
For "invite_link_revoked" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_REVOKED` action only.
|
||||
|
||||
deleted_invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*):
|
||||
Deleted invite link.
|
||||
For "invite_link_deleted" only.
|
||||
For :obj:`~pyrogram.enums.ChatEventAction.INVITE_LINK_DELETED` action only.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@ -279,8 +209,8 @@ class ChatEvent(Object):
|
||||
|
||||
invited_member: "types.ChatMember" = None,
|
||||
|
||||
old_admin_rights: "types.ChatMember" = None,
|
||||
new_admin_rights: "types.ChatMember" = None,
|
||||
old_administrator_privileges: "types.ChatMember" = None,
|
||||
new_administrator_privileges: "types.ChatMember" = None,
|
||||
|
||||
old_member_permissions: "types.ChatMember" = None,
|
||||
new_member_permissions: "types.ChatMember" = None,
|
||||
@ -339,8 +269,8 @@ class ChatEvent(Object):
|
||||
|
||||
self.invited_member = invited_member
|
||||
|
||||
self.old_admin_rights = old_admin_rights
|
||||
self.new_admin_rights = new_admin_rights
|
||||
self.old_administrator_privileges = old_administrator_privileges
|
||||
self.new_administrator_privileges = new_administrator_privileges
|
||||
|
||||
self.old_member_permissions = old_member_permissions
|
||||
self.new_member_permissions = new_member_permissions
|
||||
@ -405,8 +335,8 @@ class ChatEvent(Object):
|
||||
|
||||
invited_member: Optional[types.ChatMember] = None
|
||||
|
||||
old_admin_rights: Optional[types.ChatMember] = None
|
||||
new_admin_rights: Optional[types.ChatMember] = None
|
||||
old_administrator_privileges: Optional[types.ChatMember] = None
|
||||
new_administrator_privileges: Optional[types.ChatMember] = None
|
||||
|
||||
old_member_permissions: Optional[types.ChatMember] = None
|
||||
new_member_permissions: Optional[types.ChatMember] = None
|
||||
@ -433,102 +363,102 @@ class ChatEvent(Object):
|
||||
if isinstance(action, raw.types.ChannelAdminLogEventActionChangeAbout):
|
||||
old_description = action.prev_value
|
||||
new_description = action.new_value
|
||||
action = ChatEventAction.DESCRIPTION_CHANGED.value
|
||||
action = ChatEventAction.DESCRIPTION_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeHistoryTTL):
|
||||
old_history_ttl = action.prev_value
|
||||
new_history_ttl = action.new_value
|
||||
action = ChatEventAction.HISTORY_TTL_CHANGED.value
|
||||
action = ChatEventAction.HISTORY_TTL_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeLinkedChat):
|
||||
old_linked_chat = types.Chat._parse_chat(client, chats[action.prev_value])
|
||||
new_linked_chat = types.Chat._parse_chat(client, chats[action.new_value])
|
||||
action = ChatEventAction.LINKED_CHAT_CHANGED.value
|
||||
action = ChatEventAction.LINKED_CHAT_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionChangePhoto):
|
||||
old_photo = types.Photo._parse(client, action.prev_photo)
|
||||
new_photo = types.Photo._parse(client, action.new_photo)
|
||||
action = ChatEventAction.PHOTO_CHANGED.value
|
||||
action = ChatEventAction.PHOTO_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeTitle):
|
||||
old_title = action.prev_value
|
||||
new_title = action.new_value
|
||||
action = ChatEventAction.TITLE_CHANGED.value
|
||||
action = ChatEventAction.TITLE_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionChangeUsername):
|
||||
old_username = action.prev_value
|
||||
new_username = action.new_value
|
||||
action = ChatEventAction.USERNAME_CHANGED.value
|
||||
action = ChatEventAction.USERNAME_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionDefaultBannedRights):
|
||||
old_chat_permissions = types.ChatPermissions._parse(action.prev_banned_rights)
|
||||
new_chat_permissions = types.ChatPermissions._parse(action.new_banned_rights)
|
||||
action = ChatEventAction.CHAT_PERMISSIONS_CHANGED.value
|
||||
action = ChatEventAction.CHAT_PERMISSIONS_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionDeleteMessage):
|
||||
deleted_message = await types.Message._parse(client, action.message, users, chats)
|
||||
action = ChatEventAction.MESSAGE_DELETED.value
|
||||
action = ChatEventAction.MESSAGE_DELETED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionEditMessage):
|
||||
old_message = await types.Message._parse(client, action.prev_message, users, chats)
|
||||
new_message = await types.Message._parse(client, action.new_message, users, chats)
|
||||
action = ChatEventAction.MESSAGE_EDITED.value
|
||||
action = ChatEventAction.MESSAGE_EDITED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantInvite):
|
||||
invited_member = types.ChatMember._parse(client, action.participant, users, chats)
|
||||
action = ChatEventAction.MEMBER_INVITED.value
|
||||
action = ChatEventAction.MEMBER_INVITED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleAdmin):
|
||||
old_admin_rights = types.ChatMember._parse(client, action.prev_participant, users, chats)
|
||||
new_admin_rights = types.ChatMember._parse(client, action.new_participant, users, chats)
|
||||
action = ChatEventAction.ADMIN_RIGHTS_CHANGED.value
|
||||
old_administrator_privileges = types.ChatMember._parse(client, action.prev_participant, users, chats)
|
||||
new_administrator_privileges = types.ChatMember._parse(client, action.new_participant, users, chats)
|
||||
action = ChatEventAction.ADMIN_RIGHTS_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleBan):
|
||||
old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users, chats)
|
||||
new_member_permissions = types.ChatMember._parse(client, action.new_participant, users, chats)
|
||||
action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED.value
|
||||
action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionStopPoll):
|
||||
stopped_poll = await types.Message._parse(client, action.message, users, chats)
|
||||
action = ChatEventAction.POLL_STOPPED.value
|
||||
action = ChatEventAction.POLL_STOPPED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantJoin):
|
||||
action = ChatEventAction.MEMBER_JOINED.value
|
||||
action = ChatEventAction.MEMBER_JOINED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantLeave):
|
||||
action = ChatEventAction.MEMBER_LEFT.value
|
||||
action = ChatEventAction.MEMBER_LEFT
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleInvites):
|
||||
invites_enabled = action.new_value
|
||||
action = ChatEventAction.INVITES_ENABLED.value
|
||||
action = ChatEventAction.INVITES_ENABLED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionTogglePreHistoryHidden):
|
||||
history_hidden = action.new_value
|
||||
action = ChatEventAction.HISTORY_HIDDEN.value
|
||||
action = ChatEventAction.HISTORY_HIDDEN
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSignatures):
|
||||
signatures_enabled = action.new_value
|
||||
action = ChatEventAction.SIGNATURES_ENABLED.value
|
||||
action = ChatEventAction.SIGNATURES_ENABLED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSlowMode):
|
||||
old_slow_mode = action.prev_value
|
||||
new_slow_mode = action.new_value
|
||||
action = ChatEventAction.SLOW_MODE_CHANGED.value
|
||||
action = ChatEventAction.SLOW_MODE_CHANGED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionUpdatePinned):
|
||||
message = action.message
|
||||
|
||||
if message.pinned:
|
||||
pinned_message = await types.Message._parse(client, message, users, chats)
|
||||
action = ChatEventAction.MESSAGE_PINNED.value
|
||||
action = ChatEventAction.MESSAGE_PINNED
|
||||
else:
|
||||
unpinned_message = await types.Message._parse(client, message, users, chats)
|
||||
action = ChatEventAction.MESSAGE_UNPINNED.value
|
||||
action = ChatEventAction.MESSAGE_UNPINNED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteEdit):
|
||||
old_invite_link = types.ChatInviteLink._parse(client, action.prev_invite, users)
|
||||
new_invite_link = types.ChatInviteLink._parse(client, action.new_invite, users)
|
||||
action = ChatEventAction.INVITE_LINK_EDITED.value
|
||||
action = ChatEventAction.INVITE_LINK_EDITED
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteRevoke):
|
||||
revoked_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
|
||||
@ -536,10 +466,10 @@ class ChatEvent(Object):
|
||||
|
||||
elif isinstance(action, raw.types.ChannelAdminLogEventActionExportedInviteDelete):
|
||||
deleted_invite_link = types.ChatInviteLink._parse(client, action.invite, users)
|
||||
action = ChatEventAction.INVITE_LINK_DELETED.value
|
||||
action = ChatEventAction.INVITE_LINK_DELETED
|
||||
|
||||
else:
|
||||
action = f"{ChatEventAction.UNKNOWN.value}-{action.QUALNAME}"
|
||||
action = f"{ChatEventAction.UNKNOWN}-{action.QUALNAME}"
|
||||
|
||||
return ChatEvent(
|
||||
id=event.id,
|
||||
@ -574,8 +504,8 @@ class ChatEvent(Object):
|
||||
|
||||
invited_member=invited_member,
|
||||
|
||||
old_admin_rights=old_admin_rights,
|
||||
new_admin_rights=new_admin_rights,
|
||||
old_administrator_privileges=old_administrator_privileges,
|
||||
new_administrator_privileges=new_administrator_privileges,
|
||||
|
||||
old_member_permissions=old_member_permissions,
|
||||
new_member_permissions=new_member_permissions,
|
||||
|
@ -28,7 +28,7 @@ class ChatEventFilter(Object):
|
||||
True, if member restricted/unrestricted/banned/unbanned events should be returned.
|
||||
Defaults to False.
|
||||
|
||||
admin_rights (``bool``, *optional*):
|
||||
new_privileges (``bool``, *optional*):
|
||||
True, if member promotion/demotion events should be returned.
|
||||
Defaults to False.
|
||||
|
||||
@ -74,7 +74,7 @@ class ChatEventFilter(Object):
|
||||
def __init__(
|
||||
self, *,
|
||||
new_restrictions: bool = False,
|
||||
admin_rights: bool = False,
|
||||
new_privileges: bool = False,
|
||||
new_members: bool = False,
|
||||
chat_info: bool = False,
|
||||
chat_settings: bool = False,
|
||||
@ -88,7 +88,7 @@ class ChatEventFilter(Object):
|
||||
super().__init__()
|
||||
|
||||
self.new_restrictions = new_restrictions
|
||||
self.admin_rights = admin_rights
|
||||
self.new_privileges = new_privileges
|
||||
self.new_members = new_members
|
||||
self.chat_info = chat_info
|
||||
self.chat_settings = chat_settings
|
||||
@ -123,7 +123,7 @@ class ChatEventFilter(Object):
|
||||
kick = True
|
||||
unkick = True
|
||||
|
||||
if self.admin_rights:
|
||||
if self.new_privileges:
|
||||
promote = True
|
||||
demote = True
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
from typing import Union, Dict
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types, utils
|
||||
from pyrogram import raw, types, utils, enums
|
||||
from ..object import Object
|
||||
|
||||
|
||||
@ -27,9 +27,8 @@ class ChatMember(Object):
|
||||
"""Contains information about one member of a chat.
|
||||
|
||||
Parameters:
|
||||
status (``str``):
|
||||
status (:obj:`~pyrogram.enums.ChatMemberStatus`):
|
||||
The member's status in the chat.
|
||||
Can be "creator", "administrator", "member", "restricted", "left" or "banned".
|
||||
|
||||
user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
Information about the user.
|
||||
@ -76,7 +75,7 @@ class ChatMember(Object):
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
status: str,
|
||||
status: "enums.ChatMemberStatus",
|
||||
user: "types.User" = None,
|
||||
chat: "types.Chat" = None,
|
||||
custom_title: str = None,
|
||||
@ -108,15 +107,15 @@ class ChatMember(Object):
|
||||
|
||||
@staticmethod
|
||||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
|
||||
users: Dict[int, "raw.base.User"],
|
||||
chats: Dict[int, "raw.base.Chat"]
|
||||
client: "pyrogram.Client",
|
||||
member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"],
|
||||
users: Dict[int, "raw.base.User"],
|
||||
chats: Dict[int, "raw.base.Chat"]
|
||||
) -> "ChatMember":
|
||||
# Chat participants
|
||||
if isinstance(member, raw.types.ChatParticipant):
|
||||
return ChatMember(
|
||||
status="member",
|
||||
status=enums.ChatMemberStatus.MEMBER,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
joined_date=member.date,
|
||||
invited_by=types.User._parse(client, users[member.inviter_id]),
|
||||
@ -124,7 +123,7 @@ class ChatMember(Object):
|
||||
)
|
||||
elif isinstance(member, raw.types.ChatParticipantAdmin):
|
||||
return ChatMember(
|
||||
status="administrator",
|
||||
status=enums.ChatMemberStatus.ADMINISTRATOR,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
joined_date=member.date,
|
||||
invited_by=types.User._parse(client, users[member.inviter_id]),
|
||||
@ -132,7 +131,7 @@ class ChatMember(Object):
|
||||
)
|
||||
elif isinstance(member, raw.types.ChatParticipantCreator):
|
||||
return ChatMember(
|
||||
status="owner",
|
||||
status=enums.ChatMemberStatus.OWNER,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
client=client
|
||||
)
|
||||
@ -140,14 +139,14 @@ class ChatMember(Object):
|
||||
# Channel participants
|
||||
if isinstance(member, raw.types.ChannelParticipant):
|
||||
return ChatMember(
|
||||
status="member",
|
||||
status=enums.ChatMemberStatus.MEMBER,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
joined_date=member.date,
|
||||
client=client
|
||||
)
|
||||
elif isinstance(member, raw.types.ChannelParticipantAdmin):
|
||||
return ChatMember(
|
||||
status="administrator",
|
||||
status=enums.ChatMemberStatus.ADMINISTRATOR,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
joined_date=member.date,
|
||||
promoted_by=types.User._parse(client, users[member.promoted_by]),
|
||||
@ -172,7 +171,11 @@ class ChatMember(Object):
|
||||
)
|
||||
|
||||
return ChatMember(
|
||||
status="banned" if member.banned_rights.view_messages else "restricted",
|
||||
status=(
|
||||
enums.ChatMemberStatus.BANNED
|
||||
if member.banned_rights.view_messages
|
||||
else enums.ChatMemberStatus.RESTRICTED
|
||||
),
|
||||
user=user,
|
||||
chat=chat,
|
||||
until_date=member.banned_rights.until_date,
|
||||
@ -184,7 +187,7 @@ class ChatMember(Object):
|
||||
)
|
||||
elif isinstance(member, raw.types.ChannelParticipantCreator):
|
||||
return ChatMember(
|
||||
status="owner",
|
||||
status=enums.ChatMemberStatus.OWNER,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
custom_title=member.rank,
|
||||
privileges=types.ChatPrivileges._parse(member.admin_rights),
|
||||
@ -205,14 +208,14 @@ class ChatMember(Object):
|
||||
)
|
||||
|
||||
return ChatMember(
|
||||
status="left",
|
||||
status=enums.ChatMemberStatus.LEFT,
|
||||
user=user,
|
||||
chat=chat,
|
||||
client=client
|
||||
)
|
||||
elif isinstance(member, raw.types.ChannelParticipantSelf):
|
||||
return ChatMember(
|
||||
status="member",
|
||||
status=enums.ChatMemberStatus.MEMBER,
|
||||
user=types.User._parse(client, users[member.user_id]),
|
||||
joined_date=member.date,
|
||||
invited_by=types.User._parse(client, users[member.inviter_id]),
|
||||
|
@ -39,7 +39,7 @@ class InviteLinkImporter(Object):
|
||||
self.user = user
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, invite_importers: "raw.types.ChatInviteImporters"):
|
||||
def _parse(client, invite_importers: "raw.types.messages.ChatInviteImporters"):
|
||||
importers = types.List()
|
||||
|
||||
d = {i.id: i for i in invite_importers.users}
|
||||
|
@ -20,6 +20,7 @@ import html
|
||||
from typing import List, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import enums
|
||||
from pyrogram import raw
|
||||
from pyrogram import types
|
||||
from ..object import Object
|
||||
@ -28,9 +29,9 @@ from ..update import Update
|
||||
|
||||
class Link(str):
|
||||
HTML = "<a href={url}>{text}</a>"
|
||||
MD = "[{text}]({url})"
|
||||
MARKDOWN = "[{text}]({url})"
|
||||
|
||||
def __init__(self, url: str, text: str, style: str):
|
||||
def __init__(self, url: str, text: str, style: enums.ParseMode):
|
||||
super().__init__()
|
||||
|
||||
self.url = url
|
||||
@ -38,13 +39,11 @@ class Link(str):
|
||||
self.style = style
|
||||
|
||||
@staticmethod
|
||||
def format(url: str, text: str, style: str):
|
||||
if style in ["md", "markdown"]:
|
||||
fmt = Link.MD
|
||||
elif style in ["combined", "html", None]:
|
||||
fmt = Link.HTML
|
||||
def format(url: str, text: str, style: enums.ParseMode):
|
||||
if style == enums.ParseMode.MARKDOWN:
|
||||
fmt = Link.MARKDOWN
|
||||
else:
|
||||
raise ValueError(f"{style} is not a valid style/parse mode")
|
||||
fmt = Link.HTML
|
||||
|
||||
return fmt.format(url=url, text=html.escape(text))
|
||||
|
||||
@ -103,16 +102,8 @@ class User(Object, Update):
|
||||
last_name (``str``, *optional*):
|
||||
User's or bot's last name.
|
||||
|
||||
status (``str``, *optional*):
|
||||
User's Last Seen & Online status.
|
||||
Can be one of the following:
|
||||
"*online*", user is online right now.
|
||||
"*offline*", user is currently offline.
|
||||
"*recently*", user with hidden last seen time who was online between 1 second and 2-3 days ago.
|
||||
"*within_week*", user with hidden last seen time who was online between 2-3 and seven days ago.
|
||||
"*within_month*", user with hidden last seen time who was online between 6-7 days and a month ago.
|
||||
"*long_time_ago*", blocked user or user with hidden last seen time who was online more than a month ago.
|
||||
*None*, for bots.
|
||||
status (:obj:`~pyrogram.enums.UserStatus`, *optional*):
|
||||
User's last seen & online status. *None*, for bots.
|
||||
|
||||
last_online_date (``int``, *optional*):
|
||||
Last online date of a user, unix time. Only available in case status is "*offline*".
|
||||
@ -237,17 +228,17 @@ class User(Object, Update):
|
||||
@staticmethod
|
||||
def _parse_status(user_status: "raw.base.UserStatus", is_bot: bool = False):
|
||||
if isinstance(user_status, raw.types.UserStatusOnline):
|
||||
status, date = "online", user_status.expires
|
||||
status, date = enums.UserStatus.ONLINE, user_status.expires
|
||||
elif isinstance(user_status, raw.types.UserStatusOffline):
|
||||
status, date = "offline", user_status.was_online
|
||||
status, date = enums.UserStatus.OFFLINE, user_status.was_online
|
||||
elif isinstance(user_status, raw.types.UserStatusRecently):
|
||||
status, date = "recently", None
|
||||
status, date = enums.UserStatus.RECENTLY, None
|
||||
elif isinstance(user_status, raw.types.UserStatusLastWeek):
|
||||
status, date = "within_week", None
|
||||
status, date = enums.UserStatus.LAST_WEEK, None
|
||||
elif isinstance(user_status, raw.types.UserStatusLastMonth):
|
||||
status, date = "within_month", None
|
||||
status, date = enums.UserStatus.LAST_MONTH, None
|
||||
else:
|
||||
status, date = "long_time_ago", None
|
||||
status, date = enums.UserStatus.LONG_AGO, None
|
||||
|
||||
last_online_date = None
|
||||
next_offline_date = None
|
||||
@ -255,10 +246,10 @@ class User(Object, Update):
|
||||
if is_bot:
|
||||
status = None
|
||||
|
||||
if status == "online":
|
||||
if status == enums.UserStatus.ONLINE:
|
||||
next_offline_date = date
|
||||
|
||||
if status == "offline":
|
||||
if status == enums.UserStatus.OFFLINE:
|
||||
last_online_date = date
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user