Safe Haskell | None |
---|---|
Language | Haskell2010 |
A simple IRC client library. Typical usage will be of this form:
run :: ByteString -> Int -> Text -> IO () run host port nick = do conn <- connect host port 1 let cfg = defaultIRCConf nick let cfg' = cfg { _eventHandlers = yourCustomEventHandlers : _eventHandlers cfg } start conn cfg'
You shouldn't really need to tweak anything other than the event handlers, as everything has been designed to be as simple as possible.
- connect :: MonadIO m => ByteString -> Int -> NominalDiffTime -> m (ConnectionConfig s)
- connectWithTLS :: MonadIO m => ByteString -> Int -> NominalDiffTime -> m (ConnectionConfig s)
- start :: MonadIO m => ConnectionConfig () -> InstanceConfig () -> m ()
- start' :: MonadIO m => IRCState s -> m ()
- startStateful :: MonadIO m => ConnectionConfig s -> InstanceConfig s -> s -> m ()
- data Origin
- connect' :: MonadIO m => (Origin -> ByteString -> IO ()) -> ByteString -> Int -> NominalDiffTime -> m (ConnectionConfig s)
- connectWithTLS' :: MonadIO m => (Origin -> ByteString -> IO ()) -> ByteString -> Int -> NominalDiffTime -> m (ConnectionConfig s)
- stdoutLogger :: Origin -> ByteString -> IO ()
- fileLogger :: FilePath -> Origin -> ByteString -> IO ()
- noopLogger :: a -> b -> IO ()
- send :: UnicodeMessage -> StatefulIRC s ()
- sendBS :: IrcMessage -> StatefulIRC s ()
- disconnect :: StatefulIRC s ()
- defaultIRCConf :: Text -> InstanceConfig s
- defaultOnConnect :: StatefulIRC s ()
- defaultOnDisconnect :: StatefulIRC s ()
- defaultEventHandlers :: [EventHandler s]
- module Network.IRC.Client.Types
- module Network.IRC.Client.Utils
- rawMessage :: ByteString -> [ByteString] -> IrcMessage
- toByteString :: IrcMessage -> ByteString
Initialisation
:: MonadIO m | |
=> ByteString | The hostname |
-> Int | The port |
-> NominalDiffTime | The flood cooldown |
-> m (ConnectionConfig s) |
Connect to a server without TLS.
:: MonadIO m | |
=> ByteString | The hostname |
-> Int | The port |
-> NominalDiffTime | The flood cooldown |
-> m (ConnectionConfig s) |
Connect to a server with TLS.
start :: MonadIO m => ConnectionConfig () -> InstanceConfig () -> m () Source
Run the event loop for a server, receiving messages and handing them off to handlers as appropriate. Messages will be logged to stdout.
startStateful :: MonadIO m => ConnectionConfig s -> InstanceConfig s -> s -> m () Source
like start
but for clients with state.
Logging
The origin of a message.
:: MonadIO m | |
=> (Origin -> ByteString -> IO ()) | The message logger |
-> ByteString | The hostname |
-> Int | The port |
-> NominalDiffTime | The flood cooldown |
-> m (ConnectionConfig s) |
Connect to a server without TLS, with the provided logging function.
:: MonadIO m | |
=> (Origin -> ByteString -> IO ()) | The message logger |
-> ByteString | The hostname |
-> Int | The port |
-> NominalDiffTime | The flood cooldown |
-> m (ConnectionConfig s) |
Connect to a server with TLS, with the provided logging function.
stdoutLogger :: Origin -> ByteString -> IO () Source
Print messages to stdout, with the current time.
fileLogger :: FilePath -> Origin -> ByteString -> IO () Source
Append messages to a file, with the current time.
noopLogger :: a -> b -> IO () Source
Do no logging.
Interaction
send :: UnicodeMessage -> StatefulIRC s () Source
Send a message as UTF-8, using TLS if enabled. This blocks if messages are sent too rapidly.
sendBS :: IrcMessage -> StatefulIRC s () Source
Send a message, using TLS if enabled. This blocks if messages are sent too rapidly.
disconnect :: StatefulIRC s () Source
Disconnect from the server, properly tearing down the TLS session (if there is one).
Defaults
defaultIRCConf :: Text -> InstanceConfig s Source
Construct a default IRC configuration from a nick
defaultOnConnect :: StatefulIRC s () Source
The default connect handler: set the nick and join default channels.
defaultOnDisconnect :: StatefulIRC s () Source
The default disconnect handler: do nothing. You might want to override this with one which reconnects.
defaultEventHandlers :: [EventHandler s] Source
The default event handlers, the following are included:
- respond to server
PING
messages with aPONG
; - respond to CTCP
PING
requests with a CTCPPONG
; - respond to CTCP
VERSION
requests with the version string; - respond to CTCP
TIME
requests with the system time; - update the nick upon receiving the welcome message, in case the server modifies it;
- mangle the nick if the server reports a collision;
- update the channel list on
JOIN
andKICK
.
These event handlers are all exposed through the
Network.IRC.Client.Handlers module, so you can use them directly if
you are building up your InstanceConfig
from scratch.
If you are building a bot, you may want to write an event handler to process messages representing commands.
Types
module Network.IRC.Client.Types
Utilities
module Network.IRC.Client.Utils
:: ByteString | The command |
-> [ByteString] | The arguments |
-> IrcMessage |
Construct a raw message.
toByteString :: IrcMessage -> ByteString
Encode an IRC message into a single bytestring suitable for sending to the server.