From 65646eb07fa559e072ed53b32d168ecd314cae14 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 13 Aug 2009 00:04:49 +0200 Subject: Added server states, in order to handle rebooting more cleanly (still missing saving the chan) --- Hsbot/Core.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Hsbot/Core.hs') diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs index 5e4853f..c62ae58 100644 --- a/Hsbot/Core.hs +++ b/Hsbot/Core.hs @@ -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 + -- cgit v1.2.3