UNPKG

transit-im

Version:

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

72 lines (52 loc) 1.76 kB
// Generated by CoffeeScript 1.6.3 (function() { var IcqSession, app, transit; transit = require('transit-im'); app = transit(); IcqSession = (function() { function IcqSession(userId) { this.userId = userId; console.log("" + this.userId + " connected"); } IcqSession.prototype.getName = function() { var _ref; return (_ref = this.name) != null ? _ref : "Unknown user " + this.userId; }; IcqSession.prototype.setName = function(name) { this.name = name; }; IcqSession.prototype.close = function() { return console.log("" + this.userId + " disconnected"); }; return IcqSession; })(); app.use(transit.icq({ login: "__ICQ_NUMBER__", password: "__PASSWORD__" })); app.use(transit.html2txt()); app.use(transit.commandParser()); app.use(transit.sessions({ sessionClass: IcqSession })); app.formatOutput(transit.chain(transit.chain.splitByPortions(500), transit.chain.wrapHtml())); app.use(transit.autohelp()); app.receive('hello', function(req, res) { return res.sendBack("Hello " + (req.session.getName())); }); app.receive('callme {name}', function(req, res) { req.session.setName(req.attrs.name); return res.sendBack("I'll remember that, " + req.attrs.name); }); app.receive('bottles {count}', function(req, res) { var _i, _ref, _results; return res.sendBack(((function() { _results = []; for (var _i = _ref = req.attrs.count; _ref <= 1 ? _i <= 1 : _i >= 1; _ref <= 1 ? _i++ : _i--){ _results.push(_i); } return _results; }).apply(this).map(function(n) { return "I have " + n + " bottles of beer. Let's drink one!"; })).join("\n")); }); app.start(); }).call(this);