From fc274e665ae54cec4c99a0a60347284258d8ef65 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 15 May 2023 19:21:02 -0400 Subject: [PATCH] handle rooms dynamically --- simp.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/simp.go b/simp.go index d206859..49254d7 100644 --- a/simp.go +++ b/simp.go @@ -22,6 +22,7 @@ type simp struct { maxStream int vtubers []*Vtuber stop chan bool + rooms []id.RoomID } func newSimp() *simp { @@ -32,26 +33,25 @@ func newSimp() *simp { } func (s *simp) Run() { - ticker := time.NewTicker(time.Second * 30) + ticker := time.NewTicker(time.Second * 45) + roomResp, err := s.client.JoinedRooms() + if err != nil { + log.Errorf("error getting joined rooms: %v", err) + return + } + s.rooms = roomResp.JoinedRooms for { select { case <-s.stop: return case <-ticker.C: - - roomResp, err := s.client.JoinedRooms() - if err != nil { - log.Errorf("error getting joined rooms: %v, skipping iteration", err) - continue - } - rooms := roomResp.JoinedRooms // We're going to assume they're only stream one video at a time for _, v := range s.vtubers { err = v.Update(s.holodexToken) if err != nil { log.Error("error pinging holodex", "error", err) } - for _, room := range rooms { + for _, room := range s.rooms { if v.IsLive() { // check to see if already embeded var content YoutubeWidget @@ -61,10 +61,11 @@ func (s *simp) Run() { "dimension-m.video-simp-"+v.Name, &content, ) + update := true if err != nil { log.Errorf("error getting state event in room %v: %v", room, err) } - if content.ID == "" { + if update { if v.AnnounceLive { s.client.SendText(room, v.LiveMsg) } else { @@ -256,6 +257,7 @@ func (s *simp) SetupMatrix(uname, pass, token, hs, domain, dserver string) error log.Errorf("error joining room %v", evt.RoomID) } else { log.Infof("joined room %v", evt.RoomID) + s.rooms = append(s.rooms, evt.RoomID) } } })