Rewrite and refactor #1

Merged
stryan merged 6 commits from rewrite into master 2023-05-16 18:36:19 -04:00
Showing only changes of commit fc274e665a - Show all commits

22
simp.go
View File

@ -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)
}
}
})