@@ -79,7 +79,7 @@ class PubSubChatMessage:
7979
8080 def __init__ (self , content : str , id : str , type : str ):
8181 self .content = content
82- self .id = int ( id )
82+ self .id = id
8383 self .type = type
8484
8585
@@ -133,8 +133,8 @@ class PubSubBitsMessage(PubSubMessage):
133133 The amount of bits used.
134134 channel_id: :class:`int`
135135 The channel the bits were given to.
136- user: :class:`twitchio.PartialUser`
137- The user giving the bits.
136+ user: Optional[ :class:`twitchio.PartialUser`]
137+ The user giving the bits. Can be None if anonymous.
138138 version: :class:`str`
139139 The event version.
140140 """
@@ -144,16 +144,21 @@ class PubSubBitsMessage(PubSubMessage):
144144 def __init__ (self , client : Client , topic : str , data : dict ):
145145 super ().__init__ (client , topic , data )
146146
147- self .message = PubSubChatMessage (data ["chat_message" ], data ["message_id" ], data ["message_type" ])
147+ data = data ["message" ]
148+ self .message = PubSubChatMessage (data ["data" ]["chat_message" ], data ["message_id" ], data ["message_type" ])
148149 self .badge_entitlement = (
149- PubSubBadgeEntitlement (data ["badge_entitlement" ]["new_version" ], data ["badge_entitlement" ]["old_version" ])
150- if data ["badge_entitlement" ]
150+ PubSubBadgeEntitlement (
151+ data ["data" ]["badge_entitlement" ]["new_version" ], data ["data" ]["badge_entitlement" ]["old_version" ]
152+ )
153+ if data ["data" ]["badge_entitlement" ]
151154 else None
152155 )
153- self .bits_used : int = data ["bits_used" ]
154- self .channel_id : int = int (data ["channel_id" ])
156+ self .bits_used : int = data ["data" ][ " bits_used" ]
157+ self .channel_id : int = int (data ["data" ][ " channel_id" ])
155158 self .user = (
156- PartialUser (client ._http , data ["user_id" ], data ["user_name" ]) if data ["user_id" ] is not None else None
159+ PartialUser (client ._http , data ["data" ]["user_id" ], data ["data" ]["user_name" ])
160+ if data ["data" ]["user_id" ]
161+ else None
157162 )
158163 self .version : str = data ["version" ]
159164
@@ -180,6 +185,7 @@ class PubSubBitsBadgeMessage(PubSubMessage):
180185
181186 def __init__ (self , client : Client , topic : str , data : dict ):
182187 super ().__init__ (client , topic , data )
188+ data = data ["message" ]
183189 self .user = PartialUser (client ._http , data ["user_id" ], data ["user_name" ])
184190 self .channel : Channel = client .get_channel (data ["channel_name" ]) or Channel (
185191 name = data ["channel_name" ], websocket = client ._connection
@@ -349,15 +355,15 @@ class PubSubChannelSubscribe(PubSubMessage):
349355 Channel that has been subscribed or subgifted.
350356 context: :class:`str`
351357 Event type associated with the subscription product.
352- user: :class:`twitchio.PartialUser`
353- The person who subscribed or sent a gift subscription.
358+ user: Optional[ :class:`twitchio.PartialUser`]
359+ The person who subscribed or sent a gift subscription. Can be None if anonymous.
354360 message: :class:`str`
355361 Message sent with the sub/resub.
356- emotes: List[:class:`dict`]
362+ emotes: Optional[ List[:class:`dict`] ]
357363 Message sent with the sub/resub.
358364 is_gift: :class:`bool`
359365 If this sub message was caused by a gift subscription.
360- recipient: :class:`twitchio.PartialUser`
366+ recipient: Optional[ :class:`twitchio.PartialUser`]
361367 The person the who received the gift subscription.
362368 sub_plan: :class:`str`
363369 Subscription Plan ID.
@@ -367,9 +373,9 @@ class PubSubChannelSubscribe(PubSubMessage):
367373 Time when the subscription or gift was completed. RFC 3339 format.
368374 cumulative_months: :class:`int`
369375 Cumulative number of tenure months of the subscription.
370- streak_months: :class:`int`
376+ streak_months: Optional[ :class:`int`]
371377 Denotes the user's most recent (and contiguous) subscription tenure streak in the channel.
372- multi_month_duration: :class:`int`
378+ multi_month_duration: Optional[ :class:`int`]
373379 Number of months gifted as part of a single, multi-month gift OR number of months purchased as part of a multi-month subscription.
374380 """
375381
@@ -398,21 +404,18 @@ def __init__(self, client: Client, topic: str, data: dict):
398404 name = subscription ["channel_name" ], websocket = client ._connection
399405 )
400406 self .context : str = subscription ["context" ]
401-
402407 try :
403408 self .user = PartialUser (client ._http , int (subscription ["user_id" ]), subscription ["user_name" ])
404409 except KeyError :
405410 self .user = None
406411
407412 self .message : str = subscription ["sub_message" ]["message" ]
408-
409413 try :
410414 self .emotes = subscription ["sub_message" ]["emotes" ]
411415 except KeyError :
412416 self .emotes = None
413417
414418 self .is_gift : bool = subscription ["is_gift" ]
415-
416419 try :
417420 self .recipient = PartialUser (
418421 client ._http , int (subscription ["recipient_id" ]), subscription ["recipient_user_name" ]
@@ -423,9 +426,18 @@ def __init__(self, client: Client, topic: str, data: dict):
423426 self .sub_plan : str = subscription ["sub_plan" ]
424427 self .sub_plan_name : str = subscription ["sub_plan_name" ]
425428 self .time = parse_timestamp (subscription ["time" ])
426- self .cumulative_months : int = int (subscription ["cumulative_months" ])
427- self .streak_months = int (subscription ["streak_months" ])
428- self .multi_month_duration = int (subscription ["multi_month_duration" ])
429+ try :
430+ self .cumulative_months = int (subscription ["cumulative_months" ])
431+ except KeyError :
432+ self .cumulative_months = None
433+ try :
434+ self .streak_months = int (subscription ["streak_months" ])
435+ except KeyError :
436+ self .streak_months = None
437+ try :
438+ self .multi_month_duration = int (subscription ["multi_month_duration" ])
439+ except KeyError :
440+ self .multi_month_duration = None
429441
430442
431443class PubSubModerationActionModeratorAdd (PubSubMessage ):
0 commit comments