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
|
maxStream int
|
||||||
vtubers []*Vtuber
|
vtubers []*Vtuber
|
||||||
stop chan bool
|
stop chan bool
|
||||||
|
rooms []id.RoomID
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSimp() *simp {
|
func newSimp() *simp {
|
||||||
@ -32,26 +33,25 @@ func newSimp() *simp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *simp) Run() {
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.stop:
|
case <-s.stop:
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
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
|
// We're going to assume they're only stream one video at a time
|
||||||
for _, v := range s.vtubers {
|
for _, v := range s.vtubers {
|
||||||
err = v.Update(s.holodexToken)
|
err = v.Update(s.holodexToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error pinging holodex", "error", err)
|
log.Error("error pinging holodex", "error", err)
|
||||||
}
|
}
|
||||||
for _, room := range rooms {
|
for _, room := range s.rooms {
|
||||||
if v.IsLive() {
|
if v.IsLive() {
|
||||||
// check to see if already embeded
|
// check to see if already embeded
|
||||||
var content YoutubeWidget
|
var content YoutubeWidget
|
||||||
@ -61,10 +61,11 @@ func (s *simp) Run() {
|
|||||||
"dimension-m.video-simp-"+v.Name,
|
"dimension-m.video-simp-"+v.Name,
|
||||||
&content,
|
&content,
|
||||||
)
|
)
|
||||||
|
update := true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error getting state event in room %v: %v", room, err)
|
log.Errorf("error getting state event in room %v: %v", room, err)
|
||||||
}
|
}
|
||||||
if content.ID == "" {
|
if update {
|
||||||
if v.AnnounceLive {
|
if v.AnnounceLive {
|
||||||
s.client.SendText(room, v.LiveMsg)
|
s.client.SendText(room, v.LiveMsg)
|
||||||
} else {
|
} 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)
|
log.Errorf("error joining room %v", evt.RoomID)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("joined room %v", evt.RoomID)
|
log.Infof("joined room %v", evt.RoomID)
|
||||||
|
s.rooms = append(s.rooms, evt.RoomID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user