-
Notifications
You must be signed in to change notification settings - Fork 96
feat: GetHypetrainStatus and refactor EventSub for Hype Train V2 events #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,62 @@ type HypeTrainContribuition struct { | |
| User string `json:"user"` | ||
| } | ||
|
|
||
| // HypeTrainStatusContribution contains information about a contribution to a Hype Train | ||
| type HypeTrainStatusContribution struct { | ||
| UserID string `json:"user_id"` | ||
| UserLogin string `json:"user_login"` | ||
| UserName string `json:"user_name"` | ||
| Type string `json:"type"` | ||
| Total int64 `json:"total"` | ||
|
||
| } | ||
|
|
||
| type SharedTrainParticipant struct { | ||
| BroadcasterUserID string `json:"broadcaster_user_id"` | ||
| BroadcasterUserLogin string `json:"broadcaster_user_login"` | ||
| BroadcasterUserName string `json:"broadcaster_user_name"` | ||
| } | ||
nicklaw5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| type CurrentHypeTrainStatus struct { | ||
| ID string `json:"id"` | ||
| BroadcasterUserID string `json:"broadcaster_user_id"` | ||
| BroadcasterUserLogin string `json:"broadcaster_user_login"` | ||
| BroadcasterUserName string `json:"broadcaster_user_name"` | ||
| Level int64 `json:"level"` | ||
| Total int64 `json:"total"` | ||
| Progress int64 `json:"progress"` | ||
| Goal int64 `json:"goal"` | ||
| TopContributions []HypeTrainStatusContribution `json:"top_contributions"` | ||
| SharedTrainParticipants []SharedTrainParticipant `json:"shared_train_participants"` | ||
| StartedAt Time `json:"started_at"` | ||
| ExpiresAt Time `json:"expires_at"` | ||
| Type string `json:"type"` | ||
| } | ||
|
|
||
| type AllTimeHighHypeTrainStatus struct { | ||
| Level int64 `json:"level"` | ||
| Total int64 `json:"total"` | ||
| AchievedAt Time `json:"achieved_at"` | ||
| } | ||
|
|
||
| type HypeTrainStatus struct { | ||
| Current *CurrentHypeTrainStatus `json:"current"` | ||
| AllTimeHigh *AllTimeHighHypeTrainStatus `json:"all_time_high"` | ||
| SharedAllTimeHigh *AllTimeHighHypeTrainStatus `json:"shared_all_time_high"` | ||
| } | ||
|
|
||
| type ManyHypeTrainStatuses struct { | ||
| Statuses []HypeTrainStatus `json:"data"` | ||
| } | ||
|
|
||
| type HypeTrainStatusResponse struct { | ||
| ResponseCommon | ||
| Data ManyHypeTrainStatuses | ||
| } | ||
|
|
||
| type HypeTrainStatusParams struct { | ||
| BroadcasterID string `query:"broadcaster_id"` | ||
| } | ||
|
|
||
| type HypeTrainEvent struct { | ||
| ID string `json:"id"` | ||
| EventType string `json:"event_type"` | ||
|
|
@@ -44,6 +100,23 @@ type HypeTrainEventsParams struct { | |
| ID string `query:"id"` | ||
| } | ||
|
|
||
| // GetHypeTrainStatus gets the Hype Train status for the specified broadcaster. | ||
| // Required scope: channel:read:hype_train | ||
| func (c *Client) GetHypeTrainStatus(params *HypeTrainStatusParams) (*HypeTrainStatusResponse, error) { | ||
| resp, err := c.get("/hypetrain/status", &ManyHypeTrainStatuses{}, params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| status := &HypeTrainStatusResponse{} | ||
| resp.HydrateResponseCommon(&status.ResponseCommon) | ||
| status.Data.Statuses = resp.Data.(*ManyHypeTrainStatuses).Statuses | ||
|
|
||
| return status, nil | ||
| } | ||
|
|
||
| // GetHypeTrainEvents gets Hype Train events for a broadcaster. | ||
| // Deprecated: Use GetHypeTrainStatus instead. | ||
| // Required scope: channel:read:hype_train | ||
| func (c *Client) GetHypeTrainEvents(params *HypeTrainEventsParams) (*HypeTrainEventsResponse, error) { | ||
| resp, err := c.get("/hypetrain/events", &ManyHypeTrainEvents{}, params) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
EventSubCharityAmountstruct now has bothValueandAmountfields which appear to serve the same purpose. This is confusing and potentially error-prone. If both fields are required by the API, add a comment explaining the difference between them.