diff --git a/main.go b/main.go index c07415e..83b6aa1 100644 --- a/main.go +++ b/main.go @@ -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) } } }) @@ -163,7 +164,11 @@ func main() { if v.AnnounceLive { client.SendText(room, v.LiveMsg) } else { - client.SendNotice(room, v.LiveMsg) + 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))) @@ -171,7 +176,7 @@ func main() { 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 +}