Skip to content

Commit 71609f4

Browse files
committed
Prevent crashes with weird outbound promotions
1 parent 4f9aa4d commit 71609f4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

discord/promotions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class Promotion(Hashable):
113113

114114
__slots__ = (
115115
'id',
116+
'_type',
116117
'trial_id',
117118
'starts_at',
118119
'ends_at',
@@ -145,15 +146,16 @@ def _update(self, data: Union[PromotionPayload, ClaimedPromotionPayload]) -> Non
145146
promotion: PromotionPayload = data.get('promotion', data)
146147

147148
self.id: int = int(promotion['id'])
149+
self._type = promotion.get('promotion_type', 0) # Unknown enum, observed values 0-2
148150
self.trial_id: Optional[int] = _get_as_snowflake(promotion, 'trial_id')
149151
self.starts_at: datetime = parse_time(promotion['start_date'])
150152
self.ends_at: datetime = parse_time(promotion['end_date'])
151153
self.claimed_at: Optional[datetime] = parse_time(data.get('claimed_at'))
152154
self.code: Optional[str] = data.get('code')
153155
self._flags: int = promotion.get('flags', 0)
154156

155-
self.outbound_title: str = promotion['outbound_title']
156-
self.outbound_description: str = promotion['outbound_redemption_modal_body']
157+
self.outbound_title: str = promotion.get('outbound_title', '')
158+
self.outbound_description: str = promotion.get('outbound_redemption_modal_body', '')
157159
self.outbound_link: str = promotion.get(
158160
'outbound_redemption_page_link',
159161
promotion.get('outbound_redemption_url_format', '').replace('{code}', self.code or '{code}'),
@@ -163,7 +165,7 @@ def _update(self, data: Union[PromotionPayload, ClaimedPromotionPayload]) -> Non
163165
self.inbound_description: Optional[str] = promotion.get('inbound_body_text')
164166
self.inbound_link: Optional[str] = promotion.get('inbound_help_center_link')
165167
self.inbound_restricted_countries: List[str] = promotion.get('inbound_restricted_countries', [])
166-
self.terms_and_conditions: str = promotion['outbound_terms_and_conditions']
168+
self.terms_and_conditions: str = promotion.get('outbound_terms_and_conditions', '')
167169

168170
@property
169171
def flags(self) -> PromotionFlags:

discord/types/promotions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ class Promotion(TypedDict):
3636
trial_id: NotRequired[Snowflake]
3737
start_date: str
3838
end_date: str
39+
promotion_type: int
3940
flags: int
40-
outbound_title: str
41+
outbound_title: NotRequired[str]
4142
outbound_redemption_modal_body: str
4243
outbound_redemption_page_link: NotRequired[str]
4344
outbound_redemption_url_format: NotRequired[str]
4445
outbound_restricted_countries: NotRequired[List[str]]
4546
outbound_terms_and_conditions: str
46-
inbound_title: NotRequired[str]
47+
inbound_header_text: NotRequired[str]
4748
inbound_body_text: NotRequired[str]
4849
inbound_help_center_link: NotRequired[str]
4950
inbound_restricted_countries: NotRequired[List[str]]

0 commit comments

Comments
 (0)