diff --git a/app/app.go b/app/app.go index 4ac98f7..a5cd1d7 100644 --- a/app/app.go +++ b/app/app.go @@ -21,6 +21,7 @@ var DataBuckets = []string{ "TwitchStreamBucket", // Local publishers -> twitch stream names "TwitchLiveBucket", // Local publishers -> twitch live stream status "TwitchNotificationBucket", // Local publishers -> twitch notification state + "StreamInfoBucket", // Local publishers -> generic stream information } func init() { diff --git a/controllers/publish.go b/controllers/publish.go index 836e4d2..7d0e679 100644 --- a/controllers/publish.go +++ b/controllers/publish.go @@ -17,6 +17,7 @@ type Publisher struct { TwitchStream string `json:"twitch_stream"` TwitchLive string `json:"twitch_live"` TwitchNotification string `json:"-"` + StreamInfo string `json:"-"` } // IsValid perform basic validations on a publisher record @@ -64,6 +65,12 @@ func (c *Controller) FetchPublisher(p *Publisher) error { if err != nil { return err } + p.TwitchNotification = string(b) + b, err = c.getBucketValue("SteamInfoBucket", p.Name) + if err != nil { + return err + } + p.StreamInfo = string(b) return nil } diff --git a/controllers/twitch.go b/controllers/twitch.go index bb5e008..ac80ca7 100644 --- a/controllers/twitch.go +++ b/controllers/twitch.go @@ -307,7 +307,7 @@ func (c *Controller) updateLiveStatus(streams []StreamData) error { return err } - // mark previous live streams -> offline + // mark previous live streams -> offline and notify of stream info change for i := range publishers { live = false p := &publishers[i] @@ -316,10 +316,23 @@ func (c *Controller) updateLiveStatus(streams []StreamData) error { s := streams[x] if strings.ToLower(s.UserName) == strings.ToLower(p.TwitchStream) { live = true + // retieve stream info + g, err := c.getGame(s.GameID) + if err != nil { + return err + } + streamInfo := fmt.Sprintf("title: %s\ngame: %s", s.Title, g.Name) + if p.StreamInfo != "" && p.StreamInfo != streamInfo { + // streamer changed their stream info, set notification + notification := fmt.Sprintf("%s switched it up!\n%s", p.Name, p.StreamInfo) + c.setBucketValue("TwitchNotificationBucket", p.Name, notification) + } + p.StreamInfo = streamInfo } } if !live { c.setBucketValue("TwitchLiveBucket", p.Name, "") + c.setBucketValue("StreamInfoBucket", p.Name, "") notification := fmt.Sprintf(":checkered_flag: %s finished streaming on twitch", p.Name) c.setBucketValue("TwitchNotificationBucket", p.Name, notification) } @@ -338,12 +351,8 @@ func (c *Controller) updateLiveStatus(streams []StreamData) error { if !p.IsTwitchLive() { c.setBucketValue("TwitchLiveBucket", p.Name, s.Type) streamLink := fmt.Sprintf("https://twitch.tv/%s", p.TwitchStream) - g, err := c.getGame(s.GameID) - if err != nil { - return err - } - notification := fmt.Sprintf(":movie_camera: %s started a public stream on twitch!"+ - "\ntitle: %s\ngame: %s\nwatch now: `%s`", p.Name, s.Title, g.Name, streamLink) + notification := fmt.Sprintf(":movie_camera: %s started streaming on twitch!"+ + "\n%s\nwatch now: `%s`", p.Name, p.StreamInfo, streamLink) c.setBucketValue("TwitchNotificationBucket", p.Name, notification) } }