summaryrefslogtreecommitdiff
path: root/Hsbot/Core.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-06-10 23:30:09 +0200
committerJulien Dessaux2010-06-20 17:49:39 +0200
commitd97177ce3b392f80e36a93ca41ca1426b0220733 (patch)
treecfa8c4336cfebcad33236e9f0e88dacf832b5722 /Hsbot/Core.hs
parentFixed the plugin termination. (diff)
downloadhsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.tar.gz
hsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.tar.bz2
hsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.zip
Wrote most of the resume code for the core and the irc plugin.
Diffstat (limited to '')
-rw-r--r--Hsbot/Core.hs29
1 files changed, 18 insertions, 11 deletions
diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs
index b6c4d9c..dad965d 100644
--- a/Hsbot/Core.hs
+++ b/Hsbot/Core.hs
@@ -18,12 +18,23 @@ import Hsbot.Plugin
import Hsbot.Types
-- | Bot's main entry point
-hsbot :: [BotConfig] -> IO ()
-hsbot config = do
- startTime <- getCurrentTime
+hsbot :: [BotConfig] -> Maybe String -> IO ()
+hsbot config txtResumeData= do
+ let resumeData = case txtResumeData of
+ Just txtData -> read txtData :: BotResumeData -- TODO : catch exception
+ Nothing -> M.empty :: BotResumeData
+ startTime <- case M.lookup "HSBOT" resumeData of
+ Just hsbotData -> do
+ case M.lookup "STARTTIME" hsbotData of
+ Just txtStartTime -> do
+ let gotStartTime = read txtStartTime :: UTCTime
+ return gotStartTime
+ Nothing -> getCurrentTime
+ Nothing -> getCurrentTime
+ let resumeData' = M.insert "HSBOT" (M.singleton "STARTTIME" $ show startTime) resumeData
putStrLn "[Hsbot] Opening communication channel... "
chan <- newChan :: IO (Chan BotMsg)
- mvar <- newMVar M.empty :: IO (MVar BotResumeData)
+ mvar <- newMVar resumeData' :: IO (MVar BotResumeData)
putStrLn "[Hsbot] Installing signal handlers... "
_ <- installHandler sigHUP (Catch $ sigHupHandler chan) Nothing
_ <- installHandler sigTERM (Catch $ sigTermHandler chan) Nothing
@@ -36,10 +47,10 @@ hsbot config = do
putStrLn "[Hsbot] Entering main loop... "
(status, botState') <- runLoop botState
putStrLn "[Hsbot] Killing active plugins... "
- resumeData <- takeMVar mvar
- evalStateT (mapM_ killPlugin $ M.keys resumeData) botState'
+ newResumeData <- takeMVar mvar
+ evalStateT (mapM_ killPlugin $ M.keys newResumeData) botState'
if status == BotReboot
- then resumeHsbot resumeData
+ then hsbot config (Just $ show newResumeData) -- TODO : exec on the hsbot launcher with the reload string
else return ()
where
runLoop :: BotState -> IO (BotStatus, BotState)
@@ -50,10 +61,6 @@ hsbot config = do
BotContinue -> runLoop botState'
_ -> return (status, botState')
-resumeHsbot :: BotResumeData -> IO ()
-resumeHsbot resumeData = do
- print resumeData
-
-- | Run the bot main loop
botCore :: Bot (BotStatus)
botCore = do