add stat tracking
This commit is contained in:
parent
5697c5ecd8
commit
9b64ca67cd
25
main.go
25
main.go
@ -22,6 +22,9 @@ var DimensionServer string
|
|||||||
var HomeserverDomain string
|
var HomeserverDomain string
|
||||||
var GitCommit string
|
var GitCommit string
|
||||||
var Statefile string
|
var Statefile string
|
||||||
|
var CurrStreamCnt int
|
||||||
|
var MostStreamCnt int
|
||||||
|
var StartTime time.Time
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
@ -40,6 +43,9 @@ func main() {
|
|||||||
DimensionServer = viper.GetString("dimension")
|
DimensionServer = viper.GetString("dimension")
|
||||||
HomeserverDomain = viper.GetString("domain")
|
HomeserverDomain = viper.GetString("domain")
|
||||||
Statefile = viper.GetString("statefile")
|
Statefile = viper.GetString("statefile")
|
||||||
|
CurrStreamCnt = 0
|
||||||
|
MostStreamCnt = 0
|
||||||
|
StartTime = time.Now()
|
||||||
var vtubers []*Vtuber
|
var vtubers []*Vtuber
|
||||||
log.Println("Logging into", Homeserver, "as", Username)
|
log.Println("Logging into", Homeserver, "as", Username)
|
||||||
client, err := mautrix.NewClient(Homeserver, "", "")
|
client, err := mautrix.NewClient(Homeserver, "", "")
|
||||||
@ -85,12 +91,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
infomsg = fmt.Sprintf("Currently Simping For: \n%v", strings.Join(vlist, "\n"))
|
infomsg = fmt.Sprintf("Currently Simping For: \n%v", strings.Join(vlist, "\n"))
|
||||||
client.SendText(evt.RoomID, infomsg)
|
client.SendText(evt.RoomID, infomsg)
|
||||||
|
case "stats":
|
||||||
|
var statmsg string
|
||||||
|
vlist := []string{}
|
||||||
|
t := 0
|
||||||
|
for _, vt := range vtubers {
|
||||||
|
vlist = append(vlist, fmt.Sprintf("%v Total:%v", vt.Name, vt.TotalStreams))
|
||||||
|
t = t + vt.TotalStreams
|
||||||
|
}
|
||||||
|
statmsg = fmt.Sprintf("Current Stats Since %v:\n%v\nTotal Streams: %v\nMost Concurrent: %v/%v\n", StartTime, strings.Join(vlist, "\n"), t, MostStreamCnt, len(vtubers))
|
||||||
|
client.SendText(evt.RoomID, statmsg)
|
||||||
case "version":
|
case "version":
|
||||||
// print version
|
// print version
|
||||||
client.SendText(evt.RoomID, "SimpBot version "+GitCommit)
|
client.SendText(evt.RoomID, "SimpBot version "+GitCommit)
|
||||||
case "reload":
|
case "reload":
|
||||||
//reload config
|
//reload config
|
||||||
client.SendText(evt.RoomID, "unimplemented")
|
client.SendText(evt.RoomID, "Reloading config")
|
||||||
|
fmt.Println("Reload requested,reloading vtubers")
|
||||||
|
vtubers = LoadVtubers()
|
||||||
case "help":
|
case "help":
|
||||||
client.SendText(evt.RoomID, "Supported commands: info,version")
|
client.SendText(evt.RoomID, "Supported commands: info,version")
|
||||||
default:
|
default:
|
||||||
@ -133,6 +151,10 @@ func main() {
|
|||||||
for _, v := range vtubers {
|
for _, v := range vtubers {
|
||||||
v.Update()
|
v.Update()
|
||||||
if v.IsLive() {
|
if v.IsLive() {
|
||||||
|
CurrStreamCnt = CurrStreamCnt + 1
|
||||||
|
if CurrStreamCnt > MostStreamCnt {
|
||||||
|
MostStreamCnt = CurrStreamCnt
|
||||||
|
}
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
//check to see if already embeded
|
//check to see if already embeded
|
||||||
var content YoutubeWidget
|
var content YoutubeWidget
|
||||||
@ -155,6 +177,7 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
//Not live, check to see if there's any embeds and remove them
|
//Not live, check to see if there's any embeds and remove them
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
|
CurrStreamCnt = CurrStreamCnt - 1
|
||||||
var content YoutubeWidget
|
var content YoutubeWidget
|
||||||
err = client.StateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, &content)
|
err = client.StateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, &content)
|
||||||
if err == nil && content.ID != "" {
|
if err == nil && content.ID != "" {
|
||||||
|
@ -24,6 +24,7 @@ type Vtuber struct {
|
|||||||
CurrentStreamTitle string
|
CurrentStreamTitle string
|
||||||
LiveMsg string
|
LiveMsg string
|
||||||
AnnounceLive bool
|
AnnounceLive bool
|
||||||
|
TotalStreams int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber {
|
func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber {
|
||||||
@ -34,6 +35,7 @@ func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber {
|
|||||||
CurrentStreamTitle: "",
|
CurrentStreamTitle: "",
|
||||||
LiveMsg: liveMsg,
|
LiveMsg: liveMsg,
|
||||||
AnnounceLive: announce,
|
AnnounceLive: announce,
|
||||||
|
TotalStreams: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +80,7 @@ func (v *Vtuber) Update() error {
|
|||||||
if s.Status == "live" {
|
if s.Status == "live" {
|
||||||
v.CurrentStream = s.ID
|
v.CurrentStream = s.ID
|
||||||
v.CurrentStreamTitle = s.Title
|
v.CurrentStreamTitle = s.Title
|
||||||
|
v.TotalStreams = v.TotalStreams + 1
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user