Skip to content

Commit

Permalink
Merge pull request #2138 from Badiboy/master
Browse files Browse the repository at this point in the history
Fix ChatBoostSource issues
  • Loading branch information
Badiboy authored Jan 26, 2024
2 parents 57fbc11 + 5844b2e commit d5e5269
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9000,28 +9000,34 @@ def __init__(self, chat, boost_id, remove_date, source, **kwargs):
self.source = source


class ChatBoostSource(JsonDeserializable):
class ChatBoostSource(ABC, JsonDeserializable):
"""
This object describes the source of a chat boost.
This object describes the source of a chat boost. It can be one of
ChatBoostSourcePremium
ChatBoostSourceGiftCode
ChatBoostSourceGiveaway
Telegram documentation: https://core.telegram.org/bots/api#chatboostsource
:param source: Source of the boost
:type source: :obj:`str`
:return: Instance of the class
:rtype: :class:`ChatBoostSource`
:rtype: :class:`ChatBoostSourcePremium` or :class:`ChatBoostSourceGiftCode` or :class:`ChatBoostSourceGiveaway`
"""

@classmethod
def de_json(cls, json_string):
if json_string is None:
return None
obj = cls.check_json(json_string)
return cls(**obj)

def __init__(self, source, **kwargs):
self.source = source
if obj["type"] == "premium":
return ChatBoostSourcePremium.de_json(obj)
elif obj["type"] == "gift_code":
return ChatBoostSourceGiftCode.de_json(obj)
elif obj["type"] == "giveaway":
return ChatBoostSourceGiveaway.de_json(obj)
return None


# noinspection PyUnresolvedReferences
Expand Down Expand Up @@ -9137,7 +9143,7 @@ class ChatBoost(JsonDeserializable):
:param expiration_date: Point in time (Unix timestamp) when the boost will automatically expire, unless the booster's Telegram Premium subscription is prolonged
:type expiration_date: :obj:`int`
:param source: Source of the added boost
:param source: Optional. Source of the added boost (made Optional for now due to API error)
:type source: :class:`ChatBoostSource`
:return: Instance of the class
Expand All @@ -9149,7 +9155,8 @@ def de_json(cls, json_string):
if json_string is None:
return None
obj = cls.check_json(json_string)
obj['source'] = ChatBoostSource.de_json(obj['source'])
source = obj.get('source', None)
obj['source'] = ChatBoostSource.de_json(source) if source else None
return cls(**obj)

def __init__(self, boost_id, add_date, expiration_date, source, **kwargs):
Expand Down

0 comments on commit d5e5269

Please sign in to comment.