Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/irc|the CHICKEN 4 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 [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == irc [[toc:]] === Description A simple IRC client library. === Author [[/users/felix winkelmann|felix winkelmann]] === Requirements None === Download [[http://code.call-cc.org/legacy-eggs/3/irc.egg|irc.egg]] === Documentation This extension provides basic support for the IRC client protocol ([[http://www.faqs.org/rfcs/rfc2812.html|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). ==== irc:connection <procedure>(irc:connection #!key user password server nick real-name port)</procedure> Returns a ''connection'' object, where the following keyword arguments specify the connection parameters: <table> <tr><th>keyword</th><th>argument type</th><th>default</th></tr> <tr><td>{{user}}</td><td>string</td><td>{{nobody}}</td></tr> <tr><td>{{password}}</td><td>string</td><td>''none''</td></tr> <tr><td>{{server}}</td><td>string</td><td>''none''</td></tr> <tr><td>{{nick}}</td><td>string</td><td>some random symbol</td></tr> <tr><td>{{real-name}}</td><td>string</td><td>same as the {{user}} parameter</td></tr> <tr><td>{{port}}</td><td>integer</td><td>6667</td></tr> </table> A server must be provided in any case. The connection object can be queried using the following accessors: <procedure>(irc:connection? X)</procedure> Returns {{#t}} if {{X}} is a connection object, or {{#f}} otherwise. <procedure>(irc:connection-in CONNECTION)</procedure> <procedure>(irc:connection-out CONNECTION)</procedure> <procedure>(irc:connection-server CONNECTION)</procedure> <procedure>(irc:connection-nick CONNECTION)</procedure> <procedure>(irc:connection-user CONNECTION)</procedure> <procedure>(irc:connection-real-name CONNECTION)</procedure> <procedure>(irc:connection-port CONNECTION)</procedure> <procedure>(irc:connection-channel CONNECTION)</procedure> <procedure>(irc:connection-password CONNECTION)</procedure> 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! <procedure>(irc:connection-raw-filter-set! CONNECTION PROC)</procedure> 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 descontruction machinery instead. Use this facility to perform very low level pre-processing of input from the IRC server. ==== irc:connect <procedure>(irc:connect CONNECTION)</procedure> <procedure>(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 <procedure>(irc:disconnect CONNECTION)</procedure> Disconnects any currently active connection. ==== irc:connected? <procedure>(irc:connected? CONNECTION)</procedure> Returns {{#t}} if there exists an open connection for {{CONNECTION}}, or {{#f}} otherwise. ==== irc:quit <procedure>(irc:quit CONNECTION [MESSAGE])</procedure> 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 <procedure>(irc:join CONNECTION CHANNEL)</procedure> Sends {{JOIN}} messages for the given {{CHANNEL}} (a string). ==== irc:part <procedure>(irc:part CONNECTION CHANNEL)</procedure> Leaves the channels given in the string {{CHANNEL}} by sending a {{PART}} message. ==== irc:nick <procedure>(irc:nick CONNECTION NICK)</procedure> Changes the nickname to the one given in the string {{NICK}}. ==== irc:say <procedure>(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 <procedure>(irc:notice CONNECTION MESSAGE DESTINATION ...)</procedure> Similar to {{irc:say}} but uses a {{NOTICE}} command instead. ==== irc:action <procedure>(irc:action CONNECTION MESSAGE DESTINATION ...)</procedure> Similar to {{irc:say}} but Sends an "action" instead of a normal message. ==== irc:command <procedure>(irc:command CONNECTION STRING)</procedure> Sends an arbitrary IRC command to the server. ==== irc:listen <procedure>(irc:listen CONNECTION)</procedure> 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: <procedure>(irc:message? X)</procedure> Returns {{#t}} if {{X}} is a message object, or {{#f}} otherwise. <procedure>(irc:message-prefix MESSAGE)</procedure> <procedure>(irc:message-command MESSAGE)</procedure> <procedure>(irc:message-timestamp MESSAGE)</procedure> <procedure>(irc:message-code MESSAGE)</procedure> <procedure>(irc:message-body MESSAGE)</procedure> <procedure>(irc:message-parameters MESSAGE)</procedure> <procedure>(irc:message-index MESSAGE)</procedure> 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 {{ACTION}}s), then the last value in the list is an ''extended data'' object. The index is a numeric message index. ==== irc:message-sender <procedure>(irc:message-sender MESSAGE)</procedure> <procedure>(irc:message-receiver MESSAGE)</procedure> 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? <procedure>(irc:extended-data? X)</procedure> Returns {{#t}} if {{X}} is an extended data object, or {{#f}} otherwise. ==== irc:extended-data-tag <procedure>(irc:extended-data-tag EXTENDED)</procedure> <procedure>(irc:extended-data-content EXTENDED)</procedure> Return the tag (symbol) and content (string) parts of an extended data object. ==== irc:wait <procedure>(irc:wait CONNECTION)</procedure> Waits until data is available from {{CONNECTION}} and returns the parsed message object. ==== irc:process-message <procedure>(irc:process-message CONNECTION MESSAGE [VERBOSE])</procedure> 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 <procedure>(irc:run-message-loop CONNECTION #!key debug pong filter)</procedure> 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! <procedure>(irc:add-message-handler! CONNECTION PROC #!key command sender receiver body tag code)</procedure> 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-match}}, with the exception of the {{body}} keyword argument, which 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! <procedure>(irc:remove-message-handler! CONNECTION TAG)</procedure> Removes the message handler with the given tag. === Example A minimalistic bot that shows the current time, when asked: <enscript highlight="scheme"> (require-extension irc posix) (define con (irc:connection server: "irc.freenode.net" nick: "PongoTwistleton") ) (define (bleep _) (irc:say con (seconds->string (current-seconds))) ) (irc:connect con) (irc:join con "#scheme") (irc:add-message-handler! con bleep command: "PRIVMSG" body: "time" receiver: (irc:connection-nick con) ) (irc:run-message-loop con debug: #t) </enscript> === Changelog * 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] * 1.0 === License Copyright (c) 2000-2005, 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 3 from 2?