bit of clean up
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
stryan 2021-10-26 14:14:26 -04:00
parent 9b64ca67cd
commit 67fe7dea38

27
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net/url"
"os" "os"
"os/signal" "os/signal"
"strings" "strings"
@ -110,7 +111,7 @@ func main() {
fmt.Println("Reload requested,reloading vtubers") fmt.Println("Reload requested,reloading vtubers")
vtubers = LoadVtubers() vtubers = LoadVtubers()
case "help": case "help":
client.SendText(evt.RoomID, "Supported commands: info,version") client.SendText(evt.RoomID, "Supported commands: info,version,stats")
default: default:
//command not found //command not found
client.SendText(evt.RoomID, "command not recognized") client.SendText(evt.RoomID, "command not recognized")
@ -123,7 +124,7 @@ func main() {
if err != nil { if err != nil {
fmt.Printf("error joining room %v", evt.RoomID) fmt.Printf("error joining room %v", evt.RoomID)
} else { } else {
fmt.Println("joined room") fmt.Printf("joined room %v", evt.RoomID)
} }
} }
}) })
@ -162,16 +163,20 @@ func main() {
if content.ID == "" { if content.ID == "" {
if v.AnnounceLive { if v.AnnounceLive {
client.SendText(room, v.LiveMsg) client.SendText(room, v.LiveMsg)
} else {
if isValidUrl(v.LiveMsg) {
client.SendNotice(room, fmt.Sprintf("%v has gone live", v.Name))
} else { } else {
client.SendNotice(room, v.LiveMsg) client.SendNotice(room, v.LiveMsg)
} }
}
client.SendNotice(room, fmt.Sprintf("%v's Title: %v", v.Name, v.CurrentStreamTitle)) client.SendNotice(room, fmt.Sprintf("%v's Title: %v", v.Name, v.CurrentStreamTitle))
resp, err := client.SendStateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, NewYT(v.Name+"'s stream", v.CurrentStream, string(room))) resp, err := client.SendStateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, NewYT(v.Name+"'s stream", v.CurrentStream, string(room)))
if err != nil { if err != nil {
log.Println("error embeding video") log.Println("error embeding video")
log.Println(err) log.Println(err)
} }
log.Printf("Embed event %v", resp) log.Printf("Embed stream %v for %v ", resp, v.Name)
} }
} }
} else { } else {
@ -187,7 +192,7 @@ func main() {
log.Println("error removed video embed") log.Println("error removed video embed")
log.Println(err) log.Println(err)
} }
log.Printf("Embed removed %v", resp) log.Printf("Embed stream %v removed %v", resp, v.Name)
} }
} }
} }
@ -200,3 +205,17 @@ func main() {
panic(err) panic(err)
} }
} }
func isValidUrl(toTest string) bool {
_, err := url.ParseRequestURI(toTest)
if err != nil {
return false
}
u, err := url.Parse(toTest)
if err != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}