add stat tracking

This commit is contained in:
stryan 2021-10-26 14:01:58 -04:00
parent 5697c5ecd8
commit 9b64ca67cd
2 changed files with 27 additions and 1 deletions

25
main.go
View File

@ -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 != "" {

View File

@ -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
}
}