Browse Source

Fixed all reminds of previous session being resent at startup

master
Antoine COMBET 3 years ago
parent
commit
906ec4bfc3
  1. 9
      app/Main.hs

9
app/Main.hs

@ -38,6 +38,7 @@ import Commands.EDT (getEdt)
import qualified Control.Concurrent import qualified Control.Concurrent
import qualified Control.Event as E import qualified Control.Event as E
import UnliftIO.Directory (doesFileExist, removeFile) import UnliftIO.Directory (doesFileExist, removeFile)
import Data.Time (getCurrentTime)
main :: IO () main :: IO ()
main = do main = do
@ -75,9 +76,11 @@ onDiscordStart conf eventSystem = do
remindfile <- liftIO $ readFile "reminds.data" remindfile <- liftIO $ readFile "reminds.data"
let reminddata :: [Remind] let reminddata :: [Remind]
reminddata = map read $ lines remindfile reminddata = map read $ lines remindfile
now <- liftIO getCurrentTime
mapM_ (\r -> do mapM_ (\r -> do
withRunInIO $ \runInIO -> withRunInIO $ \runInIO ->
E.addEvent eventSystem (rmdWhen r)
if now > rmdWhen r then
void $ E.addEvent eventSystem (rmdWhen r)
( do ( do
runInIO ( restCall runInIO ( restCall
$ R.CreateMessage (rmdWhere r) $ R.CreateMessage (rmdWhere r)
@ -88,7 +91,9 @@ onDiscordStart conf eventSystem = do
) )
return () return ()
) )
) reminddata
else
pure ()
) reminddata
liftIO $ removeFile "reminds.data" liftIO $ removeFile "reminds.data"

Loading…
Cancel
Save