Skip to content

Commit

Permalink
simplify calling the disconnect function; get rid of eventFuncD
Browse files Browse the repository at this point in the history
  • Loading branch information
mklinik committed Apr 21, 2012
1 parent 1e6dae9 commit 6946d20
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Network/SimpleIRC/Core.hs
Expand Up @@ -57,6 +57,7 @@ import Data.Time
import System.Locale
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Data.Foldable as Foldable

internalEvents :: [IrcServer -> IrcMessage -> IO IrcServer]
internalEvents = [joinChans, pong, trackChanges]
Expand Down Expand Up @@ -277,12 +278,8 @@ listenLoop s = do
-- If EOF then we are disconnected
if (eof /= Just False)
then do
let comp = (\a -> a `eqEvent` (Disconnect undefined))
evts = Map.filter comp (sEvents server)
eventCall = (\obj -> (eventFuncD $ snd obj) s)
modifyMVar_ s (\serv -> return $ serv {sSock = Nothing})
debugWrite server $ B.pack $ show $ length $ Map.toList evts
mapM_ eventCall (Map.toList evts)
Foldable.mapM_ (callDisconnectFunction s) (sEvents server)
else do
line <- B.hGetLine h

Expand All @@ -305,6 +302,9 @@ listenLoop s = do


listenLoop s
where
callDisconnectFunction mIrc (Disconnect f) = f mIrc
callDisconnectFunction _ _ = return ()

-- Internal Events - They can edit the server
joinChans :: IrcServer -> IrcMessage -> IO IrcServer
Expand Down Expand Up @@ -465,8 +465,6 @@ eventFunc (Nick f) = f
eventFunc (Notice f) = f
eventFunc (RawMsg f) = f

eventFuncD (Disconnect f) = f

-- |Sends a raw command to the server
sendRaw :: MIrc -> B.ByteString -> IO ()
sendRaw mServ msg = do
Expand Down

0 comments on commit 6946d20

Please sign in to comment.