Skip to content

Commit

Permalink
fix history expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzz1y committed Aug 9, 2023
1 parent fc00565 commit 8e06db6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/bot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func (b *Bot) historyResetHandler(user *gpt.User, evt *event.Event) (ok bool) {
}

// historyExpireHandler checks if the history for a user has expired and resets if necessary.
func (b *Bot) historyExpireHandler(user *gpt.User) {
func (b *Bot) historyExpireHandler(user *gpt.User) (ok bool) {
if user.LastMsg.Add(time.Duration(b.historyExpire) * time.Hour).Before(time.Now()) {
user.History.ResetHistory()
return true
}
return false
}

// msgEvtDispatcher dispatches incoming messages to their appropriate handlers.
Expand All @@ -67,15 +69,16 @@ func (b *Bot) msgEvtDispatcher(source mautrix.EventSource, evt *event.Event) {
return
}

if b.historyResetHandler(user, evt) {
if b.historyResetHandler(user, evt) || b.historyExpireHandler(user) {
l.Info().Msg("reset history")
return
}

err := b.sendAnswer(user, evt)
if err != nil {
l.Err(err).Msg("failed to send message")
} else {
l.Info().Msg("sending answer")
return
}

l.Info().Msg("sending answer")
}

0 comments on commit 8e06db6

Please sign in to comment.