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
|
||||
Decorators
|
||||
Filters
|
||||
ChatAction
|
||||
Errors
|
||||
|
||||
|
||||
|
@ -17,9 +17,9 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .client import Client
|
||||
from .ext import BaseClient, ChatAction, Emoji
|
||||
from .ext import BaseClient, Emoji
|
||||
from .filters import Filters
|
||||
|
||||
__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/>.
|
||||
|
||||
from .base_client import BaseClient
|
||||
from .chat_action import ChatAction
|
||||
from .dispatcher import Dispatcher
|
||||
from .emoji import Emoji
|
||||
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 pyrogram.api import functions
|
||||
from pyrogram.client.ext import BaseClient, ChatAction
|
||||
from pyrogram.api import functions, types
|
||||
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):
|
||||
def send_chat_action(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
action: Union[ChatAction, str],
|
||||
progress: int = 0
|
||||
):
|
||||
def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
|
||||
"""Use this method when you need to tell the other party that something is happening on your side.
|
||||
|
||||
Parameters:
|
||||
@ -37,15 +52,13 @@ class SendChatAction(BaseClient):
|
||||
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 (:obj:`ChatAction` | ``str``):
|
||||
Type of action to broadcast.
|
||||
Choose one from the :class:`ChatAction` enumeration,
|
||||
depending on what the user is about to receive.
|
||||
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
|
||||
|
||||
progress (``int``, *optional*):
|
||||
Progress of the upload process.
|
||||
Currently useless because official clients don't seem to be handling this.
|
||||
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 or *"cancel"* to cancel any chat action currently
|
||||
displayed.
|
||||
|
||||
Returns:
|
||||
``bool``: On success, True is returned.
|
||||
@ -55,14 +68,14 @@ class SendChatAction(BaseClient):
|
||||
ValueError: In case the provided string is not a valid ChatAction.
|
||||
"""
|
||||
|
||||
# Resolve Enum type
|
||||
if isinstance(action, str):
|
||||
action = ChatAction.from_string(action).value
|
||||
elif isinstance(action, ChatAction):
|
||||
action = action.value
|
||||
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
|
||||
|
||||
if "Upload" in action.__name__:
|
||||
action = action(progress=progress)
|
||||
action = action(progress=0)
|
||||
else:
|
||||
action = action()
|
||||
|
||||
|
@ -22,7 +22,6 @@ from typing import List, Match, Union
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
from pyrogram.errors import MessageIdsEmpty
|
||||
from pyrogram.client.ext import ChatAction
|
||||
from pyrogram.client.types.input_media import InputMedia
|
||||
from .contact import Contact
|
||||
from .location import Location
|
||||
@ -1077,11 +1076,7 @@ class Message(PyrogramType, Update):
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
def reply_chat_action(
|
||||
self,
|
||||
action: Union[ChatAction, str],
|
||||
progress: int = 0
|
||||
) -> "Message":
|
||||
def reply_chat_action(self, action: str) -> bool:
|
||||
"""Bound method *reply_chat_action* of :obj:`Message`.
|
||||
|
||||
Use as a shortcut for:
|
||||
@ -1099,27 +1094,24 @@ class Message(PyrogramType, Update):
|
||||
message.reply_chat_action("typing")
|
||||
|
||||
Parameters:
|
||||
action (:obj:`ChatAction <pyrogram.ChatAction>` | ``str``):
|
||||
Type of action to broadcast.
|
||||
Choose one from the :class:`ChatAction <pyrogram.ChatAction>` enumeration,
|
||||
depending on what the user is about to receive.
|
||||
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
|
||||
|
||||
progress (``int``, *optional*):
|
||||
Progress of the upload process.
|
||||
Currently useless because official clients don't seem to be handling this.
|
||||
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 or *"cancel"* to cancel any chat action currently
|
||||
displayed.
|
||||
|
||||
Returns:
|
||||
On success, True is returned.
|
||||
``bool``: On success, True is returned.
|
||||
|
||||
Raises:
|
||||
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(
|
||||
chat_id=self.chat.id,
|
||||
action=action,
|
||||
progress=progress
|
||||
action=action
|
||||
)
|
||||
|
||||
def reply_contact(
|
||||
|
Loading…
Reference in New Issue
Block a user