From da794865a69d0d371a0eb031a35cde3efe8e0cf8 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 16:55:51 +0200 Subject: [PATCH 1/8] Update some constants to new values --- telegram/constants.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/telegram/constants.py b/telegram/constants.py index 4e3ac0ab144..70f2c9a4676 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -956,8 +956,12 @@ class ChatSubscriptionLimit(IntEnum): """:obj:`int`: The number of seconds the subscription will be active.""" MIN_PRICE = 1 """:obj:`int`: Amount of stars a user pays, minimum amount the subscription can be set to.""" - MAX_PRICE = 2500 - """:obj:`int`: Amount of stars a user pays, maximum amount the subscription can be set to.""" + MAX_PRICE = 10000 + """:obj:`int`: Amount of stars a user pays, maximum amount the subscription can be set to. + + .. versionchanged:: NEXT.VERSION + Bot API 9.0 changed the value to 10000. + """ class BackgroundTypeLimit(IntEnum): @@ -3288,12 +3292,14 @@ class InvoiceLimit(IntEnum): .. versionadded:: 21.6 """ - MAX_STAR_COUNT = 2500 + MAX_STAR_COUNT = 10000 """:obj:`int`: Maximum amount of starts that must be paid to buy access to a paid media passed as :paramref:`~telegram.Bot.send_paid_media.star_count` parameter of :meth:`telegram.Bot.send_paid_media`. .. versionadded:: 21.6 + .. versionchanged:: NEXT.VERSION + Bot API 9.0 changed the value to 10000. """ SUBSCRIPTION_PERIOD = dtm.timedelta(days=30).total_seconds() """:obj:`int`: The period of time for which the subscription is active before @@ -3302,11 +3308,13 @@ class InvoiceLimit(IntEnum): .. versionadded:: 21.8 """ - SUBSCRIPTION_MAX_PRICE = 2500 + SUBSCRIPTION_MAX_PRICE = 10000 """:obj:`int`: The maximum price of a subscription created wtih :meth:`telegram.Bot.create_invoice_link`. .. versionadded:: 21.9 + .. versionchanged:: NEXT.VERSION + Bot API 9.0 changed the value to 10000. """ From 954205c1f884a35e87fba316d9f934bd0686a8c9 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 17:09:16 +0200 Subject: [PATCH 2/8] Add class PaidMessagePriceChanged --- docs/source/telegram.at-tree.rst | 1 + .../telegram.paidmeessagepricechanged.rst | 6 ++ telegram/__init__.py | 2 + telegram/_paidmessagepricechanged.py | 55 +++++++++++++++ tests/test_paidmessagepricechanged.py | 70 +++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 docs/source/telegram.paidmeessagepricechanged.rst create mode 100644 telegram/_paidmessagepricechanged.py create mode 100644 tests/test_paidmessagepricechanged.py diff --git a/docs/source/telegram.at-tree.rst b/docs/source/telegram.at-tree.rst index 4ef092a4def..63da86e76de 100644 --- a/docs/source/telegram.at-tree.rst +++ b/docs/source/telegram.at-tree.rst @@ -136,6 +136,7 @@ Available Types telegram.paidmediapreview telegram.paidmediapurchased telegram.paidmediavideo + telegram.paidmessagepricechanged telegram.photosize telegram.poll telegram.pollanswer diff --git a/docs/source/telegram.paidmeessagepricechanged.rst b/docs/source/telegram.paidmeessagepricechanged.rst new file mode 100644 index 00000000000..3d0e739c456 --- /dev/null +++ b/docs/source/telegram.paidmeessagepricechanged.rst @@ -0,0 +1,6 @@ +PaidMessagePriceChanged +======================= + +.. autoclass:: telegram.PaidMessagePriceChanged + :members: + :show-inheritance: diff --git a/telegram/__init__.py b/telegram/__init__.py index 2ce505930e6..0f20f0ba605 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -200,6 +200,7 @@ "PaidMediaPreview", "PaidMediaPurchased", "PaidMediaVideo", + "PaidMessagePriceChanged", "PassportData", "PassportElementError", "PassportElementErrorDataField", @@ -493,6 +494,7 @@ PaidMediaPurchased, PaidMediaVideo, ) +from ._paidmessagepricechanged import PaidMessagePriceChanged from ._passport.credentials import ( Credentials, DataCredentials, diff --git a/telegram/_paidmessagepricechanged.py b/telegram/_paidmessagepricechanged.py new file mode 100644 index 00000000000..f31d7293b40 --- /dev/null +++ b/telegram/_paidmessagepricechanged.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# A library that provides a Python interface to the Telegram Bot API +# Copyright (C) 2015-2025 +# Leandro Toledo de Souza +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser Public License for more details. +# +# You should have received a copy of the GNU Lesser Public License +# along with this program. If not, see [http://www.gnu.org/licenses/]. +"""This module contains an object that describes a price change of a paid message.""" +from typing import Optional + +from telegram._telegramobject import TelegramObject +from telegram._utils.types import JSONDict + + +class PaidMessagePriceChanged(TelegramObject): + """Describes a service message about a change in the price of paid messages within a chat. + + Objects of this class are comparable in terms of equality. Two objects of this class are + considered equal, if their :attr:`paid_message_star_count` is equal. + + .. versionadded:: NEXT.VERSION + + Args: + paid_message_star_count (:obj:`int`): The new number of Telegram Stars that must be paid by + non-administrator users of the supergroup chat for each sent message + + Attributes: + paid_message_star_count (:obj:`int`): The new number of Telegram Stars that must be paid by + non-administrator users of the supergroup chat for each sent message + """ + + __slots__ = ("paid_message_star_count",) + + def __init__( + self, + paid_message_star_count: int, + *, + api_kwargs: Optional[JSONDict] = None, + ) -> None: + super().__init__(api_kwargs=api_kwargs) + self.paid_message_star_count: int = paid_message_star_count + + self._id_attrs = (self.paid_message_star_count,) + self._freeze() diff --git a/tests/test_paidmessagepricechanged.py b/tests/test_paidmessagepricechanged.py new file mode 100644 index 00000000000..b97eafbab93 --- /dev/null +++ b/tests/test_paidmessagepricechanged.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# +# A library that provides a Python interface to the Telegram Bot API +# Copyright (C) 2015-2025 +# Leandro Toledo de Souza +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser Public License for more details. +# +# You should have received a copy of the GNU Lesser Public License +# along with this program. If not, see [http://www.gnu.org/licenses/]. + +import pytest + +from telegram import Dice, PaidMessagePriceChanged +from tests.auxil.slots import mro_slots + + +class PaidMessagePriceChangedTestBase: + paid_message_star_count = 291 + + +@pytest.fixture(scope="module") +def paid_message_price_changed(): + return PaidMessagePriceChanged(PaidMessagePriceChangedTestBase.paid_message_star_count) + + +class TestPaidMessagePriceChangedWithoutRequest(PaidMessagePriceChangedTestBase): + def test_slot_behaviour(self, paid_message_price_changed): + for attr in paid_message_price_changed.__slots__: + assert ( + getattr(paid_message_price_changed, attr, "err") != "err" + ), f"got extra slot '{attr}'" + assert len(mro_slots(paid_message_price_changed)) == len( + set(mro_slots(paid_message_price_changed)) + ), "duplicate slot" + + def test_to_dict(self, paid_message_price_changed): + pmpc_dict = paid_message_price_changed.to_dict() + assert isinstance(pmpc_dict, dict) + assert pmpc_dict["paid_message_star_count"] == self.paid_message_star_count + + def test_de_json(self, offline_bot): + json_dict = {"paid_message_star_count": self.paid_message_star_count} + pmpc = PaidMessagePriceChanged.de_json(json_dict, offline_bot) + assert isinstance(pmpc, PaidMessagePriceChanged) + assert pmpc.paid_message_star_count == self.paid_message_star_count + assert pmpc.api_kwargs == {} + + def test_equality(self): + pmpc1 = PaidMessagePriceChanged(self.paid_message_star_count) + pmpc2 = PaidMessagePriceChanged(self.paid_message_star_count) + pmpc3 = PaidMessagePriceChanged(3) + dice = Dice(5, "emoji") + + assert pmpc1 == pmpc2 + assert hash(pmpc1) == hash(pmpc2) + + assert pmpc1 != pmpc3 + assert hash(pmpc1) != hash(pmpc3) + + assert pmpc1 != dice + assert hash(pmpc1) != hash(dice) From e5c4cef948f0163ca4a085ec03bc89b1b948f8e8 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 17:18:50 +0200 Subject: [PATCH 3/8] Add new attributes to `Message` --- telegram/_message.py | 28 ++++++++++++++++++++++++++++ tests/test_message.py | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/telegram/_message.py b/telegram/_message.py index 4108bccb927..967c0624149 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -55,6 +55,7 @@ from telegram._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged from telegram._messageentity import MessageEntity from telegram._paidmedia import PaidMediaInfo +from telegram._paidmessagepricechanged import PaidMessagePriceChanged from telegram._passport.passportdata import PassportData from telegram._payment.invoice import Invoice from telegram._payment.refundedpayment import RefundedPayment @@ -445,6 +446,10 @@ class Message(MaybeInaccessibleMessage): `More about Telegram Login >> `_. author_signature (:obj:`str`, optional): Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. + paid_start_count (:obj:`int`, optional): The number of Telegram Stars that were paid by the + sender of the message to send it + + .. versionadded:: NEXT.VERSION passport_data (:class:`telegram.PassportData`, optional): Telegram Passport data. poll (:class:`telegram.Poll`, optional): Message is a native poll, information about the poll. @@ -551,6 +556,10 @@ class Message(MaybeInaccessibleMessage): giveaway without public winners was completed .. versionadded:: 20.8 + paid_message_price_changed (:class:`telegram.PaidMessagePriceChanged`, optional): Service + message: the price for paid messages has changed in the chat + + .. versionadded:: NEXT.VERSION external_reply (:class:`telegram.ExternalReplyInfo`, optional): Information about the message that is being replied to, which may come from another chat or forum topic. @@ -781,6 +790,10 @@ class Message(MaybeInaccessibleMessage): `More about Telegram Login >> `_. author_signature (:obj:`str`): Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. + paid_start_count (:obj:`int`): Optional. The number of Telegram Stars that were paid by the + sender of the message to send it + + .. versionadded:: NEXT.VERSION passport_data (:class:`telegram.PassportData`): Optional. Telegram Passport data. Examples: @@ -887,6 +900,10 @@ class Message(MaybeInaccessibleMessage): giveaway without public winners was completed .. versionadded:: 20.8 + paid_message_price_changed (:class:`telegram.PaidMessagePriceChanged`): Optional. Service + message: the price for paid messages has changed in the chat + + .. versionadded:: NEXT.VERSION external_reply (:class:`telegram.ExternalReplyInfo`): Optional. Information about the message that is being replied to, which may come from another chat or forum topic. @@ -1008,6 +1025,8 @@ class Message(MaybeInaccessibleMessage): "new_chat_photo", "new_chat_title", "paid_media", + "paid_message_price_changed", + "paid_star_count", "passport_data", "photo", "pinned_message", @@ -1131,6 +1150,8 @@ def __init__( refunded_payment: Optional[RefundedPayment] = None, gift: Optional[GiftInfo] = None, unique_gift: Optional[UniqueGiftInfo] = None, + paid_message_price_changed: Optional[PaidMessagePriceChanged] = None, + paid_star_count: Optional[int] = None, *, api_kwargs: Optional[JSONDict] = None, ): @@ -1236,6 +1257,10 @@ def __init__( self.refunded_payment: Optional[RefundedPayment] = refunded_payment self.gift: Optional[GiftInfo] = gift self.unique_gift: Optional[UniqueGiftInfo] = unique_gift + self.paid_message_price_changed: Optional[PaidMessagePriceChanged] = ( + paid_message_price_changed + ) + self.paid_star_count: Optional[int] = paid_star_count self._effective_attachment = DEFAULT_NONE @@ -1372,6 +1397,9 @@ def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "Message": ) data["gift"] = de_json_optional(data.get("gift"), GiftInfo, bot) data["unique_gift"] = de_json_optional(data.get("unique_gift"), UniqueGiftInfo, bot) + data["paid_message_price_changed"] = de_json_optional( + data.get("paid_message_price_changed"), PaidMessagePriceChanged, bot + ) # Unfortunately, this needs to be here due to cyclic imports from telegram._giveaway import ( # pylint: disable=import-outside-toplevel diff --git a/tests/test_message.py b/tests/test_message.py index 7c78e37697c..e145720d705 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -50,6 +50,7 @@ MessageOriginChat, PaidMediaInfo, PaidMediaPreview, + PaidMessagePriceChanged, PassportData, PhotoSize, Poll, @@ -328,6 +329,8 @@ def message(bot): {"show_caption_above_media": True}, {"paid_media": PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)])}, {"refunded_payment": RefundedPayment("EUR", 243, "payload", "charge_id", "provider_id")}, + {"paid_star_count": 291}, + {"paid_message_price_changed": PaidMessagePriceChanged(291)}, ], ids=[ "reply", @@ -403,6 +406,8 @@ def message(bot): "show_caption_above_media", "paid_media", "refunded_payment", + "paid_star_count", + "paid_message_price_changed", ], ) def message_params(bot, request): From 3dbd5277907748c1ca5bc139b15b7b279920fd5e Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 17:23:09 +0200 Subject: [PATCH 4/8] Add new filter --- telegram/ext/filters.py | 15 +++++++++++++++ tests/ext/test_filters.py | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 13224e1e9db..a5dfe870152 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -1935,6 +1935,7 @@ def filter(self, update: Update) -> bool: or StatusUpdate.NEW_CHAT_MEMBERS.check_update(update) or StatusUpdate.NEW_CHAT_PHOTO.check_update(update) or StatusUpdate.NEW_CHAT_TITLE.check_update(update) + or StatusUpdate.PAID_MESSAGE_PRICE_CHANGED.check_update(update) or StatusUpdate.PINNED_MESSAGE.check_update(update) or StatusUpdate.PROXIMITY_ALERT_TRIGGERED.check_update(update) or StatusUpdate.REFUNDED_PAYMENT.check_update(update) @@ -2176,6 +2177,20 @@ def filter(self, message: Message) -> bool: NEW_CHAT_TITLE = _NewChatTitle(name="filters.StatusUpdate.NEW_CHAT_TITLE") """Messages that contain :attr:`telegram.Message.new_chat_title`.""" + class _PaidMessagePriceChanged(MessageFilter): + __slots__ = () + + def filter(self, message: Message) -> bool: + return bool(message.paid_message_price_changed) + + PAID_MESSAGE_PRICE_CHANGED = _PaidMessagePriceChanged( + name="filters.StatusUpdate.PAID_MESSAGE_PRICE_CHANGED" + ) + """Messages that contain :attr:`telegram.Message.paid_message_price_changed`. + + .. versionadded:: NEXT.VERSION + """ + class _PinnedMessage(MessageFilter): __slots__ = () diff --git a/tests/ext/test_filters.py b/tests/ext/test_filters.py index 6ab3672506c..ae125c98a40 100644 --- a/tests/ext/test_filters.py +++ b/tests/ext/test_filters.py @@ -1108,6 +1108,11 @@ def test_filters_status_update(self, update): assert filters.StatusUpdate.UNIQUE_GIFT.check_update(update) update.message.unique_gift = None + update.message.paid_message_price_changed = "paid_message_price_changed" + assert filters.StatusUpdate.ALL.check_update(update) + assert filters.StatusUpdate.PAID_MESSAGE_PRICE_CHANGED.check_update(update) + update.message.paid_message_price_changed = None + def test_filters_forwarded(self, update, message_origin_user): assert filters.FORWARDED.check_update(update) update.message.forward_origin = MessageOriginHiddenUser(dtm.datetime.utcnow(), 1) From 15293ce2d854ba8620084584049f018b539e4ebb Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 17:24:03 +0200 Subject: [PATCH 5/8] Add PR to chango fragment --- changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml b/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml index 23ff35c5224..3f50fb2e48b 100644 --- a/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml +++ b/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml @@ -36,3 +36,6 @@ closes_threads = [] uid = "4773" author_uid = "aelkheir" closes_threads = [] +uid = "4782" +author_uid = "Bibo-Joshi" +closes_threads = [] From 3bb93945dc48bb2b828112dbce196a77d741d99e Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 18:00:57 +0200 Subject: [PATCH 6/8] fix chango fragment --- changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml b/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml index 3f50fb2e48b..82f8c6e6367 100644 --- a/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml +++ b/changes/unreleased/4756.JT5nmUmGRG6qDEh5ScMn5f.toml @@ -36,6 +36,7 @@ closes_threads = [] uid = "4773" author_uid = "aelkheir" closes_threads = [] +[[pull_requests]] uid = "4782" author_uid = "Bibo-Joshi" closes_threads = [] From b714bd00ecf52deb52f6f5ee94accf6787231bde Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 18:05:04 +0200 Subject: [PATCH 7/8] Update `constants.MessageType` --- telegram/constants.py | 5 +++++ tests/test_constants.py | 1 + 2 files changed, 6 insertions(+) diff --git a/telegram/constants.py b/telegram/constants.py index 70f2c9a4676..9c3136bf3e3 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -2147,6 +2147,11 @@ class MessageType(StringEnum): .. versionadded:: 21.4 """ + PAID_MESSAGE_PRICE_CHANGED = "paid_message_price_changed" + """:obj:`str`: Messages with :attr:`telegram.Message.paid_message_price_changed`. + + .. versionadded:: Next.VERSION + """ PASSPORT_DATA = "passport_data" """:obj:`str`: Messages with :attr:`telegram.Message.passport_data`.""" PHOTO = "photo" diff --git a/tests/test_constants.py b/tests/test_constants.py index 3cd9e56e7ab..b97cc4f8eac 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -203,6 +203,7 @@ def is_type_attribute(name: str) -> bool: "via_bot", "is_from_offline", "show_caption_above_media", + "paid_star_count", } @pytest.mark.parametrize( From 7a95d458ad992752b30c59c561836cd7dc750465 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 4 May 2025 21:19:12 +0200 Subject: [PATCH 8/8] small docstring fix --- telegram/_message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index 967c0624149..f39e52e7851 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -446,7 +446,7 @@ class Message(MaybeInaccessibleMessage): `More about Telegram Login >> `_. author_signature (:obj:`str`, optional): Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. - paid_start_count (:obj:`int`, optional): The number of Telegram Stars that were paid by the + paid_star_count (:obj:`int`, optional): The number of Telegram Stars that were paid by the sender of the message to send it .. versionadded:: NEXT.VERSION @@ -790,7 +790,7 @@ class Message(MaybeInaccessibleMessage): `More about Telegram Login >> `_. author_signature (:obj:`str`): Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. - paid_start_count (:obj:`int`): Optional. The number of Telegram Stars that were paid by the + paid_star_count (:obj:`int`): Optional. The number of Telegram Stars that were paid by the sender of the message to send it .. versionadded:: NEXT.VERSION pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy