summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2011-08-09 23:48:15 +0200
committerJulien Dessaux2011-08-09 23:48:15 +0200
commit98a1debf03cd0b5145578f823b025d2315394503 (patch)
tree61eb8b705f396830ff637fb0dd1bfcdaf1b8583a
parentcosmetic (diff)
downloadhsbot-98a1debf03cd0b5145578f823b025d2315394503.tar.gz
hsbot-98a1debf03cd0b5145578f823b025d2315394503.tar.bz2
hsbot-98a1debf03cd0b5145578f823b025d2315394503.zip
Moved to death messages IRC output around, because those were sent too soon
Diffstat (limited to '')
-rw-r--r--Hsbot.hs22
-rw-r--r--Hsbot/Core.hs6
2 files changed, 12 insertions, 16 deletions
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
diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs
index 49f5f5d..4dc1e92 100644
--- a/Hsbot/Core.hs
+++ b/Hsbot/Core.hs
@@ -53,8 +53,8 @@ initHsbot config = do
, envTLS = tls
, envTLSCtx = tlsCtx }
-runHsbot :: Env IO BotStatus
-runHsbot = do
+runHsbot :: [String] -> Env IO BotStatus
+runHsbot die_msgs = do
botNotInitialized <- asks envBotState >>= liftIO . isEmptyMVar
when botNotInitialized runFirstSteps
trueRunHsbot
@@ -74,6 +74,8 @@ runHsbot = do
liftIO . sendStr env connhdl tlsCtx . IRC.encode $ IRC.user nickname hostname "*" (configRealname config)
-- Then we join channels
mapM_ (liftIO . sendStr env connhdl tlsCtx . IRC.encode . IRC.joinChan) channels
+ -- We advertise any death message we should
+ mapM_ (\msg -> mapM_ (\channel -> liftIO . sendStr env connhdl tlsCtx . IRC.encode $ IRC.Message Nothing "PRIVMSG" [channel, msg]) channels) die_msgs
-- Finally we set the new bot state
asks envBotState >>= liftIO . flip putMVar BotState { botPlugins = M.empty
, botAccess = configAccess config