~aleteoryx/tclircc

ref: 7fdaa9361e04b0445c322ca41537ede6fc8bda72 tclircc/doc/md/irc.md -rw-r--r-- 4.5 KiB
7fdaa936Aleteoryx subcommand system 7 days ago

#toc: false

#NAME

irc - Library irc.tcl

#Table Of Contents

#SYNOPSIS

irc::listen on chan
irc::listen off chan
irc::listener add chan ?-thread? patlist script
irc::listener remove chan id

#DESCRIPTION

This is a to-spec IRCv3 client library. It is designed to be freely extracted.

#Getting a channel

"irc.tcl" provides 2 ways to connect to an IRC server.

#irc::connect hostname port ?usetls?

Connects to hostname:port, and sets up all the necessary state. If usetls is set to true, the tls module will be used to connect, instead of the builtin socket command. If unset, socket will be used.

Channel metadata is initialized with proto, hostname, port, and uri set.

#irc::enroll chan ?meta?

Sets up the internal state necessary for chan to be used as an IRC socket. It is called internally by irc::connect. This command is exposed for the use-case where an IRC channel might have a more bespoke acquisition process than a simple socket connection.

meta is the initial state of the channel metadata.

#Listening to it

"irc.tcl" provides an event dispatch system, via a fileevent script registered on the IRC channel. Events are dispatched by matching their patterns against incoming messages.

#irc::listen subcommand chan

Enable or disable the fileevent script for the dispatch system.

  • irc::listen on chan

    Apply the fileevent wrapper to chan. Returns the previous fileevent wrapper.

  • irc::listen off chan

    Remove the fileevent wrapper from chan. Errors if the channel does not currently have the irc handler set.

#irc::listener subcommand chan ?arg...?

Configure listener-type event handlers.

listener-type handlers are scripts, executed in either a sub-interpreter or a seperate thread. Interpreter listeners should yield themselves with after during long operations, and never block for extended periods. If that is infeasible, threaded listeners are recommended.

listener-type scripts are spawned with the variable dispatch set to the channel they are to recieve dispatches over. Each line will be a dict with contents as described in Event Dispatch Contents. Interpreters are given access to the Dispatch-aliased IRC commands, while threads are given the variable parent, the ID of the main thread.

When a listener is removed, it will recieve a message of just end. It should perform necessary cleanup quickly, as the application is likely exiting. Threads may simply thread::release themselves, while interps may call the provided selfdestruct.

  • irc::listener add chan ?-thread? patlist script

    Registers script as a listener-type handler on chan, using patlist as the Message Pattern List. Returns an id that can be passed to irc::listener remove or irc::patlist.

    If -thread is passed, it will be created as a threaded listener, otherwise it will be created in a sub-interpreter.

  • irc::listener remove chan id

    Unregisters the listener identified by id from chan.

    Ignores requests for nonexistent handlers or handlers of the wrong type.

#irc::handler subcommand chan ?arg...?

#irc::is type value

Validation helper.