From 9b64ca67cdf7d338225509928d5690c9f95c91e7 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 26 Oct 2021 14:01:58 -0400 Subject: [PATCH] add stat tracking --- main.go | 25 ++++++++++++++++++++++++- vtuber.go | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 18b8ef7..c07415e 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,9 @@ var DimensionServer string var HomeserverDomain string var GitCommit string var Statefile string +var CurrStreamCnt int +var MostStreamCnt int +var StartTime time.Time func main() { viper.SetConfigName("config") @@ -40,6 +43,9 @@ func main() { DimensionServer = viper.GetString("dimension") HomeserverDomain = viper.GetString("domain") Statefile = viper.GetString("statefile") + CurrStreamCnt = 0 + MostStreamCnt = 0 + StartTime = time.Now() var vtubers []*Vtuber log.Println("Logging into", Homeserver, "as", Username) client, err := mautrix.NewClient(Homeserver, "", "") @@ -85,12 +91,24 @@ func main() { } infomsg = fmt.Sprintf("Currently Simping For: \n%v", strings.Join(vlist, "\n")) 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": // print version client.SendText(evt.RoomID, "SimpBot version "+GitCommit) case "reload": //reload config - client.SendText(evt.RoomID, "unimplemented") + client.SendText(evt.RoomID, "Reloading config") + fmt.Println("Reload requested,reloading vtubers") + vtubers = LoadVtubers() case "help": client.SendText(evt.RoomID, "Supported commands: info,version") default: @@ -133,6 +151,10 @@ func main() { for _, v := range vtubers { v.Update() if v.IsLive() { + CurrStreamCnt = CurrStreamCnt + 1 + if CurrStreamCnt > MostStreamCnt { + MostStreamCnt = CurrStreamCnt + } for _, room := range rooms { //check to see if already embeded var content YoutubeWidget @@ -155,6 +177,7 @@ func main() { } else { //Not live, check to see if there's any embeds and remove them for _, room := range rooms { + CurrStreamCnt = CurrStreamCnt - 1 var content YoutubeWidget err = client.StateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, &content) if err == nil && content.ID != "" { diff --git a/vtuber.go b/vtuber.go index 2227393..7160952 100644 --- a/vtuber.go +++ b/vtuber.go @@ -24,6 +24,7 @@ type Vtuber struct { CurrentStreamTitle string LiveMsg string AnnounceLive bool + TotalStreams int } func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber { @@ -34,6 +35,7 @@ func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber { CurrentStreamTitle: "", LiveMsg: liveMsg, AnnounceLive: announce, + TotalStreams: 0, } } @@ -78,6 +80,7 @@ func (v *Vtuber) Update() error { if s.Status == "live" { v.CurrentStream = s.ID v.CurrentStreamTitle = s.Title + v.TotalStreams = v.TotalStreams + 1 found = true } }