Skip to content

Commit 565c9a1

Browse files
authored
Make sure owned_gift_id is str, instead of converting it (#182)
1 parent 5f0f219 commit 565c9a1

8 files changed

Lines changed: 18 additions & 9 deletions

File tree

pyrogram/methods/payments/convert_gift_to_stars.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ async def convert_gift_to_stars(
5353
# Convert gift
5454
await app.convert_gift_to_stars(message_id=123)
5555
"""
56+
if not isinstance(owned_gift_id, str):
57+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
58+
5659
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
5760
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)
5861

pyrogram/methods/payments/get_upgraded_gift.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
import re
20-
2119
import pyrogram
2220
from pyrogram import raw, types
2321

pyrogram/methods/payments/hide_gift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ async def hide_gift(
5454
# Hide gift in channel (owned_gift_id packed in format chatID_savedID)
5555
await app.hide_gift(owned_gift_id="123_456")
5656
"""
57-
owned_gift_id = str(owned_gift_id)
57+
if not isinstance(owned_gift_id, str):
58+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
5859

5960
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
6061
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)

pyrogram/methods/payments/set_gift_resale_price.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ async def set_gift_resale_price(
5151
# Change resale price of a unique gift
5252
await app.set_gift_resale_price(owned_gift_id="123456", resale_star_count=100)
5353
"""
54-
owned_gift_id = str(owned_gift_id)
54+
if not isinstance(owned_gift_id, str):
55+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
5556

5657
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
5758
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)

pyrogram/methods/payments/set_pinned_gifts.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ async def set_pinned_gifts(
5858
stargifts = []
5959

6060
for gift in owned_gift_ids:
61-
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", str(gift))
62-
slug_match = self.UPGRADED_GIFT_RE.match(str(gift))
61+
if not isinstance(gift, str):
62+
raise ValueError(f"gift id has to be str, but {type(gift)} was provided")
63+
64+
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", gift)
65+
slug_match = self.UPGRADED_GIFT_RE.match(gift)
6366

6467
if saved_gift_match:
6568
stargifts.append(

pyrogram/methods/payments/show_gift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ async def show_gift(
5454
# Show gift in channel (owned_gift_id packed in format chatID_savedID)
5555
await app.show_gift(owned_gift_id="123_456")
5656
"""
57-
owned_gift_id = str(owned_gift_id)
57+
if not isinstance(owned_gift_id, str):
58+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
5859

5960
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
6061
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)

pyrogram/methods/payments/transfer_gift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async def transfer_gift(
6565
# Transfer gift to another user
6666
await app.transfer_gift(owned_gift_id="123", new_owner_chat_id=123)
6767
"""
68-
owned_gift_id = str(owned_gift_id)
68+
if not isinstance(owned_gift_id, str):
69+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
6970

7071
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
7172
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)

pyrogram/methods/payments/upgrade_gift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ async def upgrade_gift(
6666
# Upgrade gift in channel (owned_gift_id packed in format chatID_savedID)
6767
await app.upgrade_gift(owned_gift_id="123_456")
6868
"""
69-
owned_gift_id = str(owned_gift_id)
69+
if not isinstance(owned_gift_id, str):
70+
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
7071

7172
saved_gift_match = re.match(r"^(-\d+)_(\d+)$", owned_gift_id)
7273
slug_match = self.UPGRADED_GIFT_RE.match(owned_gift_id)

0 commit comments

Comments
 (0)