diff --git a/internal/events/types/hype_train/hype_train_event.go b/internal/events/types/hype_train/hype_train_event.go index 6c065c20..54c7479f 100644 --- a/internal/events/types/hype_train/hype_train_event.go +++ b/internal/events/types/hype_train/hype_train_event.go @@ -1,13 +1,16 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package hype_train + import ( "encoding/json" "time" + "github.com/twitchdev/twitch-cli/internal/events" "github.com/twitchdev/twitch-cli/internal/models" "github.com/twitchdev/twitch-cli/internal/util" ) + var transportsSupported = map[string]bool{ models.TransportWebSub: true, models.TransportEventSub: true, @@ -25,7 +28,9 @@ var triggerMapping = map[string]map[string]string{ "hype-train-end": "channel.hype_train.end", }, } + type Event struct{} + func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEventResponse, error) { var event []byte var err error @@ -36,6 +41,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven localTotal := util.RandomViewerCount() localGoal := util.RandomViewerCount() localProgress := (localTotal / localGoal) + switch params.Transport { case models.TransportEventSub: body := *&models.HypeTrainEventSubResponse{ @@ -77,8 +83,8 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven }, }, LastContribution: models.ContributionData{ - TotalContribution: util.RandomViewerCount(), - TypeOfContribution: util.RandomType(), + TotalContribution: lastTotal, + TypeOfContribution: lastType, UserWhoMadeContribution: lastUser, UserNameWhoMadeContribution: "cli_user2", UserLoginWhoMadeContribution: "cli_user2", @@ -109,22 +115,22 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven Goal: localGoal, Id: util.RandomGUID(), LastContribution: models.ContributionData{ - TotalContribution: lastTotal, - TypeOfContribution: lastType, - UserWhoMadeContribution: lastUser, + TotalContribution: lastTotal, + TypeOfContribution: lastType, + WebSubUser: lastUser, }, Level: util.RandomViewerCount() % 4, StartedAtTimestamp: util.GetTimestamp().Format(time.RFC3339), TopContributions: []models.ContributionData{ { - TotalContribution: lastTotal, - TypeOfContribution: lastType, - UserWhoMadeContribution: lastUser, + TotalContribution: lastTotal, + TypeOfContribution: lastType, + WebSubUser: lastUser, }, { - TotalContribution: util.RandomViewerCount(), - TypeOfContribution: util.RandomType(), - UserWhoMadeContribution: util.RandomUserID(), + TotalContribution: util.RandomViewerCount(), + TypeOfContribution: util.RandomType(), + WebSubUser: util.RandomUserID(), }, }, Total: localTotal, @@ -159,4 +165,4 @@ func (e Event) ValidTrigger(t string) bool { } func (e Event) GetTopic(transport string, trigger string) string { return triggerMapping[transport][trigger] -} \ No newline at end of file +} diff --git a/internal/models/hype_train.go b/internal/models/hype_train.go index aa5073c2..3ba1c24b 100644 --- a/internal/models/hype_train.go +++ b/internal/models/hype_train.go @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 package models -type ContributionData struct{ - TotalContribution int64 `json:"total"` - TypeOfContribution string `json:"type"` - UserWhoMadeContribution string `json:"user_id"` - UserNameWhoMadeContribution string `json:"user_name"` - UserLoginWhoMadeContribution string `json:"user_login"` +type ContributionData struct { + TotalContribution int64 `json:"total"` + TypeOfContribution string `json:"type"` + WebSubUser string `json:"user,omitempty"` + UserWhoMadeContribution string `json:"user_id,omitempty"` + UserNameWhoMadeContribution string `json:"user_name,omitempty"` + UserLoginWhoMadeContribution string `json:"user_login,omitempty"` } type HypeTrainWebSubEvent struct { @@ -19,16 +20,16 @@ type HypeTrainWebSubEvent struct { } type HypeTrainWebsubEventData struct { - BroadcasterID string `json:"broadcaster_id"` - CooldownEndTimestamp string `json:"cooldown_end_time"` - ExpiresAtTimestamp string `json:"expires_at"` - Goal int64 `json:"goal,omitempty"` - Id string `json:"id,omitempty"` - LastContribution ContributionData `json:"last_contribution,omitempty"` - Level int64 `json:"level,omitempty"` - StartedAtTimestamp string `json:"started_at,omitempty"` - TopContributions []ContributionData `json:"top_contributions"` - Total int64 `json:"total"` + BroadcasterID string `json:"broadcaster_id"` + CooldownEndTimestamp string `json:"cooldown_end_time"` + ExpiresAtTimestamp string `json:"expires_at"` + Goal int64 `json:"goal,omitempty"` + Id string `json:"id,omitempty"` + LastContribution ContributionData `json:"last_contribution,omitempty"` + Level int64 `json:"level,omitempty"` + StartedAtTimestamp string `json:"started_at,omitempty"` + TopContributions []ContributionData `json:"top_contributions"` + Total int64 `json:"total"` } type HypeTrainWebSubResponse struct { @@ -36,22 +37,22 @@ type HypeTrainWebSubResponse struct { } type HypeTrainEventSubResponse struct { - Subscription EventsubSubscription `json:"subscription"` - Event HypeTrainEventSubEvent `json:"event"` + Subscription EventsubSubscription `json:"subscription"` + Event HypeTrainEventSubEvent `json:"event"` } type HypeTrainEventSubEvent struct { - BroadcasterUserID string `json:"broadcaster_user_id"` - BroadcasterUserLogin string `json:"broadcaster_user_login"` - BroadcasterUserName string `json:"broadcaster_user_name"` - Level int64 `json:"level,omitempty"` - Total int64 `json:"total"` - Progress int64 `json:"progress,omitempty"` - Goal int64 `json:"goal,omitempty"` - TopContributions []ContributionData `json:"top_contributions"` - LastContribution ContributionData `json:"last_contribution,omitempty"` - StartedAtTimestamp string `json:"started_at,omitempty"` - ExpiresAtTimestamp string `json:"expires_at,omitempty"` - EndedAtTimestamp string `json:"ended_at,omitempty"` - CooldownEndsAtTimestamp string `json:"cooldown_ends_at,omitempty"` -} \ No newline at end of file + BroadcasterUserID string `json:"broadcaster_user_id"` + BroadcasterUserLogin string `json:"broadcaster_user_login"` + BroadcasterUserName string `json:"broadcaster_user_name"` + Level int64 `json:"level,omitempty"` + Total int64 `json:"total"` + Progress int64 `json:"progress,omitempty"` + Goal int64 `json:"goal,omitempty"` + TopContributions []ContributionData `json:"top_contributions"` + LastContribution ContributionData `json:"last_contribution,omitempty"` + StartedAtTimestamp string `json:"started_at,omitempty"` + ExpiresAtTimestamp string `json:"expires_at,omitempty"` + EndedAtTimestamp string `json:"ended_at,omitempty"` + CooldownEndsAtTimestamp string `json:"cooldown_ends_at,omitempty"` +}