From e4489733ccc7ed8d2feeed344e4cf1eb5bad8b68 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sat, 24 Nov 2018 10:01:25 +0100 Subject: [PATCH] bot: Fixed channel handler giving negative minute count if started after log is long dead. --- internal/bot/channel.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/bot/channel.go b/internal/bot/channel.go index 9297aff..d872076 100644 --- a/internal/bot/channel.go +++ b/internal/bot/channel.go @@ -50,7 +50,11 @@ func (channel *Channel) loop() { session, err := logs.FindOpen(channel.parentCtx, channel.name) if err == nil { minsUntilDeadline := 1 + int(((time.Hour * 2) - time.Since(session.LatestTime())).Minutes()) - channel.client.Sayf(channel.name, "Session https://aiterp.net/logs/%s will be closed in %d minutes if there are no new posts.", session.ID, minsUntilDeadline) + if minsUntilDeadline < 1 { + minsUntilDeadline = 1 + } + + channel.client.Sayf(channel.name, "Session https://aiterp.net/logs/%s will be closed in %d min if there are no new posts.", session.ID, minsUntilDeadline) channel.lastPostSessionID = session.ID channel.lastPostTime = session.LatestTime() @@ -215,7 +219,7 @@ func (channel *Channel) loop() { break } - channel.client.Sayf(channel.name, "Log session closed due to 2 hours of inactivity. See log at https://aiterp.net/logs/%s", channel.lastPostSessionID) + channel.client.Sayf(channel.name, "Log session closed after 2+ hours of inactivity. See log at https://aiterp.net/logs/%s", channel.lastPostSessionID) channel.lastPostTime = time.Time{} channel.lastPostSessionID = ""