diff options
author | Julien Dessaux | 2009-08-13 00:04:49 +0200 |
---|---|---|
committer | Julien Dessaux | 2009-08-13 00:04:49 +0200 |
commit | 65646eb07fa559e072ed53b32d168ecd314cae14 (patch) | |
tree | 30ae7009f3606b874c1b3702f8e9bf975bbc505c /Hsbot/Main.hs | |
parent | Rethought the way I handled IRC data. (diff) | |
download | hsbot-65646eb07fa559e072ed53b32d168ecd314cae14.tar.gz hsbot-65646eb07fa559e072ed53b32d168ecd314cae14.tar.bz2 hsbot-65646eb07fa559e072ed53b32d168ecd314cae14.zip |
Added server states, in order to handle rebooting more cleanly (still missing saving the chan)
Diffstat (limited to '')
-rw-r--r-- | Hsbot/Main.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Hsbot/Main.hs b/Hsbot/Main.hs index 9edd807..8c4be63 100644 --- a/Hsbot/Main.hs +++ b/Hsbot/Main.hs @@ -6,6 +6,7 @@ module Hsbot.Main import Control.Concurrent import Control.Concurrent.Chan import Control.Monad +import qualified Data.Map as M import System.IO import System.Plugins @@ -22,16 +23,19 @@ imain modul' reboot = imain' modul' reboot newbot -- | Bot's main entry point imain' :: Module -> Reboot -> Bot -> IO () imain' modul' reboot bot = do - putStrLn "yeah" + -- The chan passing to reboot (or another way to keep it) is still missing putStrLn "Connecting servers..." - servers' <- mapM connectServer (ircServers C.config) + let newServers = filter (not . isConnected bot) (ircServers C.config) + newServers' <- mapM connectServer newServers putStrLn "Joining channels..." - mapM_ initServer servers' + mapM_ initServer newServers' putStrLn "Spawning threads..." + let bot' = saveServersStates newServers' bot + Bot x = bot' chan <- newChan :: IO (Chan IrcLine) - mapM_ (forkIO . listener chan) servers' - state <- monitor chan bot - reboot modul' bot + mapM_ (forkIO . listener chan) (M.toList x) + bot'' <- monitor chan bot' + reboot modul' bot'' -- | Bot main loop, monitors the threads states and handle reboot monitor :: (Chan IrcLine) -> Bot -> IO Bot |