fixes for web endpoint
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
fed49ba3cb
commit
6480f27946
4 changed files with 12 additions and 8 deletions
|
|
@ -2,12 +2,13 @@ package activity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/whom/bingobot/internal/config"
|
"gitlab.com/whom/bingobot/internal/config"
|
||||||
"gitlab.com/whom/bingobot/internal/state"
|
|
||||||
"gitlab.com/whom/bingobot/internal/logging"
|
"gitlab.com/whom/bingobot/internal/logging"
|
||||||
|
"gitlab.com/whom/bingobot/internal/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Activity module
|
/* Activity module
|
||||||
|
|
@ -18,7 +19,7 @@ const (
|
||||||
ActivityModuleStartFail = "failed to start activity module"
|
ActivityModuleStartFail = "failed to start activity module"
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentUserActivity map[string][]state.UserActiveEvent
|
var currentUserActivity = make(map[string][]state.UserActiveEvent)
|
||||||
var userActivityLock sync.RWMutex
|
var userActivityLock sync.RWMutex
|
||||||
|
|
||||||
func Start() error {
|
func Start() error {
|
||||||
|
|
@ -38,6 +39,10 @@ func Start() error {
|
||||||
user := emap[state.UserEventUserKey]
|
user := emap[state.UserEventUserKey]
|
||||||
etime := ev.Time()
|
etime := ev.Time()
|
||||||
delta := time.Since(etime).Hours() / float64(24)
|
delta := time.Since(etime).Hours() / float64(24)
|
||||||
|
logging.Debug(fmt.Sprintf(
|
||||||
|
"processing UserActive event for %s", user,
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
if delta <= float64(config.Get().UserEventLifespanDays) {
|
if delta <= float64(config.Get().UserEventLifespanDays) {
|
||||||
new := []state.UserActiveEvent{ev.(state.UserActiveEvent)}
|
new := []state.UserActiveEvent{ev.(state.UserActiveEvent)}
|
||||||
|
|
@ -46,6 +51,7 @@ func Start() error {
|
||||||
if found {
|
if found {
|
||||||
new = append(new, current...)
|
new = append(new, current...)
|
||||||
}
|
}
|
||||||
|
currentUserActivity[user] = new
|
||||||
userActivityLock.Unlock()
|
userActivityLock.Unlock()
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("recieved expired useractive event")
|
logging.Warn("recieved expired useractive event")
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func Start() error {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
ev := <- ch
|
ev := <- ch
|
||||||
logging.Info("recieved new confessional channel link")
|
logging.Debug("recieved new confessional channel link")
|
||||||
e := ev.(state.ConfessionsChannelLinkEvent)
|
e := ev.(state.ConfessionsChannelLinkEvent)
|
||||||
linkLock.Lock()
|
linkLock.Lock()
|
||||||
confessionChannelLinks[e.GuildID] = e
|
confessionChannelLinks[e.GuildID] = e
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func NewActivityTimer(uid string) *UserActivityTimer {
|
||||||
Start() initializes the timer and calls run()
|
Start() initializes the timer and calls run()
|
||||||
*/
|
*/
|
||||||
func (t *UserActivityTimer) Start(ctx context.Context) {
|
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)
|
t.sleepDuration = time.Millisecond * time.Duration(config.Get().VoiceActivityTimerSleepIntervalMillis)
|
||||||
activityTimerDuration := time.Second * time.Duration(config.Get().VoiceActivityThresholdSeconds)
|
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.
|
// 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 {
|
if context.Cause(t.ctx) == ErrTimerExpired {
|
||||||
/*
|
/*
|
||||||
|
|
@ -147,5 +147,5 @@ func emitUserActiveEvent(uid string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.Info("published UserActiveEvent", "uid", uid)
|
logging.Debug("published UserActiveEvent", "uid", uid)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -41,13 +41,11 @@ func main() {
|
||||||
|
|
||||||
logging.Info("startup: starting activity module")
|
logging.Info("startup: starting activity module")
|
||||||
if err := activity.Start(); err != nil {
|
if err := activity.Start(); err != nil {
|
||||||
// TODO: handle gracefully and continue?
|
|
||||||
log.Fatalf("failed to start activity module: %s", err.Error())
|
log.Fatalf("failed to start activity module: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.Info("startup: starting confession module")
|
logging.Info("startup: starting confession module")
|
||||||
if err := confession.Start(); err != nil {
|
if err := confession.Start(); err != nil {
|
||||||
// TODO: handle gracefully and continue?
|
|
||||||
log.Fatalf("failed to start confession module: %s", err.Error())
|
log.Fatalf("failed to start confession module: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue