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 (
"fmt"
"log"
"net/url"
"os"
"os/signal"
"strings"
@ -110,7 +111,7 @@ func main() {
fmt.Println("Reload requested,reloading vtubers")
vtubers = LoadVtubers()
case "help":
client.SendText(evt.RoomID, "Supported commands: info,version")
client.SendText(evt.RoomID, "Supported commands: info,version,stats")
default:
//command not found
client.SendText(evt.RoomID, "command not recognized")
@ -123,7 +124,7 @@ func main() {
if err != nil {
fmt.Printf("error joining room %v", evt.RoomID)
} else {
fmt.Println("joined room")
fmt.Printf("joined room %v", evt.RoomID)
}
}
})
@ -162,16 +163,20 @@ func main() {
if content.ID == "" {
if v.AnnounceLive {
client.SendText(room, v.LiveMsg)
} else {
if isValidUrl(v.LiveMsg) {
client.SendNotice(room, fmt.Sprintf("%v has gone live", v.Name))
} else {
client.SendNotice(room, v.LiveMsg)
}
}
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)))
if err != nil {
log.Println("error embeding video")
log.Println(err)
}
log.Printf("Embed event %v", resp)
log.Printf("Embed stream %v for %v ", resp, v.Name)
}
}
} else {
@ -187,7 +192,7 @@ func main() {
log.Println("error removed video embed")
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)
}
}
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
}