
UPDATE: PLEASE READ THIS FIRST
Make sure you're using the latest version of this script. That means you need to follow the link to Github, you can't just copy the Gist from the Roll20 forum. Those Gists get cached and can be out of date. The latest version of this script includes everything in a single file so you don't need the two parts described in the first post.
https://gist.github.com/goblinHordes/7424738
This is a little rushed and rough, but ready enough. Standardized API command processing has come up a few times in the last couple of days so I'll throw my hat in the ring. This script uses a stripped down version of Optparse.js to handle options and flags used in an API call. It also offers a method for registering API functions and configuring their options. I don't do any processing on themessage object beside parsing the parameters, the message is forwarded intact if the receiving function wants to do anything with it. I'll probably end up creating some sort of better defined object to wrap all the message details in.
It comes in two parts, the first containing the main functionality. It doesn't depend on the Roll20 API, though it does use the Underscore.js library. There are still a few bugs I'd like to work out (escaped quotes within quoted arguments chief among them, then adding filters for things like Characters - not sure how to keep it decoupled at that point though) but the interface shouldn't change too much.
https://gist.github.com/goblinHordes/7424738
The second part has the on('chat:message') handler - you'd never need to write one again if you use this script. It also has an example of a registered function, apicmd, with a single flag, --echo, that echoes any additional arguments sent to it. This script does rely on the Roll20 API, since it is the glue.
https://gist.github.com/goblinHordes/7424756
Having installed those two scripts, you can define a new API function:
apicmd.on('myFunction', 'describes the myFunction usage', [['-h', '--help', 'displays help for myFunction']], function (msg, args){ if(args.opts.help){ sendChat('API', '/desc Not very helpful, is it?'); } });You could then run this function using !myFunction --help in the chat.