Yardbird - building IRC bots with Django
zork.net
zork.net
----
The code for bucket has a lot of logic that goes like this::
if ($msg =~ GREATBIGHOARYREGEX) {
...
else if ($msg =~ ANOTHERCRAZYREGEX) {
...
And so I thought to myself "Gosh, wouldn't it be great if this had
a dispatch mechanism where you could associate regexes with functions in
some kind of data structure, along with some kind of application data
for context?" Oh hangon, that reminds me of... http://docs.djangoproject.com/en/dev/topics/http/urls/
I've been looking at twisted, which seems to be the system of choice for
writing IRC bots. It's a bit hairy and bureaucratic, unfortunately.
The examples for setting up basic IRC bots are clean enough, but once
you turn the page it's all factories and reactors and aspect-oriented
bragging about how great it is to reduce your code to dozens of
three-line classes. But it gives you that great responsive asynchronous
network library, which is nothing to sneeze at!Django doesn't have any facilities for network protocols or asynchronous coding, because it assumes that apache or some other web server will take care of all that for you. Once this occurred to me, the light really went on: twisted need only provide a sort of "IRC Client Server" model, and dispatch incoming requests to Django code the way apache does!