summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2009-08-23 23:07:43 +0200
committerJulien Dessaux2009-08-23 23:07:43 +0200
commitd4103e3e18a36523735af38eace98a64e1068e6e (patch)
tree8b5995432eaac1c0321cffcb187c7e31a4f1ff23 /Hsbot
parentAdded the IRCParser (thx galdor), and PrivMsg handling (simply repeat) (diff)
downloadhsbot-d4103e3e18a36523735af38eace98a64e1068e6e.tar.gz
hsbot-d4103e3e18a36523735af38eace98a64e1068e6e.tar.bz2
hsbot-d4103e3e18a36523735af38eace98a64e1068e6e.zip
Rebooting now works great, thanks to the communication channel preservation.v0.1.0
Diffstat (limited to 'Hsbot')
-rw-r--r--Hsbot/Core.hs6
-rw-r--r--Hsbot/Main.hs19
2 files changed, 13 insertions, 12 deletions
diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs
index c62ae58..fddcb72 100644
--- a/Hsbot/Core.hs
+++ b/Hsbot/Core.hs
@@ -49,8 +49,8 @@ isConnected (Bot bot) ircServer = ircServer `M.member` bot
saveServerState :: Handle -> IrcServer -> Bot -> Bot
saveServerState handle ircServer x@(Bot bot) =
if ircServer `M.member` bot then x
- else (Bot $ M.insert ircServer handle bot)
+ else (Bot $ M.insert ircServer handle bot)
-saveServersStates :: [(IrcServer,Handle)] -> Bot -> Bot
-saveServersStates liste bot = foldr (\(ircServer,handle) bot' -> saveServerState handle ircServer bot') bot liste
+saveServersStates :: [(IrcServer, Handle)] -> Bot -> Bot
+saveServersStates liste bot = foldl (\bot' (ircServer, handle) -> saveServerState handle ircServer bot') bot liste
diff --git a/Hsbot/Main.hs b/Hsbot/Main.hs
index 4c006b5..8972022 100644
--- a/Hsbot/Main.hs
+++ b/Hsbot/Main.hs
@@ -14,28 +14,29 @@ import qualified Config as C
import Hsbot.Core
import Hsbot.IRC
-type Reboot = (Module -> Bot -> IO ())
+type Reboot = (Module -> Bot -> (Chan IrcLine) -> IO ())
-- | Bot's first main entry point
imain :: Module -> Reboot -> IO ()
-imain modul' reboot = imain' modul' reboot newbot
+imain modul' reboot = do
+ chan <- newChan :: IO (Chan IrcLine)
+ imain' modul' reboot newbot chan
-- | Bot's main entry point
-imain' :: Module -> Reboot -> Bot -> IO ()
-imain' modul' reboot bot = do
+imain' :: Module -> Reboot -> Bot -> (Chan IrcLine) -> IO ()
+imain' modul' reboot bot chan = do
-- The chan passing to reboot (or another way to keep it) is still missing
- putStrLn "Connecting servers..."
let newServers = filter (not . isConnected bot) (ircServers C.config)
+ putStrLn $ "Connecting servers : " ++ show (map address newServers)
newServers' <- mapM connectServer newServers
- putStrLn "Joining channels..."
+ putStrLn $ "Joining channels : " ++ show (map channels newServers)
mapM_ initServer newServers'
putStrLn "Spawning threads..."
let bot' = saveServersStates newServers' bot
Bot x = bot'
- chan <- newChan :: IO (Chan IrcLine)
- mapM_ (forkIO . listener chan) (M.toList x)
+ mapM_ (forkIO . listener chan) newServers' -- (M.toList x)
bot'' <- monitor chan bot'
- reboot modul' bot''
+ reboot modul' bot'' chan
-- | Bot main loop, monitors the threads states and handle reboot
monitor :: (Chan IrcLine) -> Bot -> IO Bot