Skip to content

Commit

Permalink
Revert "Make the code more DRY and more flexible using EventEmitter2."
Browse files Browse the repository at this point in the history
This reverts commit 37457e2.
  • Loading branch information
Ben Brown committed Feb 9, 2016
1 parent cf717fe commit ea5c1f1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 199 deletions.
83 changes: 78 additions & 5 deletions lib/CoreBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ var simple_storage = require(__dirname + '/storage/simple_storage.js');
var ConsoleLogger = require(__dirname + '/console_logger.js');
var LogLevels = ConsoleLogger.LogLevels;

var EE = require(__dirname + '/events.js');

function Botkit(configuration) {
var botkit = {
events: {}, // this will hold event handlers
config: {}, // this will hold the configuration
tasks: [],
taskCount: 0,
Expand All @@ -34,6 +33,8 @@ function Botkit(configuration) {
this.sent = [];
this.transcript = [];

this.events = {};

this.vars = {};

this.topics = {};
Expand Down Expand Up @@ -139,7 +140,30 @@ function Botkit(configuration) {
};


EE.extendObject(this, EE.create({newListener : true}));
this.on = function(event, cb) {
botkit.debug('Setting up a handler for', event);
var events = event.split(/\,/g);
for (var e in events) {
if (!this.events[events[e]]) {
this.events[events[e]] = [];
}
this.events[events[e]].push(cb);
}
return this;
};

this.trigger = function(event, data) {
if (this.events[event]) {
for (var e = 0; e < this.events[event].length; e++) {
var res = this.events[event][e].apply(this, data);
if (res === false) {
return;
}
}
} else {
botkit.debug('No handler for ', event);
}
};

// proceed to the next message after waiting for an answer
this.next = function() {
Expand Down Expand Up @@ -391,6 +415,7 @@ function Botkit(configuration) {
this.botkit = botkit;
this.bot = bot;

this.events = {};
this.source_message = message;
this.status = 'active';
this.startTime = new Date();
Expand Down Expand Up @@ -437,7 +462,31 @@ function Botkit(configuration) {

};

EE.extendObject(this, EE.create({newListener : true}));
this.on = function(event, cb) {
botkit.debug('Setting up a handler for', event);
var events = event.split(/\,/g);
for (var e in events) {
if (!this.events[events[e]]) {
this.events[events[e]] = [];
}
this.events[events[e]].push(cb);
}
return this;
};

this.trigger = function(event, data) {
if (this.events[event]) {
for (var e = 0; e < this.events[event].length; e++) {
var res = this.events[event][e].apply(this, data);
if (res === false) {
return;
}
}
} else {
botkit.debug('No handler for ', event);
}
};


this.getResponsesByUser = function() {

Expand Down Expand Up @@ -589,7 +638,31 @@ function Botkit(configuration) {
return this;
};

EE.extendObject(botkit, EE.create({newListener : true}));
botkit.on = function(event, cb) {
botkit.debug('Setting up a handler for', event);
var events = (typeof(event) == 'string') ? event.split(/\,/g) : event;

for (var e in events) {
if (!this.events[events[e]]) {
this.events[events[e]] = [];
}
this.events[events[e]].push(cb);
}
return this;
};

botkit.trigger = function(event, data) {
if (this.events[event]) {
for (var e = 0; e < this.events[event].length; e++) {
var res = this.events[event][e].apply(this, data);
if (res === false) {
return;
}
}
} else {
botkit.debug('No handler for ', event);
}
};

botkit.startConversation = function(bot, message, cb) {
botkit.startTask(bot, message, function(task, convo) {
Expand Down
129 changes: 0 additions & 129 deletions lib/events.js

This file was deleted.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"main": "lib/Botkit.js",
"dependencies": {
"body-parser": "^1.14.2",
"debug": "2.2.0",
"eventemitter2": "0.4.14",
"express": "^4.13.3",
"jfs": "^0.2.6",
"mustache": "^2.2.1",
Expand Down
63 changes: 0 additions & 63 deletions tests/events.js

This file was deleted.

0 comments on commit ea5c1f1

Please sign in to comment.