bit of clean up
This commit is contained in:
parent
9b64ca67cd
commit
67fe7dea38
29
main.go
29
main.go
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -163,7 +164,11 @@ func main() {
|
|||||||
if v.AnnounceLive {
|
if v.AnnounceLive {
|
||||||
client.SendText(room, v.LiveMsg)
|
client.SendText(room, v.LiveMsg)
|
||||||
} else {
|
} 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))
|
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)))
|
||||||
@ -171,7 +176,7 @@ func main() {
|
|||||||
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user