Archived
1
0
Fork 0

Added server states, in order to handle rebooting more cleanly (still missing saving the chan)

This commit is contained in:
Julien Dessaux 2009-08-13 00:04:49 +02:00
parent 7a86235906
commit 65646eb07f
2 changed files with 25 additions and 7 deletions

View file

@ -2,8 +2,10 @@ module Hsbot.Core
( Bot(..)
, Config(..)
, IrcServer(..)
, isConnected
, newbot
, sendstr
, saveServersStates
) where
import qualified Data.Map as M
@ -30,7 +32,7 @@ data IrcServer = IrcServer
, password :: String -- the hsbot's password, optional
, realname :: String -- the hsbot's real name, optional
, administrators :: [String] -- bot admins nicknames
} deriving (Eq, Show)
} deriving (Eq, Ord, Show)
-- | Returns a new, empty bot
newbot :: Bot
@ -40,3 +42,15 @@ newbot = Bot (M.empty)
sendstr :: Handle -> String -> IO ()
sendstr handle str = hPrintf handle "%s\r\n" str
-- | Are we already connected to this server?
isConnected :: Bot -> IrcServer -> Bool
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)
saveServersStates :: [(IrcServer,Handle)] -> Bot -> Bot
saveServersStates liste bot = foldr (\(ircServer,handle) bot' -> saveServerState handle ircServer bot') bot liste