Skip to content

Commit b3e9d40

Browse files
committed
Bits Use Subscription
1 parent 53af8ba commit b3e9d40

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

docs/references/eventsub_subscriptions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ Eventsub Subscriptions
3434
.. autoclass:: AutomodTermsUpdateSubscription
3535
:members:
3636

37+
.. attributetable:: ChannelBitsUseSubscription
38+
39+
.. autoclass:: ChannelBitsUseSubscription
40+
:members:
41+
3742
.. attributetable:: ChannelUpdateSubscription
3843

3944
.. autoclass:: ChannelUpdateSubscription

twitchio/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ async def login(self, *, token: str | None = None, load_tokens: bool = True, sav
333333
if self._bot_id:
334334
logger.debug("Fetching Clients self user for %r", self)
335335
partial = PartialUser(id=self._bot_id, http=self._http)
336-
self._user = partial if not self._fetch_self else await partial.user()
336+
self._user = await partial.user() if self._fetch_self else partial
337337

338338
await self.setup_hook()
339339

twitchio/eventsub/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class SubscriptionType(enum.Enum):
9999
ChannelUpdate: Literal["channel.update"]
100100
ChannelFollow: Literal["channel.follow"]
101101
ChannelAdBreakBegin: Literal["channel.ad_break.begin"]
102+
ChannelBitsUseSubscription: Literal["channel.bits.use"]
102103
ChannelChatClear: Literal["channel.chat.clear"]
103104
ChannelChatClearUserMessages: Literal["channel.chat.clear_user_messages"]
104105
ChannelChatMessage: Literal["channel.chat.message"]
@@ -172,6 +173,7 @@ class SubscriptionType(enum.Enum):
172173
AutomodMessageUpdate = "automod.message.update"
173174
AutomodSettingsUpdate = "automod.settings.update"
174175
AutomodTermsUpdate = "automod.terms.update"
176+
ChannelBitsUse = "channel.bits.use"
175177
ChannelUpdate = "channel.update"
176178
ChannelFollow = "channel.follow"
177179
ChannelAdBreakBegin = "channel.ad_break.begin"

twitchio/eventsub/subscriptions.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"AutomodSettingsUpdateSubscription",
4444
"AutomodTermsUpdateSubscription",
4545
"ChannelBanSubscription",
46+
"ChannelBitsUseSubscription",
4647
"ChannelCheerSubscription",
4748
"ChannelFollowSubscription",
4849
"ChannelModerateSubscription",
@@ -115,6 +116,7 @@
115116
# Short names: Only map names that require shortening...
116117
_SUB_MAPPING: dict[str, str] = {
117118
"channel.ad_break.begin": "ad_break",
119+
"channel.bits.use": "bits_use",
118120
"channel.chat.clear_user_messages": "chat_clear_user",
119121
"channel.chat.message": "message", # Sub events?
120122
"channel.chat.message_delete": "message_delete",
@@ -404,6 +406,51 @@ def condition(self) -> Condition:
404406
return {"broadcaster_user_id": self.broadcaster_user_id, "moderator_user_id": self.moderator_user_id}
405407

406408

409+
class ChannelBitsUseSubscription(SubscriptionPayload):
410+
"""The ``channel.bits.use`` subscription type sends a notification whenever Bits are used on a channel.
411+
412+
This event is designed to be an all-purpose event for when Bits are used in a channel and might be updated in the future as more Twitch features use Bits.
413+
414+
Currently, this event will be sent when a user:
415+
416+
- Cheers in a channel
417+
- Uses a Power-up
418+
- Will not emit when a streamer uses a Power-up for free in their own channel.
419+
420+
.. important::
421+
Requires a user access token that includes the ``bits:read`` scope. This must be the broadcaster's token.
422+
423+
Bits transactions via Twitch Extensions are not included in this subscription type.
424+
425+
One attribute ``.condition`` can be accessed from this class, which returns a mapping of the subscription
426+
parameters provided.
427+
428+
Parameters
429+
----------
430+
broadcaster_user_id: str | PartialUser
431+
The ID, or PartialUser, of the broadcaster to subscribe to.
432+
433+
Raises
434+
------
435+
ValueError
436+
The parameters "broadcaster_user_id" must be passed.
437+
"""
438+
439+
type: ClassVar[Literal["channel.bits.use"]] = "channel.bits.use"
440+
version: ClassVar[Literal["1"]] = "1"
441+
442+
@handle_user_ids()
443+
def __init__(self, **condition: Unpack[Condition]) -> None:
444+
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")
445+
446+
if not self.broadcaster_user_id:
447+
raise ValueError('The parameter "broadcaster_user_id" must be passed.')
448+
449+
@property
450+
def condition(self) -> Condition:
451+
return {"broadcaster_user_id": self.broadcaster_user_id}
452+
453+
407454
class ChannelUpdateSubscription(SubscriptionPayload):
408455
"""The ``channel.update`` subscription type sends notifications when a broadcaster updates the category, title, content classification labels, or broadcast language for their channel.
409456

twitchio/ext/commands/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __str__(self) -> str:
168168

169169
async def __call__(self, context: Context) -> Any:
170170
callback = self._callback(self._injected, context) if self._injected else self._callback(context) # type: ignore
171-
return await callback
171+
return await callback # type: ignore will fix later
172172

173173
@property
174174
def component(self) -> Component_T | None:
@@ -197,7 +197,7 @@ def relative_name(self) -> str:
197197
198198
If this command has no parent, this simply returns the name.
199199
"""
200-
return self._name if not self._parent else f"{self._parent._name} {self._name}"
200+
return f"{self._parent._name} {self._name}" if self._parent else self._name
201201

202202
@property
203203
def full_parent_name(self) -> str:

twitchio/types_/eventsub.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"BaseEmoteData",
4343
"ChannelAdBreakBeginEvent",
4444
"ChannelBanEvent",
45+
"ChannelBitsUseEvent",
4546
"ChannelChatClearEvent",
4647
"ChannelChatClearUserMessagesEvent",
4748
"ChannelChatMessageDeleteEvent",
@@ -355,6 +356,24 @@ class ChannelAdBreakBeginEvent(BaseBroadcasterEvent):
355356
is_automatic: str
356357

357358

359+
class PowerUpEmote(TypedDict):
360+
id: str
361+
name: str
362+
363+
364+
class PowerUpData(TypedDict):
365+
type: Literal["message_effect", "celebration", "gigantify_an_emote"]
366+
emote: PowerUpEmote | None
367+
message_effect_id: str | None
368+
369+
370+
class ChannelBitsUseEvent(BroadcasterUserEvent):
371+
bits: int
372+
type: Literal["cheer", "power_up"]
373+
message: ChatMessageData
374+
power_up: PowerUpData | None
375+
376+
358377
class ChannelChatClearEvent(BaseBroadcasterEvent): ...
359378

360379

0 commit comments

Comments
 (0)