add api key
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
stryan 2023-04-24 18:01:40 -04:00
parent 2c10ea6f33
commit 4938f28ace
2 changed files with 11 additions and 2 deletions

10
main.go
View File

@ -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 {

View File

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