From 4938f28acecef52b6c15483c1629b57fda1152f8 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 24 Apr 2023 18:01:40 -0400 Subject: [PATCH] add api key --- main.go | 10 +++++++++- vtuber.go | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d69e4d8..ef32890 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var Statefile string var CurrStreamCnt int var MostStreamCnt int var StartTime time.Time +var HolodexToken string func main() { viper.SetConfigName("config") @@ -45,6 +46,7 @@ func main() { Username = viper.GetString("username") Password = viper.GetString("password") Token = viper.GetString("access_token") + HolodexToken = viper.GetString("api_token") DimensionServer = viper.GetString("dimension") HomeserverDomain = viper.GetString("domain") Statefile = viper.GetString("statefile") @@ -103,6 +105,9 @@ func main() { } else { log.Println("skipping login since token provided") } + if HolodexToken == "" { + log.Println("No holodex API token provided, unlikely to be able to get streams") + } syncer := client.Syncer.(*mautrix.DefaultSyncer) syncer.OnEventType(event.EventMessage, func(source mautrix.EventSource, evt *event.Event) { if evt.Sender == client.UserID { @@ -211,7 +216,10 @@ func main() { rooms := roomResp.JoinedRooms // We're going to assume they're only stream one video at a time for _, v := range vtubers { - v.Update() + err = v.Update(HolodexToken) + if err != nil { + log.Println(err) + } if v.IsLive() { for _, room := range rooms { diff --git a/vtuber.go b/vtuber.go index 9014565..7d8fdd2 100644 --- a/vtuber.go +++ b/vtuber.go @@ -60,9 +60,10 @@ func (v *Vtuber) IsLive() bool { return v.CurrentStream != "" } -func (v *Vtuber) Update() error { +func (v *Vtuber) Update(api_key string) error { url := fmt.Sprintf("https://holodex.net/api/v2/live?channel_id=%s&lang=all&sort=available_at&order=desc&limit=25&offset=0&paginated=%%3Cempty%%3E", v.ChannelID) req, err := http.NewRequest("GET", url, nil) + req.Header.Set("X-APIKEY", api_key) if err != nil { return err }