irc-client 0.2.6.0 → 0.3.0.0
raw patch · 5 files changed
+45/−25 lines, 5 files
Files
- Network/IRC/Client.hs +5/−4
- Network/IRC/Client/Handlers.hs +14/−5
- Network/IRC/Client/Internal.hs +20/−13
- Network/IRC/Client/Types.hs +4/−1
- irc-client.cabal +2/−2
Network/IRC/Client.hs view
@@ -35,7 +35,8 @@ -- * Defaults , defaultIRCConf- , defaultDisconnectHandler+ , defaultOnConnect+ , defaultOnDisconnect , defaultEventHandlers -- * Types@@ -94,7 +95,7 @@ -> NominalDiffTime -- ^ The flood cooldown -> m (ConnectionConfig s)-connect' = connectInternal ircClient defaultDisconnectHandler+connect' = connectInternal ircClient defaultOnConnect defaultOnDisconnect -- | Connect to a server with TLS, with the provided logging function. connectWithTLS' :: MonadIO m@@ -107,7 +108,7 @@ -> NominalDiffTime -- ^ The flood cooldown -> m (ConnectionConfig s)-connectWithTLS' = connectInternal ircTLSClient defaultDisconnectHandler+connectWithTLS' = connectInternal ircTLSClient defaultOnConnect defaultOnDisconnect -- * Starting @@ -134,7 +135,7 @@ , _username = n , _realname = n , _channels = []- , _ctcpVer = "irc-client-0.2.5.0"+ , _ctcpVer = "irc-client-0.3.0.0" , _eventHandlers = defaultEventHandlers , _ignore = [] }
Network/IRC/Client/Handlers.hs view
@@ -13,8 +13,9 @@ , welcomeNick , nickMangler - -- * Disconnect handlers- , defaultDisconnectHandler+ -- * Special handlers+ , defaultOnConnect+ , defaultOnDisconnect ) where import Control.Applicative ((<$>))@@ -188,12 +189,20 @@ | otherwise -> return () _ -> return () --- *Misc+-- *Special +-- | The default connect handler: set the nick and join default+-- channels.+defaultOnConnect :: StatefulIRC s ()+defaultOnConnect = do+ iconf <- instanceConfig+ send . Nick $ _nick iconf+ mapM_ (send . Join) $ _channels iconf+ -- | The default disconnect handler: do nothing. You might want to -- override this with one which reconnects.-defaultDisconnectHandler :: StatefulIRC s ()-defaultDisconnectHandler = return ()+defaultOnDisconnect :: StatefulIRC s ()+defaultOnDisconnect = return () -- *Utils
Network/IRC/Client/Internal.hs view
@@ -33,23 +33,32 @@ -- | Connect to a server using the supplied connection function. connectInternal :: MonadIO m => (Int -> ByteString -> IO () -> Consumer (Either ByteString IrcEvent) IO () -> Producer IO IrcMessage -> IO ())+ -- ^ Function to start the network conduits. -> StatefulIRC s ()+ -- ^ Connect handler+ -> StatefulIRC s ()+ -- ^ Disconnect handler -> (Origin -> ByteString -> IO ())+ -- ^ Logging function -> ByteString+ -- ^ Server hostname -> Int+ -- ^ Server post -> NominalDiffTime+ -- ^ Flood timeout -> m (ConnectionConfig s)-connectInternal f dcHandler logf host port flood = liftIO $ do+connectInternal f onconnect ondisconnect logf host port flood = liftIO $ do queueS <- newTBMChanIO 16 return ConnectionConfig- { _func = f- , _sendqueue = queueS- , _server = host- , _port = port- , _flood = flood- , _disconnect = dcHandler- , _logfunc = logf+ { _func = f+ , _sendqueue = queueS+ , _server = host+ , _port = port+ , _flood = flood+ , _onconnect = onconnect+ , _ondisconnect = ondisconnect+ , _logfunc = logf } -- * Event loop@@ -59,16 +68,14 @@ runner = do state <- ircState - -- Set the nick and username- theNick <- _nick <$> instanceConfig+ -- Set the real- and user-name theUser <- _username <$> instanceConfig theReal <- _realname <$> instanceConfig -- Initialise the IRC session let initialise = flip runReaderT state $ do sendBS $ rawMessage "USER" [encodeUtf8 theUser, "-", "-", encodeUtf8 theReal]- send $ Nick theNick- instanceConfig >>= mapM_ (send . Join) . _channels+ _onconnect =<< connectionConfig -- Run the event loop, and call the disconnect handler if the remote -- end closes the socket.@@ -81,7 +88,7 @@ antiflood <- liftIO $ floodProtector flood - dchandler <- _disconnect <$> connectionConfig+ dchandler <- _ondisconnect <$> connectionConfig let source = toProducer $ sourceTBMChan queue $= antiflood $= logConduit (logf FromClient . toByteString) let sink = forgetful =$= logConduit (logf FromServer . _raw) =$ eventSink state
Network/IRC/Client/Types.hs view
@@ -122,7 +122,10 @@ -- ^ The server port. , _flood :: NominalDiffTime -- ^ The minimum time between two adjacent messages.- , _disconnect :: StatefulIRC s ()+ , _onconnect :: StatefulIRC s ()+ -- ^ Action to run after successfully connecting to the server and+ -- setting the nick.+ , _ondisconnect :: StatefulIRC s () -- ^ Action to run if the remote server closes the connection. , _logfunc :: Origin -> ByteString -> IO () -- ^ Function to log messages sent to and received from the server.
irc-client.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.2.6.0+version: 0.3.0.0 -- A short (one-line) description of the package. synopsis: An IRC client library.@@ -108,4 +108,4 @@ source-repository this type: git location: https://github.com/barrucadu/irc-client.git- tag: 0.2.6.0+ tag: 0.3.0.0