This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
- Outdated egg!
A simple IRC client library.
This extension provides basic support for the IRC client protocol (RFC 2812). Note that some basic knowledge of the protocol will be needed to use this library.
Error-replies from the server are signalled as composite conditions of kind (exn irc) with the properties code (the IRC error code) and reply (the actual message object received). If the connection is terminated by the server, a composite condition of the kinds (exn irc/eof) is signalled. Automatic reconnection on timeout or eof is supported and optional.
- irc:connection #!key user password server nick real-name port log-traffic ping-timeout reconnect reconnect-timeoutprocedure
Returns a connection object, where the following keyword arguments specify the connection parameters:
keyword argument type default user string nobody password string none server string none nick string some random symbol real-name string same as the user parameter port integer 6667 log-traffic port or #f #f reconnect-timeout milliseconds (integer) 3600000 reconnect boolean #f
A server must be provided in any case.
The connection object can be queried using the following accessors:
- irc:connection? Xprocedure
Returns #t if X is a connection object, or #f otherwise.
- irc:connection-in CONNECTIONprocedure
- irc:connection-out CONNECTIONprocedure
- irc:connection-server CONNECTIONprocedure
- irc:connection-nick CONNECTIONprocedure
- irc:connection-user CONNECTIONprocedure
- irc:connection-real-name CONNECTIONprocedure
- irc:connection-port CONNECTIONprocedure
- irc:connection-channels CONNECTIONprocedure
- irc:connection-log-file CONNECTIONprocedure
- irc:connection-reconnect-timeout CONNECTIONprocedure
- irc:connection-password CONNECTIONprocedure
- irc:connection-reconnect? CONNECTIONprocedure
Accessors for values stored in a connection object. The in and out values are ports, port is an integer, channel is a string and all other values are strings.
- irc:connection-raw-filter-set! CONNECTION PROCprocedure
When set, then each line of received input will first be processed by the one argument procedure PROC, and the result be passed to the message deconstruction machinery instead. Use this facility to perform very low level pre-processing of input from the IRC server.
- irc:connect CONNECTIONprocedure
- irc:connect #!key KEYWORD ...procedure
Connects to an IRC server, with the parameters given in the connection object CONNECTION or via the parameters passed as keywords arguments (just like in the call to irc:connection). Returns the connection object. A connection can only be made to a single server at the same time.
- irc:disconnect CONNECTIONprocedure
Disconnects any currently active connection.
- irc:reconnect CONNECTIONprocedure
Disconnect and reconnect to CONNECTION, automatically re-joining all channels that we have currently joined.
- irc:connected? CONNECTIONprocedure
Returns #t if there exists an open connection for CONNECTION, or #f otherwise.
- irc:quit CONNECTION #!optional MESSAGEprocedure
Sends a QUIT message to the IRC server (optionally with the text MESSAGE) and closes the connection designated by the connection object CONNECTION.
- irc:join CONNECTION CHANNELprocedure
Sends JOIN messages for the given CHANNEL (a string).
- irc:part CONNECTION CHANNELprocedure
- irc:leave CONNECTION CHANNELprocedure
Leaves the channels given in the string CHANNEL by sending a PART message.
- irc:nick CONNECTION NICKprocedure
Changes the nickname to the one given in the string NICK.
- irc:say CONNECTION MESSAGE DESTINATION ...procedure
Sends the string MESSAGE via a PRIVMSG command to the given destinations, which should be strings designating either channels or nicknames. If no destinations are given, the message is sent to the last channel that has been joined. The message is split into multiple PRIVMSG operations, if it contains newline characters.
- irc:notice CONNECTION MESSAGE DESTINATION ...procedure
Similar to irc:say but uses a NOTICE command instead.
- irc:action CONNECTION MESSAGE DESTINATION ...procedure
Similar to irc:say but Sends an "action" instead of a normal message.
- irc:command CONNECTION STRINGprocedure
Sends an arbitrary IRC command to the server.
- irc:listen CONNECTIONprocedure
If data is available for reading, then the incoming message is parsed and a "message" object is returned. If no data is currently available, #f is returned.
The message object can be queried with the following procedures:
- irc:message? Xprocedure
Returns #t if X is a message object, or #f otherwise.
- irc:message-prefix MESSAGEprocedure
- irc:message-command MESSAGEprocedure
- irc:message-timestamp MESSAGEprocedure
- irc:message-code MESSAGEprocedure
- irc:message-body MESSAGEprocedure
- irc:message-parameters MESSAGEprocedure
- irc:message-index MESSAGEprocedure
Return the components of a message object. The prefix is either a list of the form (SERVERNAME) or a list containing the message prefix of the form (NICK USER HOST) (all values are strings). The timestamp holds the current number of seconds (as returned by (current-seconds)) at the point when the message was parsed. The body contains the complete message string. The code is a numerical command-code for the message or #f. The parameters is a list of strings, containing message destination and message body. If the message contains extended information (mostly ACTIONs), then the last value in the list is an extended data object. The index is a numeric message index.
- irc:message-sender MESSAGEprocedure
- irc:message-receiver MESSAGEprocedure
Returns the sender and receiver of a message, respectively. The receiver may be a channel name or the nickname of another client.
- irc:extended-data? Xprocedure
Returns #t if X is an extended data object, or #f otherwise.
- irc:extended-data-tag EXTENDEDprocedure
- irc:extended-data-content EXTENDEDprocedure
Return the tag (symbol) and content (string) parts of an extended data object.
- irc:wait CONNECTIONprocedure
Waits until data is available from CONNECTION and returns the parsed message object.
- irc:process-message CONNECTION MESSAGE #!optional VERBOSEprocedure
Calls any registered message handlers that apply to MESSAGE. If the optional argument VERBOSE is given and true, then diagnostic output will be written to the port returned by (current-output-port).
- irc:run-message-loop CONNECTION #!key debug pong filterprocedure
Repeatedly calls irc:wait and irc:process-message. If the keyword argument debug is given and true, then each incoming message will be dumped to the port given by the value of (current-output-port). The keyword argument pong specifies whether automatic processing of PING messages should be done. If yes, then a message handler with the tag ping (a symbol) will be registered as with the following commands:
(irc:add-message-handler! con (lambda (msg) (irc:command con (string-append "PONG :" (car (irc:message-parameters msg)))) ) tag: 'ping command: "PING") )
The keyword argument filter can be used to specify a procedure that will be called for each icoming message object (the result will be used for further processing instead).
- irc:add-message-handler! CONNECTION PROC #!key command sender receiver body tag codeprocedure
Defines a message handler for the given CONNECTION that will invoke the one argument procedure PROC with the received message object when all of the regular expressions given for the keyword arguments match (uses string-search), and the code, which should be an exact integer (and is compared using eq?).
The keyword tag defines a message-handler tag, which can be used to remove the handler at a later time.
Note that if this procedure is called with two arguments (and no keyword args), then the message handler will be invoked for all incoming messages.
Message handlers are run in the order in which they are defined. A message handler should return #f if further handlers should be invoked for the same message, or true if other handlers should not be called.
The command, sender, receiver and body arguments may optionally be predicates instead of strings (which will be called with the respective part of the checked message) to allow more fine-grained matching.
- irc:remove-message-handler! CONNECTION TAGprocedure
Removes the message handler with the given tag.
A minimalistic bot that shows the current time, when asked:
(require-extension irc posix) (define con (irc:connection server: "irc.freenode.net" nick: "PongoTwistleton") ) (define (bleep _) (irc:say con (seconds->string (current-seconds)) "#somechannel") ) (irc:connect con) (irc:join con "#somechannel") (irc:add-message-handler! con bleep command: "PRIVMSG" body: "time") (irc:run-message-loop con debug: #t)
- 1.9.8 reading input did not apply the timeout-parameter correctly (fix contributed by Alex Charlton)
- 1.9.3 reconnecting on timeout
- 1.9.2 reconnect feature
- 1.9.1 handling of server-EOF
- 1.9 added logging and ping-timeout support
- 1.8 uses string-search for matching handlers; allows regexp objects
- 1.7 Ported to CHICKEN 4
- 1.6 Added irc:disconnect
- 1.5 Multimessage-support [Thanks to Andreas Scholta, again]
- 1.4 Fixed bug in irc:remove-message-handler! [Thanks to Andreas Scholta]
- 1.3 irc:join accepts only a single channel
- 1.2 Fixed a bug in processing of handler tags [Thanks to Vesa, again!]
- 1.1 Added irc:connection-raw-handler-set! and further options to irc:run-message-loop (in addition to PING handling) [Thanks to Vesa Kaihlavirta]
Copyright (c) 2000-2009, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICESLOSS OF USE, DATA, OR PROFITSOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.