Skip to content

Commit 6530c7e

Browse files
committed
Remove ChatAction module too
It's pretty much useless, better just use strings
1 parent 3a494a4 commit 6530c7e

File tree

7 files changed

+49
-128
lines changed

7 files changed

+49
-128
lines changed

docs/source/pyrogram/ChatAction.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/source/pyrogram/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ after the well established Telegram Bot API methods, thus offering a familiar lo
1414
Handlers
1515
Decorators
1616
Filters
17-
ChatAction
1817
Errors
1918

2019

pyrogram/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from .client import Client
20-
from .ext import BaseClient, ChatAction, Emoji
20+
from .ext import BaseClient, Emoji
2121
from .filters import Filters
2222

2323
__all__ = [
24-
"Client", "BaseClient", "ChatAction", "Emoji", "Filters",
24+
"Client", "BaseClient", "Emoji", "Filters",
2525
]

pyrogram/client/ext/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from .base_client import BaseClient
20-
from .chat_action import ChatAction
2120
from .dispatcher import Dispatcher
2221
from .emoji import Emoji
2322
from .syncer import Syncer

pyrogram/client/ext/chat_action.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

pyrogram/client/methods/messages/send_chat_action.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,32 @@
1818

1919
from typing import Union
2020

21-
from pyrogram.api import functions
22-
from pyrogram.client.ext import BaseClient, ChatAction
21+
from pyrogram.api import functions, types
22+
from pyrogram.client.ext import BaseClient
23+
import json
24+
25+
26+
class ChatAction:
27+
TYPING = types.SendMessageTypingAction
28+
UPLOAD_PHOTO = types.SendMessageUploadPhotoAction
29+
RECORD_VIDEO = types.SendMessageRecordVideoAction
30+
UPLOAD_VIDEO = types.SendMessageUploadVideoAction
31+
RECORD_AUDIO = types.SendMessageRecordAudioAction
32+
UPLOAD_AUDIO = types.SendMessageUploadAudioAction
33+
UPLOAD_DOCUMENT = types.SendMessageUploadDocumentAction
34+
FIND_LOCATION = types.SendMessageGeoLocationAction
35+
RECORD_VIDEO_NOTE = types.SendMessageRecordRoundAction
36+
UPLOAD_VIDEO_NOTE = types.SendMessageUploadRoundAction
37+
PLAYING = types.SendMessageGamePlayAction
38+
CHOOSE_CONTACT = types.SendMessageChooseContactAction
39+
CANCEL = types.SendMessageCancelAction
40+
41+
42+
POSSIBLE_VALUES = list(map(lambda x: x.lower(), filter(lambda x: not x.startswith("__"), ChatAction.__dict__.keys())))
2343

2444

2545
class SendChatAction(BaseClient):
26-
def send_chat_action(
27-
self,
28-
chat_id: Union[int, str],
29-
action: Union[ChatAction, str],
30-
progress: int = 0
31-
):
46+
def send_chat_action(self, chat_id: Union[int, str], action: str) -> bool:
3247
"""Use this method when you need to tell the other party that something is happening on your side.
3348
3449
Parameters:
@@ -37,15 +52,13 @@ def send_chat_action(
3752
For your personal cloud (Saved Messages) you can simply use "me" or "self".
3853
For a contact that exists in your Telegram address book you can use his phone number (str).
3954
40-
action (:obj:`ChatAction` | ``str``):
41-
Type of action to broadcast.
42-
Choose one from the :class:`ChatAction` enumeration,
43-
depending on what the user is about to receive.
44-
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
45-
46-
progress (``int``, *optional*):
47-
Progress of the upload process.
48-
Currently useless because official clients don't seem to be handling this.
55+
action (``str``):
56+
Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
57+
text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
58+
*"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
59+
*"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
60+
*"choose_contact"* for contacts, *"playing"* for games or *"cancel"* to cancel any chat action currently
61+
displayed.
4962
5063
Returns:
5164
``bool``: On success, True is returned.
@@ -55,14 +68,14 @@ def send_chat_action(
5568
ValueError: In case the provided string is not a valid ChatAction.
5669
"""
5770

58-
# Resolve Enum type
59-
if isinstance(action, str):
60-
action = ChatAction.from_string(action).value
61-
elif isinstance(action, ChatAction):
62-
action = action.value
71+
try:
72+
action = ChatAction.__dict__[action.upper()]
73+
except KeyError:
74+
raise ValueError("Invalid chat action '{}'. Possible values are: {}".format(
75+
action, json.dumps(POSSIBLE_VALUES, indent=4))) from None
6376

6477
if "Upload" in action.__name__:
65-
action = action(progress=progress)
78+
action = action(progress=0)
6679
else:
6780
action = action()
6881

pyrogram/client/types/messages_and_media/message.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import pyrogram
2323
from pyrogram.api import types
2424
from pyrogram.errors import MessageIdsEmpty
25-
from pyrogram.client.ext import ChatAction
2625
from pyrogram.client.types.input_media import InputMedia
2726
from .contact import Contact
2827
from .location import Location
@@ -1077,11 +1076,7 @@ def reply_cached_media(
10771076
reply_markup=reply_markup
10781077
)
10791078

1080-
def reply_chat_action(
1081-
self,
1082-
action: Union[ChatAction, str],
1083-
progress: int = 0
1084-
) -> "Message":
1079+
def reply_chat_action(self, action: str) -> bool:
10851080
"""Bound method *reply_chat_action* of :obj:`Message`.
10861081
10871082
Use as a shortcut for:
@@ -1099,27 +1094,24 @@ def reply_chat_action(
10991094
message.reply_chat_action("typing")
11001095
11011096
Parameters:
1102-
action (:obj:`ChatAction <pyrogram.ChatAction>` | ``str``):
1103-
Type of action to broadcast.
1104-
Choose one from the :class:`ChatAction <pyrogram.ChatAction>` enumeration,
1105-
depending on what the user is about to receive.
1106-
You can also provide a string (e.g. "typing", "upload_photo", "record_audio", ...).
1107-
1108-
progress (``int``, *optional*):
1109-
Progress of the upload process.
1110-
Currently useless because official clients don't seem to be handling this.
1097+
action (``str``):
1098+
Type of action to broadcast. Choose one, depending on what the user is about to receive: *"typing"* for
1099+
text messages, *"upload_photo"* for photos, *"record_video"* or *"upload_video"* for videos,
1100+
*"record_audio"* or *"upload_audio"* for audio files, *"upload_document"* for general files,
1101+
*"find_location"* for location data, *"record_video_note"* or *"upload_video_note"* for video notes,
1102+
*"choose_contact"* for contacts, *"playing"* for games or *"cancel"* to cancel any chat action currently
1103+
displayed.
11111104
11121105
Returns:
1113-
On success, True is returned.
1106+
``bool``: On success, True is returned.
11141107
11151108
Raises:
11161109
RPCError: In case of a Telegram RPC error.
1117-
``ValueError`` if the provided string is not a valid ChatAction.
1110+
ValueError: In case the provided string is not a valid chat action.
11181111
"""
11191112
return self._client.send_chat_action(
11201113
chat_id=self.chat.id,
1121-
action=action,
1122-
progress=progress
1114+
action=action
11231115
)
11241116

11251117
def reply_contact(

0 commit comments

Comments
 (0)