Skip to content

Commit 2267109

Browse files
authored
Merge pull request #2131 from Badiboy/master
Deprecation: stubs for Message fields in InaccessibleMessage
2 parents a1604db + 34cf549 commit 2267109

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

telebot/types.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,13 +1451,13 @@ def func(upd_text, subst_type=None, url=None, user=None, custom_emoji_id=None):
14511451
html_text += func(utf16_text[offset * 2 : entity.offset * 2])
14521452
offset = entity.offset
14531453

1454-
new_string = func(utf16_text[offset * 2 : (offset + entity.length) * 2], entity.type, entity.url, entity.user, entity.custom_emoji_id)
1454+
new_string = func(utf16_text[offset * 2 : (offset + entity.length) * 2], subst_type=entity.type, url=entity.url, user=entity.user, custom_emoji_id=entity.custom_emoji_id)
14551455
start_index = len(html_text)
14561456
html_text += new_string
14571457
offset += entity.length
14581458
end_index = len(html_text)
14591459
elif entity.offset == offset:
1460-
new_string = func(utf16_text[offset * 2 : (offset + entity.length) * 2], entity.type, entity.url, entity.user, entity.custom_emoji_id)
1460+
new_string = func(utf16_text[offset * 2 : (offset + entity.length) * 2], subst_type=entity.type, url=entity.url, user=entity.user, custom_emoji_id=entity.custom_emoji_id)
14611461
start_index = len(html_text)
14621462
html_text += new_string
14631463
end_index = len(html_text)
@@ -1468,7 +1468,8 @@ def func(upd_text, subst_type=None, url=None, user=None, custom_emoji_id=None):
14681468
# And, here we are replacing previous string with a new html-rendered text(previous string is already html-rendered,
14691469
# And we don't change it).
14701470
entity_string = html_text[start_index : end_index].encode("utf-16-le")
1471-
formatted_string = func(entity_string, entity.type, entity.url, entity.user, entity.custom_emoji_id).replace("&amp;", "&").replace("&lt;", "<").replace("&gt;",">")
1471+
formatted_string = func(entity_string, subst_type=entity.type, url=entity.url, user=entity.user, custom_emoji_id=entity.custom_emoji_id).\
1472+
replace("&amp;", "&").replace("&lt;", "<").replace("&gt;",">")
14721473
html_text = html_text[:start_index] + formatted_string + html_text[end_index:]
14731474
end_index = len(html_text)
14741475

@@ -9214,3 +9215,28 @@ def __init__(self, chat, message_id, date, **kwargs):
92149215
self.chat = chat
92159216
self.message_id = message_id
92169217
self.date = date
9218+
9219+
@staticmethod
9220+
def __universal_deprecation(property_name):
9221+
logger.warning(f'Deprecation warning: the filed "{property_name}" is not accessible for InaccessibleMessage. You should check if your object is Message instance before access.')
9222+
return None
9223+
9224+
def __getattr__(self, item):
9225+
if item in [
9226+
'message_thread_id', 'from_user', 'sender_chat', 'forward_origin', 'is_topic_message',
9227+
'is_automatic_forward', 'reply_to_message', 'external_reply', 'qoute', 'via_bot', 'edit_date',
9228+
'has_protected_content', 'media_group_id', 'author_signature', 'text', 'entities', 'link_preview_options',
9229+
'animation', 'audio', 'document', 'photo', 'sticker', 'story', 'video', 'video_note', 'voice', 'caption',
9230+
'caption_entities', 'has_media_spoiler', 'contact', 'dice', 'game', 'poll', 'venue', 'location',
9231+
'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo',
9232+
'group_chat_created', 'supergroup_chat_created', 'channel_chat_created', 'message_auto_delete_timer_changed',
9233+
'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message', 'invoice', 'successful_payment',
9234+
'users_shared', 'chat_shared', 'connected_website', 'write_access_allowed', 'passport_data',
9235+
'proximity_alert_triggered', 'forum_topic_created', 'forum_topic_edited', 'forum_topic_closed',
9236+
'forum_topic_reopened', 'general_forum_topic_hidden', 'general_forum_topic_unhidden', 'giveaway_created',
9237+
'giveaway', 'giveaway_winners', 'giveaway_completed', 'video_chat_scheduled', 'video_chat_started',
9238+
'video_chat_ended', 'video_chat_participants_invited', 'web_app_data', 'reply_markup'
9239+
]:
9240+
return self.__universal_deprecation(item)
9241+
else:
9242+
raise AttributeError(f'"{self.__class__.__name__}" object has no attribute "{item}"')

0 commit comments

Comments
 (0)