Skip to content

Commit

Permalink
ES Goals
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed Aug 24, 2024
1 parent 2623136 commit d02af73
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 7 deletions.
56 changes: 52 additions & 4 deletions twitchio/eventsub/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
"ChannelVIPRemoveSubscription",
"ChannelWarningAcknowledgementSubscription",
"ChannelWarningSendSubscription",
"GoalBeginSubscription",
"GoalProgressSubscription",
"GoalEndSubscription",
"HypeTrainBeginSubscription",
"HypeTrainProgressSubscription",
"HypeTrainEndSubscription",
Expand Down Expand Up @@ -642,8 +645,8 @@ def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id, "moderator_user_id": self.moderator_user_id}


class HypeTrainProgressSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.hype_train.progress"]] = "channel.hype_train.progress"
class GoalBeginSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.goal.begin"]] = "channel.goal.begin"
version: ClassVar[Literal["1"]] = "1"

def __init__(self, **condition: Unpack[Condition]) -> None:
Expand All @@ -657,8 +660,23 @@ def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id}


class HypeTrainEndSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.hype_train.end"]] = "channel.hype_train.end"
class GoalProgressSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.goal.progress"]] = "channel.goal.progress"
version: ClassVar[Literal["1"]] = "1"

def __init__(self, **condition: Unpack[Condition]) -> None:
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")

if not self.broadcaster_user_id:
raise ValueError('The parameter "broadcaster_user_id" must be passed.')

@property
def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id}


class GoalEndSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.goal.end"]] = "channel.goal.end"
version: ClassVar[Literal["1"]] = "1"

def __init__(self, **condition: Unpack[Condition]) -> None:
Expand Down Expand Up @@ -687,6 +705,36 @@ def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id}


class HypeTrainProgressSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.hype_train.progress"]] = "channel.hype_train.progress"
version: ClassVar[Literal["1"]] = "1"

def __init__(self, **condition: Unpack[Condition]) -> None:
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")

if not self.broadcaster_user_id:
raise ValueError('The parameter "broadcaster_user_id" must be passed.')

@property
def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id}


class HypeTrainEndSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.hype_train.end"]] = "channel.hype_train.end"
version: ClassVar[Literal["1"]] = "1"

def __init__(self, **condition: Unpack[Condition]) -> None:
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")

if not self.broadcaster_user_id:
raise ValueError('The parameter "broadcaster_user_id" must be passed.')

@property
def condition(self) -> Condition:
return {"broadcaster_user_id": self.broadcaster_user_id}


class ShieldModeBeginSubscription(SubscriptionPayload):
type: ClassVar[Literal["channel.shield_mode.begin"]] = "channel.shield_mode.begin"
version: ClassVar[Literal["1"]] = "1"
Expand Down
90 changes: 90 additions & 0 deletions twitchio/models/eventsub_.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,96 @@ def __repr__(self) -> str:
return f"<HypeTrainContribution user={self.user} type={self.type} total={self.total}>"


class GoalBegin(BaseEvent):
__slots__ = ("id", "broadcaster", "type", "description", "current_amount", "target_amount", "started_at")

def __init__(self, payload: GoalBeginEvent, *, http: HTTPClient) -> None:
self.id: str = payload["id"]
self.broadcaster: PartialUser = PartialUser(
payload["broadcaster_user_id"], payload["broadcaster_user_login"], http=http
)
self.type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
] = payload["type"]
self.description: str = payload["description"]
self.current_amount: int = int(payload["current_amount"])
self.target_amount: int = int(payload["target_amount"])
self.started_at: datetime.datetime = parse_timestamp(payload["started_at"])

def __repr__(self) -> str:
return f"<GoalBegin id={self.id} broadcaster={self.broadcaster} type={self.type} target_amount={self.target_amount} started_at={self.started_at}>"


class GoalProgress(BaseEvent):
__slots__ = ("id", "broadcaster", "type", "description", "current_amount", "target_amount", "started_at")

def __init__(self, payload: GoalProgressEvent, *, http: HTTPClient) -> None:
self.id: str = payload["id"]
self.broadcaster: PartialUser = PartialUser(
payload["broadcaster_user_id"], payload["broadcaster_user_login"], http=http
)
self.type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
] = payload["type"]
self.description: str = payload["description"]
self.current_amount: int = int(payload["current_amount"])
self.target_amount: int = int(payload["target_amount"])
self.started_at: datetime.datetime = parse_timestamp(payload["started_at"])

def __repr__(self) -> str:
return f"<GoalProgress id={self.id} broadcaster={self.broadcaster} type={self.type} current_amount={self.current_amount} target_amount={self.target_amount} started_at={self.started_at}>"


class GoalEnd(BaseEvent):
__slots__ = (
"id",
"broadcaster",
"type",
"description",
"current_amount",
"target_amount",
"started_at",
"ended_at",
"achieved",
)

def __init__(self, payload: GoalEndEvent, *, http: HTTPClient) -> None:
self.id: str = payload["id"]
self.broadcaster: PartialUser = PartialUser(
payload["broadcaster_user_id"], payload["broadcaster_user_login"], http=http
)
self.type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
] = payload["type"]
self.description: str = payload["description"]
self.current_amount: int = int(payload["current_amount"])
self.target_amount: int = int(payload["target_amount"])
self.started_at: datetime.datetime = parse_timestamp(payload["started_at"])
self.ended_at: datetime.datetime = parse_timestamp(payload["ended_at"])
self.achieved: bool = bool(payload["is_achieved"])

def __repr__(self) -> str:
return f"<GoalEnd id={self.id} broadcaster={self.broadcaster} type={self.type} started_at={self.started_at} ended_at={self.ended_at}>"


class HypeTrainBegin(BaseEvent):
subscription_type = "channel.hype_train.begin"

Expand Down
45 changes: 42 additions & 3 deletions twitchio/types_/eventsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"ChatResubData",
"ChatSubData",
"ChatSubGiftData",
"GoalBeginEvent",
"GoalProgressEvent",
"GoalEndEvent",
"HypeTrainBeginEvent",
"HypeTrainProgressEvent",
"HypeTrainEndEvent",
Expand Down Expand Up @@ -825,12 +828,40 @@ class ChannelWarningSendEvent(BroadcasterModUserEvent):
chat_rules_cited: list[str] | None


class GoalBeginProgressEvent(TypedDict):
class GoalBeginEvent(TypedDict):
id: str
broadcaster_user_id: str
broadcaster_user_login: str
broadcaster_user_name: str
type: str
type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
]
description: str
current_amount: int
target_amount: int
started_at: str


class GoalProgressEvent(TypedDict):
id: str
broadcaster_user_id: str
broadcaster_user_login: str
broadcaster_user_name: str
type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
]
description: str
current_amount: int
target_amount: int
Expand All @@ -842,7 +873,15 @@ class GoalEndEvent(TypedDict):
broadcaster_user_id: str
broadcaster_user_login: str
broadcaster_user_name: str
type: str
type: Literal[
"follow",
"subscription",
"subscription_count",
"new_subscription",
"new_subscription_count",
"new_bit",
"new_cheerer",
]
description: str
is_achieved: bool
current_amount: int
Expand Down

0 comments on commit d02af73

Please sign in to comment.