Skip to content

Commit 856d383

Browse files
committed
add charity events to eventsub
1 parent 9937590 commit 856d383

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

docs/exts/eventsub.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ This is a list of events dispatched by the eventsub ext.
230230

231231
Called when a channel receives a shoutout.
232232

233+
.. function:: event_eventsub_notification_channel_charity_donate(event: ChannelCharityDonationData)
234+
235+
Called when a user donates to an active charity campaign.
236+
233237
API Reference
234238
--------------
235239

@@ -485,3 +489,9 @@ API Reference
485489
:members:
486490
:inherited-members:
487491

492+
.. attributetable::: ChannelCharityDonationData
493+
494+
.. autoclass:: ChannelCharityDonationData
495+
:members:
496+
:inherited-members:
497+

twitchio/ext/eventsub/models.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,53 @@ def __init__(self, client: EventSubClient, data: dict):
15441544
self.viewer_count: int = data["viewer_count"]
15451545

15461546

1547+
class ChannelCharityDonationData(EventData):
1548+
"""
1549+
Represents a donation towards a charity campaign.
1550+
1551+
Requires the ``channel:read:charity`` scope.
1552+
1553+
Attributes
1554+
-----------
1555+
id: :class:`str`
1556+
The ID of the event.
1557+
campaign_id: :class:`str`
1558+
The ID of the running charity campaign.
1559+
broadcaster: :class:`~twitchio.PartialUser`
1560+
The broadcaster running the campaign.
1561+
user: :class:`~twitchio.PartialUser`
1562+
The user who donated.
1563+
charity_name: :class:`str`
1564+
The name of the charity.
1565+
charity_description: :class:`str`
1566+
The description of the charity.
1567+
charity_logo: :class:`str`
1568+
The logo of the charity.
1569+
charity_website: :class:`str`
1570+
The websiet of the charity.
1571+
donation_value: :class:`int`
1572+
The amount of money being donated.
1573+
donation_decimal_places: :class:`int`
1574+
The decimal places to put into the :attr`~.donation_amount`.
1575+
donation_currency: :class:`str`
1576+
The currency that was donated (ex. ``USD``, ``GBP``, ``EUR``)
1577+
"""
1578+
1579+
__slots__ = ("id", "campaign_id", "broadcaster", "user", "charity_name", "charity_description", "charity_logo", "charity_website", "donation_value", "donation_decimal_places", "donation_currency")
1580+
1581+
def __init__(self, client: EventSubClient, data: dict):
1582+
self.id: str = data["id"]
1583+
self.campaign_id: str = data["campaign_id"]
1584+
self.broadcaster: PartialUser = _transform_user(client, data, "broadcaster")
1585+
self.user: PartialUser = _transform_user(client, data, "user")
1586+
self.charity_name: str = data["charity_name"]
1587+
self.charity_description: str = data["charity_description"]
1588+
self.charity_logo: str = data["charity_logo"]
1589+
self.charity_website: str = data["charity_website"]
1590+
self.donation_value: int = data["amount"]["value"]
1591+
self.donation_currency: str = data["amount"]["currency"]
1592+
self.donation_decimal_places: int = data["amount"]["decimal_places"]
1593+
15471594
_DataType = Union[
15481595
ChannelBanData,
15491596
ChannelUnbanData,
@@ -1576,6 +1623,7 @@ def __init__(self, client: EventSubClient, data: dict):
15761623
ChannelShieldModeEndData,
15771624
ChannelShoutoutCreateData,
15781625
ChannelShoutoutReceiveData,
1626+
ChannelCharityDonationData
15791627
]
15801628

15811629

@@ -1628,6 +1676,8 @@ class _SubscriptionTypes(metaclass=_SubTypesMeta):
16281676
channel_shoutout_create = "channel.shoutout.create", 1, ChannelShoutoutCreateData
16291677
channel_shoutout_receive = "channel.shoutout.receive", 1, ChannelShoutoutReceiveData
16301678

1679+
channel_charity_donate = "channel.charity_campaign.donate", 1, ChannelCharityDonationData
1680+
16311681
hypetrain_begin = "channel.hype_train.begin", 1, HypeTrainBeginProgressData
16321682
hypetrain_progress = "channel.hype_train.progress", 1, HypeTrainBeginProgressData
16331683
hypetrain_end = "channel.hype_train.end", 1, HypeTrainEndData

twitchio/ext/eventsub/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def subscribe_channel_shoutout_receive(
276276
models.SubscriptionTypes.channel_shoutout_receive, broadcaster, moderator
277277
)
278278

279+
def subscribe_channel_charity_donate(self, broadcaster: Union[PartialUser, str, int]):
280+
return self._subscribe_with_broadcaster(models.SubscriptionTypes.channel_charity_donate, broadcaster)
281+
279282
async def subscribe_user_authorization_granted(self):
280283
return await self._http.create_webhook_subscription(
281284
models.SubscriptionTypes.user_authorization_grant, {"client_id": self.client._http.client_id}

twitchio/ext/eventsub/websocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,6 @@ async def subscribe_channel_shoutout_receive(
497497
await self._subscribe_with_broadcaster_moderator(
498498
models.SubscriptionTypes.channel_shoutout_receive, broadcaster, moderator, token
499499
)
500+
501+
async def subscribe_channel_charity_donate(self, broadcaster: Union[PartialUser, str, int], token: str):
502+
await self._subscribe_with_broadcaster(models.SubscriptionTypes.channel_charity_donate, broadcaster, token)

0 commit comments

Comments
 (0)