handle rooms dynamically
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0d5a3ff5b9
commit
fc274e665a
22
simp.go
22
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user