mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-17 18:46:40 +00:00
Use inline result mime to infer the result type
This commit is contained in:
parent
312dac90a3
commit
3ff09f7b91
@ -3,6 +3,20 @@ import hashlib
|
|||||||
from .. import functions, types
|
from .. import functions, types
|
||||||
from ... import utils
|
from ... import utils
|
||||||
|
|
||||||
|
_TYPE_TO_MIMES = {
|
||||||
|
'gif': ['image/gif'], # 'video/mp4' too, but that's used for video
|
||||||
|
'article': ['text/html'],
|
||||||
|
'audio': ['audio/mpeg'],
|
||||||
|
'contact': [],
|
||||||
|
'file': ['application/pdf', 'application/zip'], # actually any
|
||||||
|
'geo': [],
|
||||||
|
'photo': ['image/jpeg'],
|
||||||
|
'sticker': ['image/webp', 'application/x-tgsticker'],
|
||||||
|
'venue': [],
|
||||||
|
'video': ['video/mp4'], # tdlib includes text/html for some reason
|
||||||
|
'voice': ['audio/ogg'],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class InlineBuilder:
|
class InlineBuilder:
|
||||||
"""
|
"""
|
||||||
@ -239,6 +253,8 @@ class InlineBuilder:
|
|||||||
type (`str`, optional):
|
type (`str`, optional):
|
||||||
The type of the document. May be one of: article, audio,
|
The type of the document. May be one of: article, audio,
|
||||||
contact, file, geo, gif, photo, sticker, venue, video, voice.
|
contact, file, geo, gif, photo, sticker, venue, video, voice.
|
||||||
|
It will be automatically set if ``mime_type`` is specified,
|
||||||
|
and default to ``'file'`` if no matching mime type is found.
|
||||||
|
|
||||||
include_media (`bool`, optional):
|
include_media (`bool`, optional):
|
||||||
Whether the document file used to display the result should be
|
Whether the document file used to display the result should be
|
||||||
@ -270,7 +286,14 @@ class InlineBuilder:
|
|||||||
if type is None:
|
if type is None:
|
||||||
if voice_note:
|
if voice_note:
|
||||||
type = 'voice'
|
type = 'voice'
|
||||||
else:
|
elif mime_type:
|
||||||
|
for ty, mimes in _TYPE_TO_MIMES.items():
|
||||||
|
for mime in mimes:
|
||||||
|
if mime_type == mime:
|
||||||
|
type = ty
|
||||||
|
break
|
||||||
|
|
||||||
|
if type is None:
|
||||||
type = 'file'
|
type = 'file'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -9,6 +9,7 @@ ADMIN_RANK_INVALID,400,The given admin title or rank was invalid (possibly large
|
|||||||
API_ID_INVALID,400,The api_id/api_hash combination is invalid
|
API_ID_INVALID,400,The api_id/api_hash combination is invalid
|
||||||
API_ID_PUBLISHED_FLOOD,400,"This API id was published somewhere, you can't use it now"
|
API_ID_PUBLISHED_FLOOD,400,"This API id was published somewhere, you can't use it now"
|
||||||
ARTICLE_TITLE_EMPTY,400,The title of the article is empty
|
ARTICLE_TITLE_EMPTY,400,The title of the article is empty
|
||||||
|
AUDIO_TITLE_EMPTY,400,The title attribute of the audio must be non-empty
|
||||||
AUTH_BYTES_INVALID,400,The provided authorization is invalid
|
AUTH_BYTES_INVALID,400,The provided authorization is invalid
|
||||||
AUTH_KEY_DUPLICATED,406,"The authorization key (session file) was used under two different IP addresses simultaneously, and can no longer be used. Use the same session exclusively, or use different sessions"
|
AUTH_KEY_DUPLICATED,406,"The authorization key (session file) was used under two different IP addresses simultaneously, and can no longer be used. Use the same session exclusively, or use different sessions"
|
||||||
AUTH_KEY_INVALID,401,The key is invalid
|
AUTH_KEY_INVALID,401,The key is invalid
|
||||||
|
|
@ -282,7 +282,7 @@ messages.setBotPrecheckoutResults,both,ERROR_TEXT_EMPTY
|
|||||||
messages.setBotShippingResults,both,QUERY_ID_INVALID
|
messages.setBotShippingResults,both,QUERY_ID_INVALID
|
||||||
messages.setEncryptedTyping,user,CHAT_ID_INVALID
|
messages.setEncryptedTyping,user,CHAT_ID_INVALID
|
||||||
messages.setGameScore,bot,PEER_ID_INVALID USER_BOT_REQUIRED
|
messages.setGameScore,bot,PEER_ID_INVALID USER_BOT_REQUIRED
|
||||||
messages.setInlineBotResults,bot,ARTICLE_TITLE_EMPTY BUTTON_DATA_INVALID BUTTON_TYPE_INVALID BUTTON_URL_INVALID MESSAGE_EMPTY PHOTO_CONTENT_URL_EMPTY PHOTO_THUMB_URL_EMPTY QUERY_ID_INVALID REPLY_MARKUP_INVALID RESULT_TYPE_INVALID SEND_MESSAGE_MEDIA_INVALID SEND_MESSAGE_TYPE_INVALID START_PARAM_INVALID STICKER_DOCUMENT_INVALID USER_BOT_INVALID WEBDOCUMENT_URL_INVALID
|
messages.setInlineBotResults,bot,ARTICLE_TITLE_EMPTY AUDIO_TITLE_EMPTY BUTTON_DATA_INVALID BUTTON_TYPE_INVALID BUTTON_URL_INVALID MESSAGE_EMPTY PHOTO_CONTENT_URL_EMPTY PHOTO_THUMB_URL_EMPTY QUERY_ID_INVALID REPLY_MARKUP_INVALID RESULT_TYPE_INVALID SEND_MESSAGE_MEDIA_INVALID SEND_MESSAGE_TYPE_INVALID START_PARAM_INVALID STICKER_DOCUMENT_INVALID USER_BOT_INVALID WEBDOCUMENT_URL_INVALID
|
||||||
messages.setInlineGameScore,bot,MESSAGE_ID_INVALID USER_BOT_REQUIRED
|
messages.setInlineGameScore,bot,MESSAGE_ID_INVALID USER_BOT_REQUIRED
|
||||||
messages.setTyping,both,CHANNEL_INVALID CHANNEL_PRIVATE CHAT_ID_INVALID CHAT_WRITE_FORBIDDEN PEER_ID_INVALID USER_BANNED_IN_CHANNEL USER_IS_BLOCKED USER_IS_BOT
|
messages.setTyping,both,CHANNEL_INVALID CHANNEL_PRIVATE CHAT_ID_INVALID CHAT_WRITE_FORBIDDEN PEER_ID_INVALID USER_BANNED_IN_CHANNEL USER_IS_BLOCKED USER_IS_BOT
|
||||||
messages.startBot,user,BOT_INVALID PEER_ID_INVALID START_PARAM_EMPTY START_PARAM_INVALID
|
messages.startBot,user,BOT_INVALID PEER_ID_INVALID START_PARAM_EMPTY START_PARAM_INVALID
|
||||||
|
|
Loading…
Reference in New Issue
Block a user