From 906ec4bfc38b3b38de63316794ba692db04e31fc Mon Sep 17 00:00:00 2001 From: Antoine COMBET Date: Thu, 3 Mar 2022 23:11:15 +0100 Subject: [PATCH] Fixed all reminds of previous session being resent at startup --- app/Main.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index e09b9a0..dea427c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -38,6 +38,7 @@ import Commands.EDT (getEdt) import qualified Control.Concurrent import qualified Control.Event as E import UnliftIO.Directory (doesFileExist, removeFile) +import Data.Time (getCurrentTime) main :: IO () main = do @@ -75,9 +76,11 @@ onDiscordStart conf eventSystem = do remindfile <- liftIO $ readFile "reminds.data" let reminddata :: [Remind] reminddata = map read $ lines remindfile + now <- liftIO getCurrentTime mapM_ (\r -> do withRunInIO $ \runInIO -> - E.addEvent eventSystem (rmdWhen r) + if now > rmdWhen r then + void $ E.addEvent eventSystem (rmdWhen r) ( do runInIO ( restCall $ R.CreateMessage (rmdWhere r) @@ -88,7 +91,9 @@ onDiscordStart conf eventSystem = do ) return () ) - ) reminddata + else + pure () + ) reminddata liftIO $ removeFile "reminds.data"