Moved to death messages IRC output around, because those were sent too soon
This commit is contained in:
parent
d933088dcb
commit
98a1debf03
2 changed files with 12 additions and 16 deletions
22
Hsbot.hs
22
Hsbot.hs
|
@ -7,11 +7,9 @@ import Config.Dyre.Relaunch
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import System.Log.Logger
|
import System.Log.Logger
|
||||||
import qualified Network.IRC as IRC
|
|
||||||
|
|
||||||
import Hsbot.Core
|
import Hsbot.Core
|
||||||
import Hsbot.Types
|
import Hsbot.Types
|
||||||
import Hsbot.Utils
|
|
||||||
|
|
||||||
data State = State (M.Map String String) deriving (Read, Show)
|
data State = State (M.Map String String) deriving (Read, Show)
|
||||||
|
|
||||||
|
@ -22,27 +20,23 @@ startHsbot config = do
|
||||||
case configErrors config of
|
case configErrors config of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just em -> putStrLn $ "Error: " ++ em
|
Just em -> putStrLn $ "Error: " ++ em
|
||||||
-- initialization
|
|
||||||
infoM "Hsbot" "Bot initializations"
|
|
||||||
hsbotEnv <- initHsbot config
|
|
||||||
-- Handle previous exit state if it exists
|
-- 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
|
Just dieMsg -> case reads dieMsg :: [(BotStatus, String)] of
|
||||||
(status, _):_ -> case status of
|
(status, _):_ -> case status of
|
||||||
BotReload reason -> return ["hsbot reloaded, reason : " ++ reason]
|
BotReload reason -> return ["hsbot reloaded, reason : " ++ reason]
|
||||||
BotRestart (reason, Just info) -> return ["hsbot restarted, readon : " ++ reason, "additional information: " ++ info]
|
BotRestart (reason, Just info) -> return ["hsbot restarted, reason : " ++ reason, "additional information: " ++ info]
|
||||||
BotRestart (reason, Nothing) -> return ["hsbot restarted, readon : " ++ reason]
|
BotRestart (reason, Nothing) -> return ["hsbot restarted, reason : " ++ reason]
|
||||||
BotExit -> return []
|
BotExit -> return []
|
||||||
_ -> return ["hsbot die_msg parsing error, this should not happen"]
|
_ -> return ["hsbot die_msg parsing error, this should not happen"]
|
||||||
Nothing -> return []
|
Nothing -> return []
|
||||||
let connhdl = envHandle hsbotEnv
|
mapM_ (infoM "Hsbot") dieMsgs
|
||||||
tlsCtx = envTLSCtx hsbotEnv
|
-- initialization
|
||||||
channels = configChannels config
|
infoM "Hsbot" "Bot initializations"
|
||||||
mapM_ (infoM "Hsbot") die_msgs
|
hsbotEnv <- initHsbot config
|
||||||
mapM_ (\msg -> mapM_ (\channel -> sendStr hsbotEnv connhdl tlsCtx . IRC.encode $ IRC.Message Nothing "PRIVMSG" [channel, msg]) channels) die_msgs
|
|
||||||
-- main stuff
|
-- main stuff
|
||||||
infoM "Hsbot" "Bot core starting"
|
infoM "Hsbot" "Bot core starting"
|
||||||
status <- runReaderT runHsbot hsbotEnv
|
status <- runReaderT (runHsbot dieMsgs) hsbotEnv
|
||||||
infoM "Hsbot" $ "Bot core exited with status " ++ show status
|
infoM "Hsbot" $ "Bot core exited with status " ++ show status
|
||||||
-- Handling exit signal
|
-- Handling exit signal
|
||||||
case status of
|
case status of
|
||||||
|
|
|
@ -53,8 +53,8 @@ initHsbot config = do
|
||||||
, envTLS = tls
|
, envTLS = tls
|
||||||
, envTLSCtx = tlsCtx }
|
, envTLSCtx = tlsCtx }
|
||||||
|
|
||||||
runHsbot :: Env IO BotStatus
|
runHsbot :: [String] -> Env IO BotStatus
|
||||||
runHsbot = do
|
runHsbot die_msgs = do
|
||||||
botNotInitialized <- asks envBotState >>= liftIO . isEmptyMVar
|
botNotInitialized <- asks envBotState >>= liftIO . isEmptyMVar
|
||||||
when botNotInitialized runFirstSteps
|
when botNotInitialized runFirstSteps
|
||||||
trueRunHsbot
|
trueRunHsbot
|
||||||
|
@ -74,6 +74,8 @@ runHsbot = do
|
||||||
liftIO . sendStr env connhdl tlsCtx . IRC.encode $ IRC.user nickname hostname "*" (configRealname config)
|
liftIO . sendStr env connhdl tlsCtx . IRC.encode $ IRC.user nickname hostname "*" (configRealname config)
|
||||||
-- Then we join channels
|
-- Then we join channels
|
||||||
mapM_ (liftIO . sendStr env connhdl tlsCtx . IRC.encode . IRC.joinChan) 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
|
-- Finally we set the new bot state
|
||||||
asks envBotState >>= liftIO . flip putMVar BotState { botPlugins = M.empty
|
asks envBotState >>= liftIO . flip putMVar BotState { botPlugins = M.empty
|
||||||
, botAccess = configAccess config
|
, botAccess = configAccess config
|
||||||
|
|
Reference in a new issue