fixes for web endpoint

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2025-01-13 17:07:37 -08:00
parent fed49ba3cb
commit 6480f27946
4 changed files with 12 additions and 8 deletions

View file

@ -2,12 +2,13 @@ package activity
import (
"errors"
"fmt"
"sync"
"time"
"gitlab.com/whom/bingobot/internal/config"
"gitlab.com/whom/bingobot/internal/state"
"gitlab.com/whom/bingobot/internal/logging"
"gitlab.com/whom/bingobot/internal/state"
)
/* Activity module
@ -18,7 +19,7 @@ const (
ActivityModuleStartFail = "failed to start activity module"
)
var currentUserActivity map[string][]state.UserActiveEvent
var currentUserActivity = make(map[string][]state.UserActiveEvent)
var userActivityLock sync.RWMutex
func Start() error {
@ -38,6 +39,10 @@ func Start() error {
user := emap[state.UserEventUserKey]
etime := ev.Time()
delta := time.Since(etime).Hours() / float64(24)
logging.Debug(fmt.Sprintf(
"processing UserActive event for %s", user,
))
if delta <= float64(config.Get().UserEventLifespanDays) {
new := []state.UserActiveEvent{ev.(state.UserActiveEvent)}
@ -46,6 +51,7 @@ func Start() error {
if found {
new = append(new, current...)
}
currentUserActivity[user] = new
userActivityLock.Unlock()
} else {
logging.Warn("recieved expired useractive event")

View file

@ -37,7 +37,7 @@ func Start() error {
go func() {
for {
ev := <- ch
logging.Info("recieved new confessional channel link")
logging.Debug("recieved new confessional channel link")
e := ev.(state.ConfessionsChannelLinkEvent)
linkLock.Lock()
confessionChannelLinks[e.GuildID] = e

View file

@ -42,7 +42,7 @@ func NewActivityTimer(uid string) *UserActivityTimer {
Start() initializes the timer and calls run()
*/
func (t *UserActivityTimer) Start(ctx context.Context) {
logging.Info("starting voiceActivityTimer", "uid", t.UID)
logging.Debug("starting voiceActivityTimer", "uid", t.UID)
t.sleepDuration = time.Millisecond * time.Duration(config.Get().VoiceActivityTimerSleepIntervalMillis)
activityTimerDuration := time.Second * time.Duration(config.Get().VoiceActivityThresholdSeconds)
@ -89,7 +89,7 @@ func (t *UserActivityTimer) run() {
}
// the timer's context has been cancelled or deadline expired.
logging.Info("voiceActivityTimer stopping", "uid", t.UID, "reason", context.Cause(t.ctx))
logging.Debug("voiceActivityTimer stopping", "uid", t.UID, "reason", context.Cause(t.ctx))
if context.Cause(t.ctx) == ErrTimerExpired {
/*
@ -147,5 +147,5 @@ func emitUserActiveEvent(uid string) {
return
}
logging.Info("published UserActiveEvent", "uid", uid)
logging.Debug("published UserActiveEvent", "uid", uid)
}