So recently I've completed a long time work in progress that I thought I
would share with you all. Some years ago I wrote an IRC bot in GNU awk
for the #awk IRC channel of freenode. I originally intended to build a
psate bin, but I ran into a few stumbling blocks based around awk's lack
of being able to handle signals, not block on reads when data is not
present, so forth...So in the mean time I built out awkbot, bit by bit,
adding simple things like karma counting, factoids, the ability to scan
the awk man and info pages and arbitrary arithmetic to it (using mysql
and a mysql "library" I wrote which pipes to and from mysql client and
uses tempfiles, and bc among other things). Giving her about 10 hours a
year worth of attention, she started to look quite nice.
Then one day I figured out how to do the IPC. I replaced GNU awk's
special co-process and internet filename usage with a general wrapper
around netcat. I built a bootstrap which allocates a tempfile, and
stores the name of it in the awkbot database. I then created a wrapper
script which executes the bootstrap and then invokes awkbot. I created
my wrapper around netcat with the ability to read from an arbitrarily
specified tempfile. Awkbot configures the library and then proceeds to
use it to connect to the IRC server.
Awkpaste, the paste-bin extension then opens connections to the same
database, and when a paste is submitted injects a special non-IRC-
protocol string into the "stream" awkbot gets it's IRC data from,
indicating it should relay a message to the #awk IRC channel to re****t a
paste.
The awkpaste CGI will, given a query string parameter of an id, look up
the paste of the specified key and pipe it through highlight(1) or vim,
depending on how the macros are setup (I should mention for modularity
I've been heavily abusing the C pre-processor).
More about it here:
http://www.blisted.org/wiki/blog/2008/Mar/01/19.53.49.html
The source can be browsed here:
http://www.blisted.org/browser/trunk/awkbot/


|