diff options
author | Julien Dessaux | 2011-09-10 00:10:00 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-09-10 00:10:00 +0200 |
commit | 900c242551f624f4ab5b3ea79fd51611b47bd95e (patch) | |
tree | 215be6ae5c35f08eaa1be497b504abc0b28ee7c6 /Hsbot.hs | |
parent | Fixed compilation errors. Since I forgot to add the quote module to cabal the... (diff) | |
parent | Added score sorting for the duck module (diff) | |
download | hsbot-900c242551f624f4ab5b3ea79fd51611b47bd95e.tar.gz hsbot-900c242551f624f4ab5b3ea79fd51611b47bd95e.tar.bz2 hsbot-900c242551f624f4ab5b3ea79fd51611b47bd95e.zip |
Merge branch 'master' into quoteModule
Conflicts:
hsbot.cabal
Diffstat (limited to 'Hsbot.hs')
-rw-r--r-- | Hsbot.hs | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -5,30 +5,48 @@ module Hsbot import qualified Config.Dyre as Dyre import Config.Dyre.Relaunch import Control.Monad.Reader +import qualified Data.Map as M import System.Log.Logger import Hsbot.Core import Hsbot.Types +data State = State (M.Map String String) deriving (Read, Show) + startHsbot :: Config -> IO () startHsbot config = do + (State buffer) <- restoreTextState $ State M.empty -- checking for configuration file compilation error case configErrors config of Nothing -> return () Just em -> putStrLn $ "Error: " ++ em + -- Handle previous exit state if it exists + dieMsgs <- case M.lookup "die_msg" buffer of + Just dieMsg -> case reads dieMsg :: [(BotStatus, String)] of + (status, _):_ -> case status of + BotReload reason -> return ["hsbot reloaded, reason : " ++ reason] + BotRestart (reason, Just info) -> return ["hsbot restarted, reason : " ++ reason, "additional information: " ++ info] + BotRestart (reason, Nothing) -> return ["hsbot restarted, reason : " ++ reason] + BotExit -> return [] + _ -> return ["hsbot die_msg parsing error, this should not happen"] + Nothing -> return [] + mapM_ (infoM "Hsbot") dieMsgs -- initialization infoM "Hsbot" "Bot initializations" hsbotEnv <- initHsbot config -- main stuff infoM "Hsbot" "Bot core starting" - status <- runReaderT runHsbot hsbotEnv + status <- runReaderT (runHsbot dieMsgs) hsbotEnv infoM "Hsbot" $ "Bot core exited with status " ++ show status -- Handling exit signal case status of - BotContinue -> startHsbot config -- TODO do something not so dumb about starting over BotExit -> runReaderT terminateHsbot hsbotEnv - BotReload -> relaunchMaster Nothing -- TODO relaunchWithTextState (state { stateConfig = config }) Nothing, add a flag that prevent spawning the sockets again - BotRestart -> relaunchMaster Nothing -- TODO relaunch and kill sockets + BotReload reason -> do + runReaderT terminateHsbot hsbotEnv + relaunchWithTextState (State $ M.singleton "die_msg" . show $ BotReload reason) Nothing -- TODO find a way to properly implement that, then insert necessary information in this MVar + BotRestart reason -> do + runReaderT terminateHsbot hsbotEnv + relaunchWithTextState (State $ M.singleton "die_msg" . show $ BotRestart reason) Nothing hsbot :: Config -> IO () hsbot = Dyre.wrapMain $ Dyre.defaultParams |