Rename ACTIONS -> CHAT_ACTIONS

This commit is contained in:
Dan 2017-12-06 21:57:46 +01:00
parent e2a5deaf17
commit 5c11f42933

View File

@ -49,6 +49,22 @@ Config = namedtuple("Config", ["api_id", "api_hash"])
class Client: class Client:
DIALOGS_AT_ONCE = 100 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): def __init__(self, session_name: str, test_mode: bool = False):
self.session_name = session_name self.session_name = session_name
self.test_mode = test_mode self.test_mode = test_mode
@ -454,27 +470,11 @@ class Client:
) )
) )
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 send_chat_action(self, chat_id: int or str, action: str, progress: int = 0): def send_chat_action(self, chat_id: int or str, action: str, progress: int = 0):
return self.send( return self.send(
functions.messages.SetTyping( functions.messages.SetTyping(
peer=self.resolve_peer(chat_id), peer=self.resolve_peer(chat_id),
action=self.ACTIONS.get( action=self.CHAT_ACTIONS.get(
action.lower() action.lower()
)(progress=progress) )(progress=progress)
) )