picoirc(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

picoirc β€” the cutest lil IRC client you ever did embed πŸ’–

okay bestie, welcome to picoirc, from the tcllib family, sitting pretty at manual section 3tcl ✨ (yes, that's the Simple embeddable IRC interface page, and yes it's exactly as iconic as it sounds).


✨ NAME ✨

picoirc β€” Small and simple embeddable IRC client.

like. it's tiny. it's cute. it does IRC. that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

package require Tcl 8.6 9

package require picoirc ?0.14.0?

::picoirc::connect callback nick ?password? url

::picoirc::post context channel message

πŸ’« DESCRIPTION πŸ’«

So this package hands you a general purpose minimal IRC client that is literally built to be embedded inside other applications. 🫢

All the communication with the parent app happens through one application-provided callback procedure. That's it. That's the whole relationship. And every single connection keeps its own state, so you can hook up multiple servers in a single application instance β€” no cap, multi-server energy fr fr πŸ‘‘

To kick off an IRC connection you gotta call picoirc::connect with three-ish things:

  1. a callback procedure
  2. a nick-name to use on IRC
  3. the IRC URL that describes the connection

and it hands you back a variable name that is the irc connection context. peek the CALLBACK section below for the deets πŸ’…

real talk though β€” this package is a fairly simple IRC client. If you need something with more capability, go investigate the irc package. picoirc is the lowkey chill one, not the everything-bagel one. πŸ₯―

πŸ”₯ COMMANDS πŸ”₯

  • ::picoirc::connect callback nick ?password? url β€” makes a whole new irc connection to the server in url, logging in with nick as the username and optionally password. If url starts with ircs:// then it's a TLS connection, periodt. The callback has to be exactly as specified in CALLBACK. Returns a package-specific variable that you use when calling the other commands in this package.
⚠️ Note: for connecting via TLS the Tcl module tls must already be loaded, otherwise an error is raised. no tls module, no vibes.
# must be loaded for TLS
package require tls
# default arguments
tls::init -autoservername true -command workaround \
    -require 1 -cadir /etc/ssl/certs -tls1 0 -tls1.1 0
# avoid annoying bgerror, errors are already catched internally
proc workaround {state args} {
    if {$state == "verify"} {
        return [lindex $args 3]
    }
}
  • ::picoirc::post context channel message β€” call this to process user input and send it off to the server πŸ“¨. If message is multiline then each line gets processed and sent individually. Also, a whole bunch of commands get recognised when you prefix them with a forward-slash (/) β€” those get converted into IRC command sequences and then sent. If channel is empty then all raw output to the server is handled. The default action is to write the message to the irc socket. BUT before that happens, the callback gets called with "debug write" β€” which lets the application author inspect the raw IRC data and, if they want, return a break error code to halt further processing. That's how an app can override the default send through the callback procedure. slay, customisation πŸŽ€

πŸ¦‹ CALLBACK πŸ¦‹

The callback has to look like this, exactly:

proc Callback {context state args} {
}

where context is the irc context variable name (in case you need to pass it back to a picoirc procedure). And state is one of a number of states, described below πŸ‘‡

  • init β€” called just before the socket is created.
  • connect β€” called once we've connected, before we join any channels.
  • close β€” called when the socket gets closed, before the context is deleted. If an error occurs before we get connected, the only argument will be the socket error message. 😭
  • userlist channel nicklist β€” called to notify the application of an updated userlist. This gets generated when the output of the NAMES irc command is seen. The package collects the entire output β€” which can span a number of output lines from the server β€” and calls this callback when they've all been received. patient queen behavior ✨
  • userinfo nick info β€” called as a response of the WHOIS command. nick is the user the command was targeted for. info is the dictionary containing detailed information about that user: name, host, channels and userinfo. userinfo typically contains the name and version of the user's IRC client. πŸ•΅οΈβ™€οΈ
  • chat target nick message type β€” called when a message arrives. target is the identity that the message was targetted for β€” this can be the logged in nick or a channel name. nick is the name of the sender of the message. message is the message text. type is set to "ACTION" if the message was sent as a CTCP ACTION. type is set to "NOTICE" if the message was sent as a NOTICE command β€” in that case target is empty if it matches the current user nick, or it's "*". In the latter case, an empty target means that notice comes from the server. πŸ’Œ
  • mode nick target flags β€” called when the mode of a user or channel changes. nick is the name of the user who requested a change, and can be empty if it's the server. target is the identity that has its mode changed. flags are the changes in mode.
  • system channel message β€” called when a system message is received.
  • topic channel topic β€” called when the channel topic string is seen. topic is the text of the channel topic.
  • traffic action channel nick ?newnick? β€” called when users join, leave or change names. action is either entered, left or nickchange, and nick is the user doing the action. newnick is the new name if action is nickchange.
⚠️ NOTE: channel is often empty for these messages, because nick activities are global for the irc server. You will have to manage the nick for all connected channels yourself. it's giving homework, but it's giving necessary homework πŸ“š
  • version β€” this is called to request a version string to use to override the internal version. If implemented, you should return a colon delimited string like:
Appname:Appversion:LibraryVersion

For example, the default is:

PicoIRC:[package provide picoirc]:Tcl [info patchlevel]
  • debug type raw β€” called when data is either being read or written to the network socket. type is set to read when reading data, and write if the data is to be written. raw is the unprocessed IRC protocol data. πŸ‘€

In both cases the application can return a break error code to interrupt further processing of the raw data. If it's a read operation then the package will not handle this line. If the operation is write then the package will not send the data. This callback is intended for debugging protocol issues, but it could be used to redirect all input and output if you desired. main character debugging energy πŸ’…


🌈 SEE ALSO 🌈

  • rfc 1459

πŸ’œ KEYWORDS πŸ’œ

  • chat
  • irc

πŸ‘‘ CATEGORY πŸ‘‘

  • Networking

okay that's the whole page bestie, go build something adorable with it 🧚 and hey β€” this lil beauty ships with tcllib, version 0.14.0, on the picoirc(3tcl) page. mwah, love u, bye πŸ’–πŸ“

πŸ“¦ where this page comes from