From 38d024312e802c0b6203bdd7a980d15c75112ebf Mon Sep 17 00:00:00 2001 From: Nick80835 <24271245+Nick80835@users.noreply.github.com> Date: Sat, 1 Feb 2025 11:20:56 -0500 Subject: [PATCH 1/6] Unconditionally match text and link text in markdown Fixes cases where there's a nested [] in the text by matching until "](" is reached. This doesn't match newlines in URLs because that makes no sense. --- telethon/extensions/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telethon/extensions/markdown.py b/telethon/extensions/markdown.py index 82e90345..dda1ae5e 100644 --- a/telethon/extensions/markdown.py +++ b/telethon/extensions/markdown.py @@ -22,7 +22,7 @@ DEFAULT_DELIMITERS = { '```': MessageEntityPre } -DEFAULT_URL_RE = re.compile(r'\[([^\]]+)\]\(([^)]+)\)') +DEFAULT_URL_RE = re.compile(r'\[([\s\S]+)\]\((.+)\)') DEFAULT_URL_FORMAT = '[{0}]({1})' From 551c24f3e4fc5d64652da849495ac046115bffe5 Mon Sep 17 00:00:00 2001 From: Nick80835 <24271245+Nick80835@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:47:29 -0500 Subject: [PATCH 2/6] Fix overlapping URLs and improve overlapping in md Also remove the unused overlap function. --- telethon/extensions/markdown.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/telethon/extensions/markdown.py b/telethon/extensions/markdown.py index dda1ae5e..0a0e3291 100644 --- a/telethon/extensions/markdown.py +++ b/telethon/extensions/markdown.py @@ -26,10 +26,6 @@ DEFAULT_URL_RE = re.compile(r'\[([\s\S]+)\]\((.+)\)') DEFAULT_URL_FORMAT = '[{0}]({1})' -def overlap(a, b, x, y): - return max(a, x) < min(b, y) - - def parse(message, delimiters=None, url_re=None): """ Parses the given markdown message and returns its stripped representation @@ -90,8 +86,8 @@ def parse(message, delimiters=None, url_re=None): for ent in result: # If the end is after our start, it is affected if ent.offset + ent.length > i: - # If the old start is also before ours, it is fully enclosed - if ent.offset <= i: + # If the old start is before ours and the old end is after ours, we are fully enclosed + if ent.offset <= i and ent.offset + ent.length >= end + len(delim): ent.length -= len(delim) * 2 else: ent.length -= len(delim) @@ -119,7 +115,7 @@ def parse(message, delimiters=None, url_re=None): message[m.end():] )) - delim_size = m.end() - m.start() - len(m.group()) + delim_size = m.end() - m.start() - len(m.group(1)) for ent in result: # If the end is after our start, it is affected if ent.offset + ent.length > m.start(): From 141b620437aab660aabcb7bff521c4af5c3852e1 Mon Sep 17 00:00:00 2001 From: Nick80835 <24271245+Nick80835@users.noreply.github.com> Date: Wed, 5 Feb 2025 05:35:10 -0500 Subject: [PATCH 3/6] Make markdown URL regex less greedy Fixes multiple URLs in a single message. --- telethon/extensions/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telethon/extensions/markdown.py b/telethon/extensions/markdown.py index 0a0e3291..032f7eef 100644 --- a/telethon/extensions/markdown.py +++ b/telethon/extensions/markdown.py @@ -22,7 +22,7 @@ DEFAULT_DELIMITERS = { '```': MessageEntityPre } -DEFAULT_URL_RE = re.compile(r'\[([\s\S]+)\]\((.+)\)') +DEFAULT_URL_RE = re.compile(r'\[([\s\S]+?)\]\((.+?)\)') DEFAULT_URL_FORMAT = '[{0}]({1})' From 9762a83541c9f60a0558853a71cd33f32a4caf81 Mon Sep 17 00:00:00 2001 From: s1xu Date: Sat, 8 Feb 2025 21:53:20 +0800 Subject: [PATCH 4/6] fix: support batch sending of image URLs and video URLs in albums --- telethon/client/uploads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 091e8d15..afb1f2c2 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -516,7 +516,7 @@ class UploadMethods: )) fm = utils.get_input_media(r.photo) - elif isinstance(fm, types.InputMediaUploadedDocument): + elif isinstance(fm, (types.InputMediaUploadedDocument, types.InputMediaDocumentExternal)): r = await self(functions.messages.UploadMediaRequest( entity, media=fm )) From 1cb5ff1dd54ecfad41711fc5a4ecf36d2ad8eaf6 Mon Sep 17 00:00:00 2001 From: Nick80835 <24271245+Nick80835@users.noreply.github.com> Date: Sat, 8 Feb 2025 19:23:12 -0500 Subject: [PATCH 5/6] Consider range list-like This allows you to pass range() to things such as get_messages as ids= without first explicitly converting it to a list. --- telethon/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telethon/utils.py b/telethon/utils.py index 7f5e3e23..8f21df17 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -899,7 +899,7 @@ def is_list_like(obj): enough. Things like ``open()`` are also iterable (and probably many other things), so just support the commonly known list-like objects. """ - return isinstance(obj, (list, tuple, set, dict, GeneratorType)) + return isinstance(obj, (list, tuple, set, dict, range, GeneratorType)) def parse_phone(phone): From 592a899aabb76d2b6f3f14600a29349680b37bd8 Mon Sep 17 00:00:00 2001 From: Nick80835 <24271245+Nick80835@users.noreply.github.com> Date: Thu, 13 Feb 2025 07:57:16 -0500 Subject: [PATCH 6/6] Update to layer 199 --- telethon_generator/data/api.tl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/telethon_generator/data/api.tl b/telethon_generator/data/api.tl index e7c59e10..b2d27fd0 100644 --- a/telethon_generator/data/api.tl +++ b/telethon_generator/data/api.tl @@ -426,7 +426,7 @@ updateStarsBalance#4e80a379 balance:StarsAmount = Update; updateBusinessBotCallbackQuery#1ea2fda7 flags:# query_id:long user_id:long connection_id:string message:Message reply_to_message:flags.2?Message chat_instance:long data:flags.0?bytes = Update; updateStarsRevenueStatus#a584b019 peer:Peer status:StarsRevenueStatus = Update; updateBotPurchasedPaidMedia#283bd312 user_id:long payload:string qts:int = Update; -updatePaidReactionPrivacy#51ca7aec private:Bool = Update; +updatePaidReactionPrivacy#8b725fce private:PaidReactionPrivacy = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -599,7 +599,7 @@ messages.affectedMessages#84d19185 pts:int pts_count:int = messages.AffectedMess webPageEmpty#211a1788 flags:# id:long url:flags.0?string = WebPage; webPagePending#b0d13e47 flags:# id:long url:flags.0?string date:int = WebPage; -webPage#e89c45b2 flags:# has_large_media:flags.13?true id:long url:string display_url:string hash:int type:flags.0?string site_name:flags.1?string title:flags.2?string description:flags.3?string photo:flags.4?Photo embed_url:flags.5?string embed_type:flags.5?string embed_width:flags.6?int embed_height:flags.6?int duration:flags.7?int author:flags.8?string document:flags.9?Document cached_page:flags.10?Page attributes:flags.12?Vector = WebPage; +webPage#e89c45b2 flags:# has_large_media:flags.13?true video_cover_photo:flags.14?true id:long url:string display_url:string hash:int type:flags.0?string site_name:flags.1?string title:flags.2?string description:flags.3?string photo:flags.4?Photo embed_url:flags.5?string embed_type:flags.5?string embed_width:flags.6?int embed_height:flags.6?int duration:flags.7?int author:flags.8?string document:flags.9?Document cached_page:flags.10?Page attributes:flags.12?Vector = WebPage; webPageNotModified#7311ca11 flags:# cached_page_views:flags.0?int = WebPage; authorization#ad01d61d flags:# current:flags.0?true official_app:flags.1?true password_pending:flags.2?true encrypted_requests_disabled:flags.3?true call_requests_disabled:flags.4?true unconfirmed:flags.5?true hash:long device_model:string platform:string system_version:string api_id:int app_name:string app_version:string date_created:int date_active:int ip:string country:string region:string = Authorization; @@ -1877,7 +1877,7 @@ starsGiveawayOption#94ce852a flags:# extended:flags.0?true default:flags.1?true starsGiveawayWinnersOption#54236209 flags:# default:flags.0?true users:int per_user_stars:long = StarsGiveawayWinnersOption; starGift#2cc73c8 flags:# limited:flags.0?true sold_out:flags.1?true birthday:flags.2?true id:long sticker:Document stars:long availability_remains:flags.0?int availability_total:flags.0?int convert_stars:long first_sale_date:flags.1?int last_sale_date:flags.1?int upgrade_stars:flags.3?long = StarGift; -starGiftUnique#f2fe7e4a flags:# id:long title:string slug:string num:int owner_id:flags.0?Peer owner_name:flags.1?string owner_address:flags.2?string attributes:Vector availability_issued:int availability_total:int = StarGift; +starGiftUnique#5c62d151 flags:# id:long title:string slug:string num:int owner_id:flags.0?Peer owner_name:flags.1?string owner_address:flags.2?string attributes:Vector availability_issued:int availability_total:int gift_address:flags.3?string = StarGift; payments.starGiftsNotModified#a388a368 = payments.StarGifts; payments.starGifts#901689ea hash:int gifts:Vector = payments.StarGifts; @@ -1934,6 +1934,10 @@ inputSavedStarGiftChat#f101aa7f peer:InputPeer saved_id:long = InputSavedStarGif payments.starGiftWithdrawalUrl#84aa3a9c url:string = payments.StarGiftWithdrawalUrl; +paidReactionPrivacyDefault#206ad49e = PaidReactionPrivacy; +paidReactionPrivacyAnonymous#1f0c1ad9 = PaidReactionPrivacy; +paidReactionPrivacyPeer#dc6cfcf0 peer:InputPeer = PaidReactionPrivacy; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1946,6 +1950,7 @@ invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X; invokeWithBusinessConnection#dd289f8e {X:Type} connection_id:string query:!X = X; invokeWithGooglePlayIntegrity#1df92984 {X:Type} nonce:string token:string query:!X = X; invokeWithApnsSecret#0dae54f8 {X:Type} nonce:string secret:string query:!X = X; +invokeWithReCaptcha#adbb0f94 {X:Type} token:string query:!X = X; auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode; auth.signUp#aac7b717 flags:# no_joined_notifications:flags.0?true phone_number:string phone_code_hash:string first_name:string last_name:string = auth.Authorization; @@ -2331,8 +2336,8 @@ messages.editFactCheck#589ee75 peer:InputPeer msg_id:int text:TextWithEntities = messages.deleteFactCheck#d1da940c peer:InputPeer msg_id:int = Updates; messages.getFactCheck#b9cdc5ee peer:InputPeer msg_id:Vector = Vector; messages.requestMainWebView#c9e01e7b flags:# compact:flags.7?true fullscreen:flags.8?true peer:InputPeer bot:InputUser start_param:flags.1?string theme_params:flags.0?DataJSON platform:string = WebViewResult; -messages.sendPaidReaction#9dd6a67b flags:# peer:InputPeer msg_id:int count:int random_id:long private:flags.0?Bool = Updates; -messages.togglePaidReactionPrivacy#849ad397 peer:InputPeer msg_id:int private:Bool = Bool; +messages.sendPaidReaction#58bbcb50 flags:# peer:InputPeer msg_id:int count:int random_id:long private:flags.0?PaidReactionPrivacy = Updates; +messages.togglePaidReactionPrivacy#435885b5 peer:InputPeer msg_id:int private:PaidReactionPrivacy = Bool; messages.getPaidReactionPrivacy#472455aa = Updates; messages.viewSponsoredMessage#673ad8f1 peer:InputPeer random_id:bytes = Bool; messages.clickSponsoredMessage#f093465 flags:# media:flags.0?true fullscreen:flags.1?true peer:InputPeer random_id:bytes = Bool; @@ -2423,7 +2428,7 @@ channels.editLocation#58e63f6d channel:InputChannel geo_point:InputGeoPoint addr channels.toggleSlowMode#edd49ef0 channel:InputChannel seconds:int = Updates; channels.getInactiveChannels#11e831ee = messages.InactiveChats; channels.convertToGigagroup#b290c69 channel:InputChannel = Updates; -channels.getSendAs#dc770ee peer:InputPeer = channels.SendAsPeers; +channels.getSendAs#e785a43f flags:# for_paid_reactions:flags.0?true peer:InputPeer = channels.SendAsPeers; channels.deleteParticipantHistory#367544db channel:InputChannel participant:InputPeer = messages.AffectedHistory; channels.toggleJoinToSend#e4cb9580 channel:InputChannel enabled:Bool = Updates; channels.toggleJoinRequest#4c2985b6 channel:InputChannel enabled:Bool = Updates; @@ -2648,4 +2653,4 @@ smsjobs.finishJob#4f1ebf24 flags:# job_id:string error:flags.0?string = Bool; fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo; -// LAYER 198 +// LAYER 199