picoirc(3tcl)
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:
- a callback procedure
- a nick-name to use on IRC
- 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 inurl, logging in withnickas the username and optionallypassword. Ifurlstarts withircs://then it's a TLS connection, periodt. Thecallbackhas 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 π¨. Ifmessageis 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. Ifchannelis 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 theNAMESirc 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 theWHOIScommand.nickis the user the command was targeted for.infois the dictionary containing detailed information about that user:name,host,channelsanduserinfo.userinfotypically contains the name and version of the user's IRC client. π΅οΈβοΈchat target nick message typeβ called when a message arrives.targetis the identity that the message was targetted for β this can be the logged in nick or a channel name.nickis the name of the sender of the message.messageis the message text.typeis set to"ACTION"if the message was sent as a CTCP ACTION.typeis set to"NOTICE"if the message was sent as aNOTICEcommand β in that casetargetis empty if it matches the current user nick, or it's"*". In the latter case, an emptytargetmeans that notice comes from the server. πmode nick target flagsβ called when the mode of a user or channel changes.nickis the name of the user who requested a change, and can be empty if it's the server.targetis the identity that has its mode changed.flagsare 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.topicis the text of the channel topic.traffic action channel nick ?newnick?β called when users join, leave or change names.actionis eitherentered,leftornickchange, andnickis the user doing the action.newnickis the new name ifactionisnickchange.
β οΈ 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.typeis set toreadwhen reading data, andwriteif the data is to be written.rawis 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 π
chatirc
π 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
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms