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/Core.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/Core.hs | 16 |
1 files changed, 15 insertions, 1 deletions
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 + |