- It has to be used to create a web page
- It has to be able to output a plain string with absolutely nothing else on the page (no html or js or anything) other than that string. Not even an opening html or body tag.
I, of course, am using ColdFusion for my first bot. I'll get into how this framework (and the CFML bot) work after the jump.
I'm not ready to release any code yet, as this might just be good enough to warrant protection and a name for the... can I call it software? Anyway I'm perfectly willing to go over the methodology.
I'm not ready to release any code yet, as this might just be good enough to warrant protection and a name for the... can I call it software? Anyway I'm perfectly willing to go over the methodology.
The framework is written in Perl. I don't actually know a lot of Perl, but somehow I got it working and it only has one bug that I know of!
It's really simple. When you start the framework (I should probably figure out if that's the right word before continuing use) it opens a socket connection to an address on a port. In my case "hubbard.freenode.net" on 6667. It sets its its nick and user and joins a channel; Janebot, Perl Gambot, and #wesnothxp in my case.
Each line it receives is chopped and checked for "PING". It responds to pings with a pong. Otherwise it passes the message in a url parameter to a webpage on my local server. This is where it gets interesting.
After parsing symbols it will make an http request at "http://localhost:8500/Gambot/perlgateway.cfm?msg=$str" where $str would be substituted with the message.
It then sends the contents of that webpage back through the socket connection. This approach offers many advantages.
- Because you've sperated the part that is connecting to the server from the part that processes messages, you don't have to restart the robot to change/add something.
- With just a tiny bit more work you can have easy multi-line output.
- I find web languages to be much simpler, so making them do almost all the work is a huge plus for me.
- You really shouldn't ever have to touch the "framework" after the initial setup. The more pieces of the project you can have that are literally maintenance free, the better.
Speaking of number four and maintenance freeness. That ColdFusion page doesn't actually process messages. Nope. It boils them down a bit. It cuts them into pieces and then by performing various bits of logic on those pieces I create variables such as "eventtype", "sender", "message", "channel". These could have values like "onPrivateMessage","Gambit","Hey there!","#wesnothxp" respectively.
These variables then get passed to another page that handles the actual message processing, and then sends back the output. So this leaves me with two nice files that, together, do about half of the work. They should never require any editing again, and they're separated from the part of the project that will be changing.
Assuming this doesn't become vapor-ware like so many of my other projects, I will release the code here.
0 comments:
Post a Comment