Skip to content

Commit

Permalink
Merge branch 'main' into shoutouts-ga
Browse files Browse the repository at this point in the history
  • Loading branch information
Xemdo authored Feb 15, 2023
2 parents c325d43 + 46d6a37 commit f0d8950
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
count int
description string
gameID string
tier string
timestamp string
charityCurrentValue int
charityTargetValue int
Expand Down Expand Up @@ -122,6 +123,7 @@ func init() {
triggerCmd.Flags().Int64VarP(&cost, "cost", "C", 0, "Amount of 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.")
triggerCmd.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") // TODO: This description will need to change with https://github.com/twitchdev/twitch-cli/issues/184
triggerCmd.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
triggerCmd.Flags().IntVar(&charityCurrentValue, "charity-current-value", 0, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events.")
Expand Down Expand Up @@ -190,6 +192,7 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {
Description: description,
ItemName: itemName,
GameID: gameID,
Tier: tier,
SubscriptionStatus: subscriptionStatus,
Timestamp: timestamp,
CharityCurrentValue: charityCurrentValue,
Expand Down
1 change: 1 addition & 0 deletions docs/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Used to either create or send mock events for use with local webhooks testing.
| `--cost` | `-C` | Amount of bits or channel points redeemed/used in the event. | `-C 250` | N |
| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N |
| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N |
| `--tier` | | Tier of the subscription. | `--tier 3000` | N |


```sh
Expand Down
1 change: 1 addition & 0 deletions internal/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MockEventParameters struct {
IsPermanent bool
Description string
GameID string
Tier string
Timestamp string
CharityCurrentValue int
CharityTargetValue int
Expand Down
13 changes: 13 additions & 0 deletions internal/events/trigger/trigger_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TriggerParameters struct {
Description string
ItemName string
GameID string
Tier string
Timestamp string
EventID string // Also serves as subscription ID. See https://github.com/twitchdev/twitch-cli/issues/184
CharityCurrentValue int
Expand Down Expand Up @@ -66,6 +67,17 @@ func Fire(p TriggerParameters) (string, error) {
p.GameID = fmt.Sprint(util.RandomInt(10 * 1000))
}

switch p.Tier {
case "":
p.Tier = "1000"
case "1000", "2000", "3000":
// do nothing, these are valid values
default:
return "", fmt.Errorf(
`Discarding event: Invalid tier provided.
Valid values are 1000, 2000 or 3000`)
}

if p.EventID == "" {
p.EventID = util.RandomGUID()
}
Expand Down Expand Up @@ -98,6 +110,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
Description: p.Description,
ItemName: p.ItemName,
GameID: p.GameID,
Tier: p.Tier,
SubscriptionStatus: p.SubscriptionStatus,
Timestamp: p.Timestamp,
CharityCurrentValue: p.CharityCurrentValue,
Expand Down
2 changes: 1 addition & 1 deletion internal/events/types/subscribe/sub_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
BroadcasterUserID: params.ToUserID,
BroadcasterUserLogin: params.ToUserName,
BroadcasterUserName: params.ToUserName,
Tier: "1000",
Tier: params.Tier,
IsGift: params.IsGift,
},
}
Expand Down
3 changes: 3 additions & 0 deletions internal/events/types/subscribe/sub_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var fromUser = "1234"
var toUser = "4567"
var tierTwo = "2000"

func TestEventSub(t *testing.T) {
a := test_setup.SetupTestEnv(t)
Expand All @@ -23,6 +24,7 @@ func TestEventSub(t *testing.T) {
Transport: models.TransportEventSub,
SubscriptionStatus: "enabled",
Trigger: "subscribe",
Tier: tierTwo,
}

r, err := Event{}.GenerateEvent(params)
Expand All @@ -34,6 +36,7 @@ func TestEventSub(t *testing.T) {

a.Equal(toUser, body.Event.BroadcasterUserID, "Expected to user %v, got %v", toUser, body.Event.BroadcasterUserID)
a.Equal(fromUser, body.Event.UserID, "Expected from user %v, got %v", r.ToUser, body.Event.UserID)
a.Equal(tierTwo, body.Event.Tier, "Expected tier %v, got %v", tierTwo, body.Event.Tier)
}

func TestFakeTransport(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
BroadcasterUserID: params.ToUserID,
BroadcasterUserLogin: params.ToUserName,
BroadcasterUserName: params.ToUserName,
Tier: "1000",
Tier: params.Tier,
Message: models.SubscribeMessageEventSubMessage{
Text: "Hello from the Twitch CLI! twitchdevLeek",
Emotes: []models.SubscribeMessageEventSubMessageEmote{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var toUser = "4567"
func TestEventSub(t *testing.T) {
a := test_setup.SetupTestEnv(t)
ten := 10
tierThree := "3000"

params := *&events.MockEventParameters{
FromUserID: fromUser,
Expand Down Expand Up @@ -44,6 +45,7 @@ func TestEventSub(t *testing.T) {
SubscriptionStatus: "enabled",
Cost: int64(ten),
IsAnonymous: true,
Tier: tierThree,
}

r, err = Event{}.GenerateEvent(params)
Expand All @@ -53,6 +55,7 @@ func TestEventSub(t *testing.T) {
a.Nil(err)
a.Nil(body.Event.StreakMonths)
a.GreaterOrEqual(body.Event.CumulativeMonths, 10)
a.Equal(body.Event.Tier, "3000")
}

func TestFakeTransport(t *testing.T) {
Expand Down

0 comments on commit f0d8950

Please sign in to comment.