This is a preliminary API reference manual for guile-irc version 0.2. Copyright © 2012 bas smit (fbs)
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.

1 IRC

1.1 IRC API

— Procedure: make-irc [#:nick=“bot”] [#:realname=“bot”] [#:hostname=“localhost”] [#:server=”localhost”] [#:port=6667] [#:password=”#f”]

Create a new irc-object.

— Constant: *nick* “bot”
— Constant: *realname* “mr bot”
— Constant: *server* “localhost”
— Constant: *port* 6667
— Constant: *hostname* “localhost”
— Constant: *quitmsg* “Not enough parenthesis”

Default values.

— Procedure: irc-object? obj

Return #t if obj is an irc-object, else return #f.

— Procedure: nick obj
— Procedure: realname obj
— Procedure: hostname obj
— Procedure: password obj
— Procedure: port obj
— Procedure: server obj

Access the corresponding field of irc-object obj.

— Procedure: set-port! obj val
— Procedure: set-server! obj val
— Procedure: set-nick! obj val
— Procedure: set-realname! obj val
— Procedure: set-hostname! obj val
— Procedure: set-password! obj val

Set the field of irc-object obj. set-port! expects a valid port number, all others expect a string. Using the empty string will reset the values to their defaults (see make-irc). The return value is not specified.

Note that it is not possible to set a value when connected. Trying to do so will result in an error.

— Procedure: do-nick obj nick

Not yet implemented.

— Procedure: do-connect obj

Connect irc-object obj to server, and try to register (PASS USER NICK sequence). Failure to connect results in an error.

Note that there is no nick collision detection yet, so make sure you use a `free' nick.

— Procedure: do-quit obj [#:quit-msg=*quit*]

Send the QUIT command, using quit-msg as quit message.

— Procedure: do-close obj

Close the connection without sending the QUIT command.

— Procedure: do-command obj [#:command] [#:middle] [#:trailing]
— Procedure: do-privmsg obj receiver msg

Send message msg to user or channel receiver.

— Procedure: do-listen obj

Returns a irc-message-object if there is data available, #f otherwise.

— Procedure: do-wait obj

Similar to do-listen but keeps waiting till data is available.

— Procedure: do-join obj chan

Send the JOIN command.

Currently there is no error checking implemented, so a rejected join still shows in the channel list.

— Procedure: do-runloop obj
            (let ([sock (_socket obj)])
              (while (not (port-closed? sock))
                (handle-message obj (do-wait obj))))
— Procedure: do-part obj chan

Leave channel chan.

— Procedure: add-message-hook obj proc [#:tag] [#:append=#f]
— Procedure: add-simple-message-hook! obj proc [#:sender] [#:receiver] [#:command] [#:middle] [#:trailing] [#:tag] [#:append]
— Procedure: exists-message-hook? obj tag

Returns #t if a hook with tag tag exists, #f otherwise.

— Procedure: remove-message-hook! obj tag

Remove the procedure with tag tag from the message-hook of irc-object obj.

— Procedure: run-message-hook obj [args]

Apply all procedures from the message-hook of irc-object obj to the arguments arg .The order of the procedure application is first to last. The return value of this procedure is not specified.

— Procedure: reset-message-hook! obj

Remove all procedures from the message-hook of irc-object obj.

— Procedure: channels->list obj

Return the channels joined by irc-object obj as list.

— Procedure: in-channel? obj chan

Returns #t if channel chan is joined, #f otherwise.

2 Message handling

Messages are parsed according to the 'pseudo' BNF in RFC 1459 (http://www.ietf.org/rfc/rfc1459.txt).

<message> ::=
    [':' <prefix> <SPACE> ] <command> <params> <crlf>
<prefix> ::=
    <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
<command> ::=
    <letter> { <letter> } | <number> <number> <number>
<SPACE> ::=
    ' ' { ' ' }
<params> ::=
    <SPACE> [ ':' <trailing> | <middle> <params> ]
<middle> ::=
    <Any *non-empty* sequence of octets not including SPACE or NUL or CR or LF, the first of which may not be ':'>
<trailing> ::=
    <Any, possibly *empty*, sequence of octets not including NUL or CR or LF>
<crlf> ::=
    CR LF 

2.1 Message API

— Module: (irc message)
— Procedure: parse-message-string msg

Parse the message string msg into an message-object.

— Procedure: make-message [#:command] [#:middle] [#:trailing]

Create a new message-object.

— Procedure: message? obj

Return #t if obj is an message-object, else #f.

— Procedure: prefix msg

Return the prefix part of message-object msg.

Either '(user nick host), server or #f.

— Procedure: prefix-type msg

Returns 'USER if the message was send by a user, 'SERVER if the message was send by a server and #f otherwise.

— Procedure: command msg

Returns either a number or symbol depending on the type of command.

— Procedure: middle msg

Returns the empty string, a string or a list of string.

— Procedure: trailing msg

Returns a string or #f.

— Procedure: time msg

Returns a timestamp as created by (current-time).

2.1.1 Message handling helpers

— Procedure: parse-source msg

Find the source or message-object msg. If the source is found the return value is a string, otherwise it is #f.

— Procedure: parse-target msg

Find out who to send a reply to.

Note that this only works for PRIVMSG and PING commands.

— Procedure: is-channel? str

Test if string str is a valid channel.

— Procedure: message->string msg

Transform message-object msg into a sendable string (i.e. command middle :trailing).