Move chat actions to a separate class
This commit is contained in:
parent
bfe82182e1
commit
e7c44933c2
@ -20,4 +20,5 @@ __copyright__ = "Copyright (C) 2017 Dan Tès <https://github.com/delivrance>"
|
||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||
__version__ = "0.1.2"
|
||||
|
||||
from .client import ChatAction
|
||||
from .client import Client
|
||||
|
@ -16,4 +16,5 @@
|
||||
# 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 .client import Client
|
||||
|
35
pyrogram/client/chat_action.py
Normal file
35
pyrogram/client/chat_action.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017 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 pyrogram.api import types
|
||||
|
||||
|
||||
class ChatAction:
|
||||
CANCEL = types.SendMessageCancelAction
|
||||
TYPING = types.SendMessageTypingAction
|
||||
PLAYING = types.SendMessageGamePlayAction
|
||||
CHOOSE_CONTACT = types.SendMessageChooseContactAction
|
||||
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
|
@ -49,22 +49,6 @@ Config = namedtuple("Config", ["api_id", "api_hash"])
|
||||
class Client:
|
||||
DIALOGS_AT_ONCE = 100
|
||||
|
||||
CHAT_ACTIONS = {
|
||||
"cancel": types.SendMessageCancelAction,
|
||||
"typing": types.SendMessageTypingAction,
|
||||
"playing": types.SendMessageGamePlayAction,
|
||||
"choose_contact": types.SendMessageChooseContactAction,
|
||||
"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,
|
||||
}
|
||||
|
||||
def __init__(self, session_name: str, test_mode: bool = False):
|
||||
self.session_name = session_name
|
||||
self.test_mode = test_mode
|
||||
@ -477,15 +461,12 @@ class Client:
|
||||
|
||||
def send_chat_action(self,
|
||||
chat_id: int or str,
|
||||
action: str,
|
||||
action: callable,
|
||||
progress: int = 0):
|
||||
return self.send(
|
||||
functions.messages.SetTyping(
|
||||
peer=self.resolve_peer(chat_id),
|
||||
action=self.CHAT_ACTIONS.get(
|
||||
action.lower(),
|
||||
types.SendMessageTypingAction
|
||||
)(progress=progress)
|
||||
action=action(progress=progress)
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user