diff --git a/companion/adapter/inbound/twitchchat/client.go b/companion/adapter/inbound/twitchchat/client.go index 81b456a..6030dc5 100644 --- a/companion/adapter/inbound/twitchchat/client.go +++ b/companion/adapter/inbound/twitchchat/client.go @@ -49,17 +49,21 @@ func (t *twitchChat) FakerShaker(interval time.Duration) { for { time.Sleep(interval) - switch rand.Intn(1) { + switch rand.Intn(5) { case 0: t.client.Say("channel", fmt.Sprintf("bits --bitscount %v Woohoo!", rand.Intn(500))) + //fallthrough case 1: t.client.Say("channel", fmt.Sprintf("subgift --tier %v --username glEnd2", rand.Intn(3)+1)) + //fallthrough case 2: t.client.Say("channel", fmt.Sprintf("submysterygift --count %v --username zebiniasis", rand.Intn(15)+1)) + //fallthrough case 3: - t.client.Say("channel", fmt.Sprintf("subscription --tier %v --username glEnd2", rand.Intn(3)+1)) + t.client.Say("channel", fmt.Sprintf("subscription --tier %v", rand.Intn(3)+1)) + //fallthrough case 4: - t.client.Say("channel", "resubscription") + t.client.Say("channel", fmt.Sprintf("resubscription --tier %v", rand.Intn(3)+1)) } } @@ -105,10 +109,18 @@ func (t *twitchChat) Connect(events chan<- companion.StreamEvent, messages chan< EventType: companion.EventTypeSub, Amount: count, } - case "resub": - fallthrough + case "sub": fallthrough + + case "resub": + plan, _ := strconv.Atoi(message.MsgParams["msg-param-sub-plan"]) + months, _ := strconv.Atoi(message.MsgParams["msg-param-cumulative-months"]) + events <- companion.StreamEvent{ + EventType: planToEventType(plan), + Amount: months, + } + case "subgift": events <- companion.StreamEvent{ EventType: companion.EventTypeSub, @@ -126,3 +138,14 @@ func (t *twitchChat) Connect(events chan<- companion.StreamEvent, messages chan< return nil } + +func planToEventType(plan int) companion.EventType { + switch plan { + case 3000: + return companion.EventTypeT3Sub + case 2000: + return companion.EventTypeT2Sub + default: + return companion.EventTypeT1Sub + } +} diff --git a/companion/cmd/main.go b/companion/cmd/main.go index 62d4fdf..c0205ee 100644 --- a/companion/cmd/main.go +++ b/companion/cmd/main.go @@ -67,7 +67,7 @@ func main() { } if conf.Twitch != "" { - //tc := twitchchat.New(conf.Twitch, twitchchat.WithFdgt(), twitchchat.WithFaker(3270*time.Millisecond)) + //tc := twitchchat.New(conf.Twitch, twitchchat.WithFdgt(), twitchchat.WithFaker(1*time.Second)) tc := twitchchat.New(conf.Twitch) err := tc.Connect(events, messages) diff --git a/companion/config.go b/companion/config.go index e771596..719182c 100644 --- a/companion/config.go +++ b/companion/config.go @@ -67,17 +67,20 @@ func (c Config) GetEvent(ev StreamEvent) (bool, *SquirtPattern) { continue } - log.Println("found a match: ", e) + //log.Println("Looks good:", c.Events[i], "-", i) if match == nil { match = &c.Events[i] + log.Println("Mark match") } if e.Min > match.Min { - match = &e + match = &c.Events[i] + log.Println("Move match") } } + log.Println("found a match: ", match) if match != nil { if len(match.Pattern) == 0 { return true, &defaultPattern diff --git a/companion/config_test.go b/companion/config_test.go index 55ad23e..11838ea 100644 --- a/companion/config_test.go +++ b/companion/config_test.go @@ -14,6 +14,10 @@ func TestConfig_HasEvent(t *testing.T) { sqTwo := SquirtPattern{2 * time.Second} sqThree := SquirtPattern{3 * time.Second} sqFour := SquirtPattern{4 * time.Second} + sqFive := SquirtPattern{1234 * time.Millisecond} + sqSix := SquirtPattern{2345 * time.Millisecond} + sqSeven := SquirtPattern{3456 * time.Millisecond} + sq8 := SquirtPattern{8 * time.Millisecond} c := Config{ Duration: sqDefault, @@ -45,6 +49,26 @@ func TestConfig_HasEvent(t *testing.T) { Type: EventTypeDono, Min: 200, }, + { + Type: EventTypeT3Sub, + Pattern: sqFive, + }, + { + Type: EventTypeT3Sub, + Pattern: sqSix, + Min: 15, + }, + { + Type: EventTypeT1Sub, + Pattern: sqSeven, + Min: 10, + Max: 10, + }, + { + Type: EventTypeT2Sub, + Pattern: sq8, + Min: 2, + }, }} tests := []struct { @@ -59,15 +83,21 @@ func TestConfig_HasEvent(t *testing.T) { {StreamEvent{EventTypeDono, 25}, true, &sqThree}, {StreamEvent{EventTypeDono, 150}, true, &sqFour}, {StreamEvent{EventTypeDono, 500}, true, &sqDefault}, + {StreamEvent{EventTypeT3Sub, 10}, true, &sqFive}, + {StreamEvent{EventTypeT3Sub, 20}, true, &sqSix}, + {StreamEvent{EventTypeT2Sub, 1}, false, nil}, + {StreamEvent{EventTypeT1Sub, 10}, true, &sqSeven}, + {StreamEvent{EventTypeT1Sub, 11}, false, nil}, } - for i, tt := range tests { - t.Run(fmt.Sprint(i), func(t *testing.T) { + for _, tt := range tests { + t.Run(fmt.Sprintf("%v_%v", tt.ev.EventType, tt.ev.Amount), func(t *testing.T) { got, p := c.GetEvent(tt.ev) if got != tt.want { t.Errorf("HasEvent() = %v, want %v", got, tt.want) } + t.Logf("Event: %v", tt.ev) t.Logf("Want: %v", tt.wantPattern) t.Logf("Got: %v", p) diff --git a/companion/streamevent.go b/companion/streamevent.go index 46902ab..3ecf93d 100644 --- a/companion/streamevent.go +++ b/companion/streamevent.go @@ -5,9 +5,12 @@ import "fmt" type EventType string const ( - EventTypeBits = "bits" - EventTypeDono = "dono" - EventTypeSub = "subs" + EventTypeBits = "bits" + EventTypeDono = "dono" + EventTypeSub = "subs" + EventTypeT1Sub = "tier1" + EventTypeT2Sub = "tier2" + EventTypeT3Sub = "tier3" ) type StreamEvent struct {