Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added cli. Added state object. Things broke maybe?

  • Loading branch information...
commit ffa2bb928176abe23ca53b1433408072727b99e3 1 parent c7e11af
Christopher Joel authored
View
30 lib/adapter/cli.js
@@ -0,0 +1,30 @@
+var events = require('events');
+
+function createCLI(prefix) {
+
+ var eventer = new events.EventEmitter(),
+ prompt = function() {
+
+ process.stdout.write(prefix + ' ');
+ };
+
+ process.stdin.resume();
+ process.stdin.setEncoding('utf8');
+
+ process.stdin.on(
+ 'data',
+ function(chunk) {
+
+ eventer.emit('input', chunk);
+ prompt();
+ }
+ );
+
+ prompt();
+
+ return eventer;
+}
+
+exports.createCLI = createCLI;
+
+
View
34 lib/adapter/index.js
@@ -1,7 +1,8 @@
var events = require('events'),
child = require('child_process'),
path = require('path'),
- log = require('../log');
+ log = require('../log'),
+ cli = require('./cli');
function watch(name, process) {
@@ -43,6 +44,37 @@ exports.createAdapter = function(type, options) {
switch(type) {
default:
+ case 'repl':
+
+ (function() {
+
+ var repl = cli.createCLI('[ YOU ]');
+
+ repl.on(
+ 'input',
+ function(message) {
+
+ eventer.emit(
+ 'message',
+ {
+ body: message,
+ sender: {
+ name: "my subconscious",
+ handle: "subconscious"
+ },
+ chat: {
+ id: "repl",
+ private: true,
+ userCount: 2
+ }
+ }
+ );
+ }
+ );
+
+ })()
+
+ break;
case 'skype':
(function() {
View
14 lib/bridge.js
@@ -49,6 +49,20 @@ exports.createBridge = function() {
bridge = adapter.createAdapter(argv.bridge, { account: argv.u, secret: argv.p, port: argv.port || 1337 });
bridge.on('dead', function() { /* TODO: Attempt to restart.. */ });
+ bridge.on('message', function(message) {
+ eventer.emit(
+ 'message',
+ new Message(
+ {
+ send: function(response) {
+
+ console.log(response.body);
+ }
+ },
+ message
+ )
+ )
+ });
}
return eventer;
View
8 lib/index.js
@@ -3,8 +3,12 @@ var log = require('./log'),
exports = module.exports = function() {
- var handlers = Array.prototype.slice.call(arguments),
- interface = bridge.createBridge();
+ var interface = bridge.createBridge(),
+ handlers = [],
+ bot = {};
+
+ for(var index = 0; index < arguments.length; index++)
+ handlers.push(arguments[index](bot));
interface.on(
'message',
Please sign in to comment.
Something went wrong with that request. Please try again.