Skip to content

Commit

Permalink
Merge pull request #298 from twitchdev/feat/192
Browse files Browse the repository at this point in the history
Support for larger drop payloads
  • Loading branch information
Xemdo authored Dec 13, 2023
2 parents 10482e3 + 648a468 commit 237b300
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func init() {
triggerCmd.Flags().StringVarP(&subscriptionStatus, "subscription-status", "r", "enabled", "Status of the Subscription object (.subscription.status in JSON). Defaults to \"enabled\".")
triggerCmd.Flags().StringVarP(&itemID, "item-id", "i", "", "Manually set the ID of the event payload item (for example the reward ID in redemption events). For stream events, this is the game ID.")
triggerCmd.Flags().StringVarP(&itemName, "item-name", "n", "", "Manually set the name of the event payload item (for example the reward ID in redemption events). For stream events, this is the game title.")
triggerCmd.Flags().Int64VarP(&cost, "cost", "C", 0, "Amount of subscriptions, bits, or channel points redeemed/used in the event.")
triggerCmd.Flags().Int64VarP(&cost, "cost", "C", 0, "Amount of drops, subscriptions, bits, or channel points redeemed/used in the event.")
triggerCmd.Flags().StringVarP(&description, "description", "d", "", "Title the stream should be updated with.")
triggerCmd.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.")
triggerCmd.Flags().StringVarP(&tier, "tier", "", "", "Sets the subscription tier. Valid values are 1000, 2000, and 3000.")
Expand Down
53 changes: 36 additions & 17 deletions internal/events/types/drop/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,41 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
case models.TransportWebhook:
campaignId := util.RandomGUID()

dropEvents := []models.DropsEntitlementEventSubEvent{
{
ID: util.RandomGUID(),
Data: models.DropsEntitlementEventSubEventData{
OrganizationID: params.FromUserID,
CategoryID: params.GameID,
CategoryName: "Special Events",
CampaignID: campaignId,
EntitlementID: util.RandomGUID(),
BenefitID: params.ItemID,
UserID: params.ToUserID,
UserName: params.ToUserName,
UserLogin: params.ToUserName,
CreatedAt: params.Timestamp,
},
},
}

for i := int64(1); i < params.Cost; i++ {
// for the new events, we'll use the entitlement above except generating new users as to avoid conflicting drops
dropEvents = append(dropEvents, models.DropsEntitlementEventSubEvent{
ID: util.RandomGUID(),
Data: models.DropsEntitlementEventSubEventData{
OrganizationID: params.FromUserID,
CategoryID: params.GameID,
CategoryName: "Special Events",
CampaignID: campaignId,
EntitlementID: util.RandomGUID(),
BenefitID: params.ItemID,
UserID: util.RandomUserID(),
UserName: params.ToUserName,
UserLogin: params.ToUserName,
CreatedAt: params.Timestamp,
}})
}
body := &models.DropsEntitlementEventSubResponse{
Subscription: models.EventsubSubscription{
ID: params.ID,
Expand All @@ -59,23 +94,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Cost: 0,
CreatedAt: params.Timestamp,
},
Events: []models.DropsEntitlementEventSubEvent{
{
ID: util.RandomGUID(),
Data: models.DropsEntitlementEventSubEventData{
OrganizationID: params.FromUserID,
CategoryID: params.GameID,
CategoryName: "Special Events",
CampaignID: campaignId,
EntitlementID: util.RandomGUID(),
BenefitID: params.ItemID,
UserID: params.ToUserID,
UserName: params.ToUserName,
UserLogin: params.ToUserName,
CreatedAt: params.Timestamp,
},
},
},
Events: dropEvents,
}
event, err = json.Marshal(body)
if err != nil {
Expand Down

0 comments on commit 237b300

Please sign in to comment.