To extend my introduction to FICS bot writing I decided to share some code.
The mekk.fics library allows one to write asynchronous FICS bots and utilities in Python. I created it mostly by factoring reusable code out of WatchBot sources, polishing it here and there, extending test suite, and documenting.
The code heavily uses Twisted framework and is expected to run within Twisted main loop. So you need to know at least a little bit about Deferreds and inline callbacks.
Is this event-based approach necessary to interface FICS? Of course not, but I believe that it fits the context fairly well, and … that writing some asynchronous code is a good experience for every programmer.
Library status
The library is in no way finished and may never be: it covers only some of FICS commands and notifications, and my plan is rather to extend it on per need basis, than to systematically cover everything FICS does. If you need some currently missing command or event, let me know.
The implemented code should be rather stable – as I said, noticeable parts of it were taken from Watchbot, so experienced a couple of years of continuous work.
Using the library
The code is hosted on bitbucket, clone it from there.
Bugs and improvement suggestions should also be reported using bitbucket issue tracker.
I have not yet released the library to PyPi (so no easy_install mekk.fics
for
now), if this would make your life easier, please let me know.
Example code
How the code based on mekk.fics looks like? I provide a few samples. Here is the simplest one: utility program, which logs to FICS to grab some information:
And more bot-like sample: observing some FICS events, making simple stats out of them, and responding to people's commands.