From 98a1debf03cd0b5145578f823b025d2315394503 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 9 Aug 2011 23:48:15 +0200 Subject: Moved to death messages IRC output around, because those were sent too soon --- Hsbot.hs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'Hsbot.hs') diff --git a/Hsbot.hs b/Hsbot.hs index 08456bf..33cfa45 100644 --- a/Hsbot.hs +++ b/Hsbot.hs @@ -7,11 +7,9 @@ import Config.Dyre.Relaunch import Control.Monad.Reader import qualified Data.Map as M import System.Log.Logger -import qualified Network.IRC as IRC import Hsbot.Core import Hsbot.Types -import Hsbot.Utils data State = State (M.Map String String) deriving (Read, Show) @@ -22,27 +20,23 @@ startHsbot config = do case configErrors config of Nothing -> return () Just em -> putStrLn $ "Error: " ++ em - -- initialization - infoM "Hsbot" "Bot initializations" - hsbotEnv <- initHsbot config -- Handle previous exit state if it exists - die_msgs <- case M.lookup "die_msg" buffer of + 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, readon : " ++ reason, "additional information: " ++ info] - BotRestart (reason, Nothing) -> return ["hsbot restarted, readon : " ++ 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 [] - let connhdl = envHandle hsbotEnv - tlsCtx = envTLSCtx hsbotEnv - channels = configChannels config - mapM_ (infoM "Hsbot") die_msgs - mapM_ (\msg -> mapM_ (\channel -> sendStr hsbotEnv connhdl tlsCtx . IRC.encode $ IRC.Message Nothing "PRIVMSG" [channel, msg]) channels) die_msgs + 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 -- cgit v1.2.3