sigildocs

(sigil irc)

(sigil irc) - IRC Client Library

A complete IRC client library with TLS support, SASL authentication, and cooperative non-blocking I/O for concurrent applications.

Quick Start

(import (sigil irc))

(define conn (make-irc-connection
               server: "irc.libera.chat"
               port: 6697
               nick: "mybot"
               tls: #t))

(irc-on conn 'PRIVMSG
  (lambda (msg)
    (display (irc-message-nick msg))
    (display ": ")
    (display (irc-message-text msg))
    (newline)))

(irc-connect conn)
(irc-join conn "#mychannel")
(irc-run conn)

With SASL Authentication

(define conn (make-irc-connection
               server: "irc.libera.chat"
               port: 6697
               nick: "mybot"
               tls: #t
               sasl-username: "mybot"
               sasl-password: "secret"))

Integration with HTTP Server

(let loop ()
  (let* ((irc-sock (irc-connection-socket conn))
         (http-sock server-socket)
         (ready (socket-select (list irc-sock http-sock) '() 100)))
    (when (memq irc-sock (car ready))
      (irc-process-input conn))
    (when (memq http-sock (car ready))
      (handle-http-client))
    (loop)))

Exports

irc-messageprocedure

Construct a irc-message struct.

Re-exported from (sigil irc message)

irc-message?procedure

Test if a value is a irc-message struct.

Re-exported from (sigil irc message)

Get the raw field of a irc-message struct.

Re-exported from (sigil irc message)

Get the prefix field of a irc-message struct.

Re-exported from (sigil irc message)

Get the nick field of a irc-message struct.

Re-exported from (sigil irc message)

Get the user field of a irc-message struct.

Re-exported from (sigil irc message)

Get the host field of a irc-message struct.

Re-exported from (sigil irc message)

Get the command field of a irc-message struct.

Re-exported from (sigil irc message)

Get the params field of a irc-message struct.

Re-exported from (sigil irc message)

Get the trailing field of a irc-message struct.

Re-exported from (sigil irc message)

Get the target of a message (first param, usually channel or nick).

For PRIVMSG, JOIN, PART, etc., this is the channel or user.

(irc-message-target msg)  ; => "#channel" or "nickname"

Re-exported from (sigil irc message)

Get the text content of a message (alias for trailing).

(irc-message-text msg)  ; => "Hello world"

Re-exported from (sigil irc message)

Parse a raw IRC message line into an irc-message record.

Returns an irc-message record, or #f if parsing fails.

(parse-irc-message ":nick!user@host PRIVMSG #chan :Hello")
; => #<irc-message nick: "nick" command: PRIVMSG ...>

Re-exported from (sigil irc message)

Create an IRC command string from parts.

(make-irc-command "PRIVMSG" "#channel" "Hello world")
; => "PRIVMSG #channel :Hello world"

Re-exported from (sigil irc message)

Convert an IRC command to a wire-format string (with CRLF).

(irc-command->string "PRIVMSG" "#channel" "Hello")
; => "PRIVMSG #channel :Hello\r\n"

Re-exported from (sigil irc message)

Construct a irc-connection struct.

Re-exported from (sigil irc connection)

Create a new IRC connection (does not connect yet).

Options: server: - IRC server hostname (required) port: - Port number (default: 6667, or 6697 for TLS) nick: - Nickname (required) user: - Username (default: same as nick) realname: - Real name (default: "") tls: - Use TLS (default: #f) sasl-username: - SASL username (optional) sasl-password: - SASL password (optional)

(make-irc-connection
  server: "irc.libera.chat"
  port: 6697
  nick: "mybot"
  tls: #t)

Re-exported from (sigil irc connection)

Test if a value is a irc-connection struct.

Re-exported from (sigil irc connection)

Get the server field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the port field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the nick field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the user field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the realname field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the tls? field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the state field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the socket field of a irc-connection struct.

Re-exported from (sigil irc connection)

Get the current-nick field of a irc-connection struct.

Re-exported from (sigil irc connection)

irc-connectprocedure

Connect to the IRC server.

Establishes the connection, performs TLS handshake if enabled, and begins IRC registration (NICK/USER or CAP/SASL).

Returns #t on success, #f on failure.

Re-exported from (sigil irc connection)

Disconnect from the IRC server.

Optionally sends a QUIT message before closing.

Re-exported from (sigil irc connection)

Check if connection is in connected state.

Re-exported from (sigil irc connection)

Register a handler for all incoming messages.

The handler receives an irc-message record.

(irc-on-message conn
  (lambda (msg)
    (display (irc-message-command msg))
    (newline)))

Re-exported from (sigil irc connection)

irc-onprocedure

Register a handler for a specific IRC command.

(irc-on conn 'PRIVMSG
  (lambda (msg)
    (display (irc-message-text msg))))

Re-exported from (sigil irc connection)

irc-send-rawprocedure

Send a raw IRC command (must include trailing CRLF).

Re-exported from (sigil irc connection)

Process available input from the IRC connection.

Reads data from the socket, parses complete lines, and dispatches messages to handlers. Call this when socket-select indicates the connection is readable.

Returns #t if connection is still alive, #f if disconnected.

Re-exported from (sigil irc connection)

irc-privmsgprocedure

Send a PRIVMSG to a channel or user.

Re-exported from (sigil irc connection)

irc-noticeprocedure

Send a NOTICE to a channel or user.

Re-exported from (sigil irc connection)

irc-joinprocedure

Join a channel.

Re-exported from (sigil irc connection)

irc-partprocedure

Leave a channel.

Re-exported from (sigil irc connection)

irc-quitprocedure

Send QUIT and disconnect.

Re-exported from (sigil irc connection)

irc-nickprocedure

Change nickname.

Re-exported from (sigil irc connection)

irc-modeprocedure

Set mode.

Re-exported from (sigil irc connection)

Identify with NickServ.

Can be called with just password (uses current nick) or with nick and password (for grouped nicks).

Re-exported from (sigil irc connection)

irc-runprocedure

Run the IRC connection event loop.

Processes messages until disconnected. When running inside a channel-run context, cooperates with other tasks via await-readable. Otherwise blocks in a traditional event loop.

Re-exported from (sigil irc connection)

irc-tickprocedure

Process one tick of the IRC connection (non-blocking).

Checks if data is available and processes it. Returns #t if connection is alive, #f if disconnected.

Re-exported from (sigil irc connection)