UNPKG

transit-im

Version:

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

62 lines (56 loc) 1.7 kB
// Generated by CoffeeScript 1.6.3 (function() { var readline, rl, userId; readline = require('readline'); rl = readline.createInterface({ input: process.stdin, output: process.stdout }); userId = 1; module.exports = function(options) { if (options == null) { options = {}; } return { install: function(transit) { return transit.client(this); }, receive: function(callback) { this.callback = callback; }, start: function() { var _this = this; console.log("Command line client supports special commands to emulate IM interaction:\n" + " :uid {id} - changes the current user's ID (ICQ number for example)\n" + " :exit - emulates user goes offline\n"); rl.on('line', function(line) { line = line.trim(); if (line.indexOf(":uid") === 0) { userId = line.split(" ")[1]; console.log("User id changed to " + userId); return rl.prompt(); } else if (line === ':exit') { return _this.callback(userId, { command: "exit" }, function(err) { return rl.prompt(); }); } else { return _this.callback(userId, line, function(err) { if (err) { console.error(err); } if (options.ack) { console.log("OK"); } return rl.prompt(); }); } }); return rl.prompt(); }, sendBack: function(userId, data, cb) { console.log(userId + ": " + data); return cb(); } }; }; }).call(this);