Remove ChatAction module too
It's pretty much useless, better just use strings
This commit is contained in:
parent
3a494a478f
commit
6530c7e293
@ -1,5 +0,0 @@
|
|||||||
ChatAction
|
|
||||||
==========
|
|
||||||
|
|
||||||
.. autoclass:: pyrogram.ChatAction
|
|
||||||
:members:
|
|
@ -14,7 +14,6 @@ after the well established Telegram Bot API methods, thus offering a familiar lo
|
|||||||
Handlers
|
Handlers
|
||||||
Decorators
|
Decorators
|
||||||
Filters
|
Filters
|
||||||
ChatAction
|
|
||||||
Errors
|
Errors
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from .client import Client
|
from .client import Client
|
||||||
from .ext import BaseClient, ChatAction, Emoji
|
from .ext import BaseClient, Emoji
|
||||||
from .filters import Filters
|
from .filters import Filters
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Client", "BaseClient", "ChatAction", "Emoji", "Filters",
|
"Client", "BaseClient", "Emoji", "Filters",
|
||||||
]
|
]
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from .base_client import BaseClient
|
from .base_client import BaseClient
|
||||||
from .chat_action import ChatAction
|
|
||||||
from .dispatcher import Dispatcher
|
from .dispatcher import Dispatcher
|
||||||
from .emoji import Emoji
|
from .emoji import Emoji
|
||||||
from .syncer import Syncer
|
from .syncer import Syncer
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
||||||
# Copyright (C) 2017-2019 Dan Tès <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
|
|
||||||
|
|
||||||
from pyrogram.api import types
|
|
||||||
|
|
||||||
|
|
||||||
class ChatAction(Enum):
|
|
||||||
"""This enumeration provides a convenient access to all Chat Actions available.
|
|
||||||
Chat Actions are intended to be used with
|
|
||||||
:meth:`send_chat_action() <pyrogram.Client.send_chat_action>`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
CANCEL = types.SendMessageCancelAction
|
|
||||||
"""Cancels any chat action currently displayed."""
|
|
||||||
|
|
||||||
TYPING = types.SendMessageTypingAction
|
|
||||||
"""User is typing a text message."""
|
|
||||||
|
|
||||||
PLAYING = types.SendMessageGamePlayAction
|
|
||||||
"""User is playing a game."""
|
|
||||||
|
|
||||||
CHOOSE_CONTACT = types.SendMessageChooseContactAction
|
|
||||||
"""User is choosing a contact to share."""
|
|
||||||
|
|
||||||
UPLOAD_PHOTO = types.SendMessageUploadPhotoAction
|
|
||||||
"""User is uploading a photo."""
|
|
||||||
|
|
||||||
RECORD_VIDEO = types.SendMessageRecordVideoAction
|
|
||||||
"""User is recording a video."""
|
|
||||||
|
|
||||||
UPLOAD_VIDEO = types.SendMessageUploadVideoAction
|
|
||||||
"""User is uploading a video."""
|
|
||||||
|
|
||||||
RECORD_AUDIO = types.SendMessageRecordAudioAction
|
|
||||||
"""User is recording an audio message."""
|
|
||||||
|
|
||||||
UPLOAD_AUDIO = types.SendMessageUploadAudioAction
|
|
||||||
"""User is uploading an audio message."""
|
|
||||||
|
|
||||||
UPLOAD_DOCUMENT = types.SendMessageUploadDocumentAction
|
|
||||||
"""User is uploading a generic document."""
|
|
||||||
|
|
||||||
FIND_LOCATION = types.SendMessageGeoLocationAction
|
|
||||||
"""User is searching for a location on the map."""
|
|
||||||
|
|
||||||
RECORD_VIDEO_NOTE = types.SendMessageRecordRoundAction
|
|
||||||
"""User is recording a round video note."""
|
|
||||||
|
|
||||||
UPLOAD_VIDEO_NOTE = types.SendMessageUploadRoundAction
|
|
||||||
"""User is uploading a round video note."""
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_string(action: str) -> "ChatAction":
|
|
||||||
for a in ChatAction:
|
|
||||||
if a.name.lower() == action.lower():
|
|
||||||
return a
|
|
||||||
|
|
||||||
raise ValueError("Invalid ChatAction: '{}'. Possible types are {}".format(
|
|
||||||
action, [x.name.lower() for x in ChatAction]
|
|
||||||
))
|
|
@ -18,17 +18,32 @@
|
|||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions, types
|
||||||
from pyrogram.client.ext import BaseClient, ChatAction
|
from pyrogram.client.ext import BaseClient
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class ChatAction:
|
||||||
|
TYPING = types.SendMessageTypingAction
|
||||||
|
UPLOAD_PHOTO = types.SendMessageUploadPhotoAction
|
||||||
|
RECORD_VIDEO = types.SendMessageRecordVideoAction
|
||||||
|
UPLOAD_VIDEO = types.SendMessageUploadVideoAction
|
||||||
|
RECORD_AUDIO = types.SendMessageRecordAudioAction
|
||||||
|
UPLOAD_AUDIO = types.SendMessageUploadAudioAction
|
||||||
|
UPLOAD_DOCUMENT = types.SendMessageUploadDocumentAction
|
||||||
|
FIND_LOCATION = types.SendMessageGeoLocationAction
|
||||||
|
RECORD_VIDEO_NOTE = types.SendMessageRecordRoundAction
|
||||||
|
UPLOAD_VIDEO_NOTE = types.SendMessageUploadRoundAction
|
||||||
|
PLAYING = types.SendMessageGamePlayAction
|
||||||
|
CHOOSE_CONTACT = types.SendMessageChooseContactAction
|
||||||
|
CANCEL = types.SendMessageCancelAction
|
||||||
|
|
||||||
|
|
||||||
|
POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), ChatAction.__dict__.keys())))
|
||||||
|
|
||||||
|
|
||||||
class SendChatAction(BaseClient):
|
class SendChatAction(BaseClient):
|
||||||
def send_chat_action(
|
def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
|
||||||
self,
|
|
||||||
chat_id: Union[int, str],
|
|
||||||
action: Union[ChatAction, str],
|
|
||||||
progress: int = 0
|
|
||||||
):
|
|
||||||
"""Use this method when you need to tell the other party that something is happening on your side.
|
"""Use this method when you need to tell the other party that something is happening on your side.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -37,15 +52,13 @@ class SendChatAction(BaseClient):
|
|||||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
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).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
action (:obj:`ChatAction` | ``str``):
|
action (``str``):
|
||||||
Type of action to broadcast.
|
Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
|
||||||
Choose one from the :class:`ChatAction` enumeration,
|
text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
|
||||||
depending on what the user is about to receive.
|
*"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
|
||||||
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
|
*"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
|
||||||
|
*"choose_contact"* for contacts, *"playing"* for games or *"cancel"* to cancel any chat action currently
|
||||||
progress (``int``, *optional*):
|
displayed.
|
||||||
Progress of the upload process.
|
|
||||||
Currently useless because official clients don't seem to be handling this.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
``bool``: On success, True is returned.
|
``bool``: On success, True is returned.
|
||||||
@ -55,14 +68,14 @@ class SendChatAction(BaseClient):
|
|||||||
ValueError: In case the provided string is not a valid ChatAction.
|
ValueError: In case the provided string is not a valid ChatAction.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Resolve Enum type
|
try:
|
||||||
if isinstance(action, str):
|
action = ChatAction.__dict__[action.upper()]
|
||||||
action = ChatAction.from_string(action).value
|
except KeyError:
|
||||||
elif isinstance(action, ChatAction):
|
raise ValueError("Invalid chat action '{}'. Possible values are: {}".format(
|
||||||
action = action.value
|
action, json.dumps(POSSIBLE_VALUES, indent=4))) from None
|
||||||
|
|
||||||
if "Upload" in action.__name__:
|
if "Upload" in action.__name__:
|
||||||
action = action(progress=progress)
|
action = action(progress=0)
|
||||||
else:
|
else:
|
||||||
action = action()
|
action = action()
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ from typing import List, Match, Union
|
|||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from pyrogram.errors import MessageIdsEmpty
|
from pyrogram.errors import MessageIdsEmpty
|
||||||
from pyrogram.client.ext import ChatAction
|
|
||||||
from pyrogram.client.types.input_media import InputMedia
|
from pyrogram.client.types.input_media import InputMedia
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
from .location import Location
|
from .location import Location
|
||||||
@ -1077,11 +1076,7 @@ class Message(PyrogramType, Update):
|
|||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
|
||||||
def reply_chat_action(
|
def reply_chat_action(self, action: str) -> bool:
|
||||||
self,
|
|
||||||
action: Union[ChatAction, str],
|
|
||||||
progress: int = 0
|
|
||||||
) -> "Message":
|
|
||||||
"""Bound method *reply_chat_action* of :obj:`Message`.
|
"""Bound method *reply_chat_action* of :obj:`Message`.
|
||||||
|
|
||||||
Use as a shortcut for:
|
Use as a shortcut for:
|
||||||
@ -1099,27 +1094,24 @@ class Message(PyrogramType, Update):
|
|||||||
message.reply_chat_action("typing")
|
message.reply_chat_action("typing")
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
action (:obj:`ChatAction <pyrogram.ChatAction>` | ``str``):
|
action (``str``):
|
||||||
Type of action to broadcast.
|
Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
|
||||||
Choose one from the :class:`ChatAction <pyrogram.ChatAction>` enumeration,
|
text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
|
||||||
depending on what the user is about to receive.
|
*"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
|
||||||
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
|
*"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
|
||||||
|
*"choose_contact"* for contacts, *"playing"* for games or *"cancel"* to cancel any chat action currently
|
||||||
progress (``int``, *optional*):
|
displayed.
|
||||||
Progress of the upload process.
|
|
||||||
Currently useless because official clients don't seem to be handling this.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
On success, True is returned.
|
``bool``: On success, True is returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
``ValueError`` if the provided string is not a valid ChatAction.
|
ValueError: In case the provided string is not a valid chat action.
|
||||||
"""
|
"""
|
||||||
return self._client.send_chat_action(
|
return self._client.send_chat_action(
|
||||||
chat_id=self.chat.id,
|
chat_id=self.chat.id,
|
||||||
action=action,
|
action=action
|
||||||
progress=progress
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def reply_contact(
|
def reply_contact(
|
||||||
|
Loading…
Reference in New Issue
Block a user