UNPKG

transit-im

Version:

express-like framework for AIM bots creation (ICQ as well)

46 lines (42 loc) 1.2 kB
// Generated by CoffeeScript 1.6.3 (function() { var _; _ = require('underscore'); module.exports = function(options) { if (options == null) { options = {}; } options = _.defaults(options, { greeting: "Here are the commands you may use", helpString: "shows this help", command: "help", property: "autohelp", showOnUnknown: true }); return { install: function(transit) { var handler; handler = function(req, res) { var help, toDescription; toDescription = function(h) { var descr; descr = [h.pattern]; if (h.autohelp) { descr.push(" - "); descr.push(h[options.property]); } return descr.join(""); }; help = [options.greeting + ": "].concat(req.handlers.map(toDescription).filter(_.identity)).join("\n * "); return res.sendBack(help); }; transit.receive(options.command, { autohelp: options.helpString }, handler); if (options.showOnUnknown) { return transit.receive(handler); } } }; }; }).call(this);