Skip to content

Commit fa22b7f

Browse files
author
lleadbet
committed
updating per pr feedback
1 parent 3f42430 commit fa22b7f

File tree

11 files changed

+40
-27
lines changed

11 files changed

+40
-27
lines changed

cmd/events.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
cost int64
2929
count int
3030
description string
31+
gameID string
3132
)
3233

3334
var eventCmd = &cobra.Command{
@@ -90,6 +91,7 @@ func init() {
9091
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.")
9192
triggerCmd.Flags().Int64VarP(&cost, "cost", "C", 0, "Amount of bits or channel points redeemed/used in the event.")
9293
triggerCmd.Flags().StringVarP(&description, "description", "d", "", "Title the stream should be updated with.")
94+
triggerCmd.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.")
9395

9496
// retrigger flags
9597
retriggerCmd.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event.")
@@ -134,6 +136,7 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {
134136
Cost: cost,
135137
Description: description,
136138
ItemName: itemName,
139+
GameID: gameID,
137140
})
138141

139142
if err != nil {

docs/event.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,23 @@ Used to either create or send mock events for use with local webhooks testing.
5757

5858
**Flags**
5959

60-
| Flag | Shorthand | Description | Example | Required? (Y/N) |
61-
|---------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|-----------------|
62-
| `--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N |
63-
| `--transport` | `-T` | The method used to send events. Default is `eventsub`, but can send using `websub`. | `-T websub` | N |
64-
| `--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N |
65-
| `--from-user` | `-f` | Denotes the sender's TUID of the event, for example the user that follows another user or the subscriber to a broadcaster. | `-f 44635596` | N |
66-
| `--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID | `-g 44635596` | N |
67-
| `--secret` | `-s` | Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC. | `-s testsecret` | N |
68-
| `--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N |
69-
| `--anonymous` | `-a` | If the event is anonymous. Only applies to `gift` and `cheer` events. | `-a` | N |
70-
| `--status` | `-S` | Status of the event object, currently applies to channel points redemptions. | `-S fulfilled` | N |
71-
| `--item-id` | `-i` | Manually set the ID of the event payload item (for example the reward ID in redemption events or game in stream events). | `-i 032e4a6c-4aef-11eb-a9f5-1f703d1f0b92` | N |
72-
| `--item-name` | `-n` | Manually set the name of the event payload item (for example the reward ID in redemption events or game name in stream events). | `-n "Science & Technology"` | N |
73-
| `--cost` | `-C` | Amount of bits or channel points redeemed/used in the event. | `-C 250` | N |
74-
| `--description` | `-d` | Title the stream should be updated/started with. Additionally used as the category ID for Drops events. | `-d Awesome new title!` | N |
60+
Flag | Shorthand | Description | Example | Required? (Y/N)
61+
---------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|-----------------
62+
`--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N
63+
`--transport` | `-T` | The method used to send events. Default is `eventsub`, but can send using `websub`. | `-T websub` | N
64+
`--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N
65+
`--from-user` | `-f` | Denotes the sender's TUID of the event, for example the user that follows another user or the subscriber to a broadcaster. | `-f 44635596` | N
66+
`--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID | `-g 44635596` | N
67+
`--secret` | `-s` | Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC. | `-s testsecret` | N
68+
`--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N
69+
`--anonymous` | `-a` | If the event is anonymous. Only applies to `gift` and `cheer` events. | `-a` | N
70+
`--status` | `-S` | Status of the event object, currently applies to channel points redemptions. | `-S fulfilled` | N
71+
`--item-id` | `-i` | Manually set the ID of the event payload item (for example the reward ID in redemption events or game in stream events). | `-i 032e4a6c-4aef-11eb-a9f5-1f703d1f0b92` | N
72+
`--item-name` | `-n` | Manually set the name of the event payload item (for example the reward ID in redemption events or game name in stream events). | `-n "Science & Technology"` | N
73+
`--cost` | `-C` | Amount of bits or channel points redeemed/used in the event. | `-C 250` | N
74+
`--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N
75+
`--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N
76+
7577

7678

7779
**Examples**

internal/events/event.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type MockEventParameters struct {
2020
Cost int64
2121
IsPermanent bool
2222
Description string
23+
GameID string
2324
}
2425

2526
type MockEventResponse struct {

internal/events/trigger/trigger_event.go

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type TriggerParameters struct {
3030
Count int
3131
Description string
3232
ItemName string
33+
GameID string
3334
}
3435

3536
type TriggerResponse struct {
@@ -53,6 +54,9 @@ func Fire(p TriggerParameters) (string, error) {
5354
p.FromUser = util.RandomUserID()
5455
}
5556

57+
if p.GameID == "" {
58+
p.GameID = fmt.Sprint(util.RandomInt(10 * 1000))
59+
}
5660
eventParamaters := events.MockEventParameters{
5761
ID: util.RandomGUID(),
5862
Trigger: p.Event,
@@ -67,6 +71,7 @@ func Fire(p TriggerParameters) (string, error) {
6771
ItemID: p.ItemID,
6872
Description: p.Description,
6973
ItemName: p.ItemName,
74+
GameID: p.GameID,
7075
}
7176

7277
e, err := types.GetByTriggerAndTransport(p.Event, p.Transport)

internal/events/types/drop/drop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
6161
ID: util.RandomGUID(),
6262
Data: models.DropsEntitlementEventSubEventData{
6363
OrganizationID: params.FromUserID,
64-
CategoryID: params.Description,
64+
CategoryID: params.GameID,
6565
CategoryName: "",
6666
CampaignID: util.RandomGUID(),
6767
EntitlementID: util.RandomGUID(),

internal/events/types/drop/drop_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestEventSub(t *testing.T) {
2727
r, err := Event{}.GenerateEvent(params)
2828
a.Nil(err)
2929

30-
var body models.DropsEntitlementEventSubResponse // replace with actual value
30+
var body models.DropsEntitlementEventSubResponse
3131
err = json.Unmarshal(r.JSON, &body)
3232
a.Nil(err)
3333

internal/events/types/gift/channel_gift_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestEventSub(t *testing.T) {
2929
r, err := Event{}.GenerateEvent(params)
3030
a.Nil(err)
3131

32-
var body models.GiftEventSubResponse // replace with actual value
32+
var body models.GiftEventSubResponse
3333
err = json.Unmarshal(r.JSON, &body)
3434
a.Nil(err)
3535

internal/events/types/raid/raid_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestEventSub(t *testing.T) {
2727
r, err := Event{}.GenerateEvent(params)
2828
a.Nil(err)
2929

30-
var body models.SubEventSubResponse // replace with actual value
30+
var body models.SubEventSubResponse
3131
err = json.Unmarshal(r.JSON, &body)
3232
a.Nil(err)
3333

internal/events/types/stream_change/stream_change_event.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
3737
if params.Description == "" {
3838
params.Description = "Example title from the CLI!"
3939
}
40-
if params.ItemID == "" {
41-
params.ItemID = "509658"
40+
if params.ItemID == "" && params.GameID == "" {
41+
params.GameID = "509658"
42+
} else if params.ItemID != "" && params.GameID == "" {
43+
params.GameID = params.ItemID
4244
}
4345
if params.ItemName == "" {
4446
params.ItemName = "Just Chatting"
@@ -69,7 +71,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
6971
BroadcasterUserName: params.ToUserName,
7072
StreamTitle: params.Description,
7173
StreamLanguage: "en",
72-
StreamCategoryID: params.ItemID,
74+
StreamCategoryID: params.GameID,
7375
StreamCategoryName: params.ItemName,
7476
IsMature: false,
7577
},
@@ -86,8 +88,8 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
8688
BroadcasterUserID: params.ToUserID,
8789
BroadcasterUserLogin: params.ToUserName,
8890
BroadcasterUserName: params.ToUserName,
89-
StreamCategoryID: params.ItemID,
90-
StreamCategoryName: "Just Chatting",
91+
StreamCategoryID: params.GameID,
92+
StreamCategoryName: params.ItemName,
9193
StreamType: "live",
9294
StreamTitle: params.Description,
9395
StreamViewerCount: 9848,

internal/events/types/stream_change/stream_change_event_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestEventSub(t *testing.T) {
4040
ToUserID: toUser,
4141
Transport: models.TransportEventSub,
4242
Trigger: "stream_change",
43-
ItemID: "1234",
43+
GameID: "1234",
4444
}
4545

4646
r, err = Event{}.GenerateEvent(params)
@@ -65,7 +65,7 @@ func TestWebSubStreamChange(t *testing.T) {
6565
Transport: models.TransportWebSub,
6666
Trigger: "stream-change",
6767
Description: newStreamTitle,
68-
ItemID: "1234",
68+
GameID: "1234",
6969
}
7070

7171
r, err := Event{}.GenerateEvent(params)

internal/events/types/subscription_message/subscription_message_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestEventSub(t *testing.T) {
2929
r, err := Event{}.GenerateEvent(params)
3030
a.Nil(err)
3131

32-
var body models.SubscribeMessageEventSubResponse // replace with actual value
32+
var body models.SubscribeMessageEventSubResponse
3333
err = json.Unmarshal(r.JSON, &body)
3434
a.Nil(err)
3535
a.Equal(&ten, body.Event.StreakMonths)

0 commit comments

Comments
 (0)