1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1881 from Cub11k/master

Create method get_media_file_id() in util.py
This commit is contained in:
Badiboy 2023-01-10 20:48:50 +03:00 committed by GitHub
commit a5af586a46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -643,6 +643,40 @@ def validate_web_app_data(token: str, raw_init_data: str):
return hmac.new(secret_key.digest(), data_check_string.encode(), sha256).hexdigest() == init_data_hash return hmac.new(secret_key.digest(), data_check_string.encode(), sha256).hexdigest() == init_data_hash
def get_media_file_id(message: types.Message, content_types: Optional[List[str]] = None):
"""
Use this method to get file id of message media if it's present.
:param message: The message to get media from
:type message: :class:`telebot.types.Message`
:param content_types: Types of media to look for, by default all types are considered.
:type content_types: :obj:`list[str]`, optional
:return: file_id or :obj:`None`
:rtype: :obj:`str` | :obj:`None`
"""
if content_types is None:
content_types = content_type_media
if "animation" in content_types and message.animation is not None:
return message.animation.file_id
elif "audio" in content_types and message.audio is not None:
return message.audio.file_id
elif "document" in content_types and message.document is not None:
return message.document.file_id
elif "photo" in content_types and message.photo is not None:
return message.photo[0].file_id
elif "sticker" in content_types and message.sticker is not None:
return message.sticker.file_id
elif "video" in content_types and message.video is not None:
return message.video.file_id
elif "video_note" in content_types and message.video_note is not None:
return message.video_note.file_id
elif "voice" in content_types and message.voice is not None:
return message.voice.file_id
__all__ = ( __all__ = (
"content_type_media", "content_type_service", "update_types", "content_type_media", "content_type_service", "update_types",
"WorkerThread", "AsyncTask", "CustomRequestResponse", "WorkerThread", "AsyncTask", "CustomRequestResponse",
@ -651,7 +685,7 @@ __all__ = (
"chunks", "generate_random_token", "pil_image_to_file", "chunks", "generate_random_token", "pil_image_to_file",
"is_command", "extract_command", "extract_arguments", "is_command", "extract_command", "extract_arguments",
"split_string", "smart_split", "escape", "user_link", "quick_markup", "split_string", "smart_split", "escape", "user_link", "quick_markup",
"antiflood", "parse_web_app_data", "validate_web_app_data", "antiflood", "get_media_file_id", "parse_web_app_data", "validate_web_app_data",
"or_set", "or_clear", "orify", "OrEvent", "per_thread", "or_set", "or_clear", "orify", "OrEvent", "per_thread",
"webhook_google_functions" "webhook_google_functions"
) )