Skip to content

Commit

Permalink
Merge pull request #148 from twitchdev/bugfix/hype-train-version-fix
Browse files Browse the repository at this point in the history
bugfix: addressing hype train events issues #130 & #131
  • Loading branch information
lleadbet authored Apr 7, 2022
2 parents 454e4bc + 4385f08 commit 1a1af9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions internal/events/types/hype_train/hype_train_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
localLevel := util.RandomInt(4) + 1
localTotal := util.RandomInt(10 * 100)
localGoal := util.RandomInt(10*100*100) + localTotal
localProgress := (localTotal / localGoal)
localProgress := localTotal - util.RandomInt(100)

switch params.Transport {
case models.TransportEventSub:
body := *&models.HypeTrainEventSubResponse{
body := models.HypeTrainEventSubResponse{
Subscription: models.EventsubSubscription{
ID: params.ID,
Status: "enabled",
Type: triggerMapping[params.Transport][params.Trigger],
Version: "1.0",
Version: "1",
Condition: models.EventsubCondition{
BroadcasterUserID: params.ToUserID,
},
Expand All @@ -62,7 +62,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
BroadcasterUserLogin: params.ToUserName,
BroadcasterUserName: params.ToUserName,
Total: localTotal,
Progress: localProgress,
Progress: &localProgress,
Goal: localGoal,
TopContributions: []models.ContributionData{
{
Expand Down Expand Up @@ -91,6 +91,9 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
ExpiresAtTimestamp: util.GetTimestamp().Add(5 * time.Minute).Format(time.RFC3339Nano),
},
}
if params.Trigger == "hype-train-begin" {
body.Event.Progress = &localTotal
}
if params.Trigger == "hype-train-progress" {
body.Event.Level = localLevel
}
Expand All @@ -100,7 +103,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
body.Event.ExpiresAtTimestamp = ""
body.Event.Goal = 0
body.Event.Level = localLevel
body.Event.Progress = 0
body.Event.Progress = nil
body.Event.StartedAtTimestamp = util.GetTimestamp().Add(5 * -time.Minute).Format(time.RFC3339Nano)
}
event, err = json.Marshal(body)
Expand Down
2 changes: 1 addition & 1 deletion internal/models/hype_train.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type HypeTrainEventSubEvent struct {
BroadcasterUserName string `json:"broadcaster_user_name"`
Level int64 `json:"level,omitempty"`
Total int64 `json:"total"`
Progress int64 `json:"progress,omitempty"`
Progress *int64 `json:"progress,omitempty"`
Goal int64 `json:"goal,omitempty"`
TopContributions []ContributionData `json:"top_contributions"`
LastContribution ContributionData `json:"last_contribution,omitempty"`
Expand Down

0 comments on commit 1a1af9b

Please sign in to comment.