summaryrefslogtreecommitdiff
path: root/dynobot-irc.js
diff options
context:
space:
mode:
Diffstat (limited to 'dynobot-irc.js')
-rw-r--r--dynobot-irc.js53
1 files changed, 36 insertions, 17 deletions
diff --git a/dynobot-irc.js b/dynobot-irc.js
index 9cae258..a942883 100644
--- a/dynobot-irc.js
+++ b/dynobot-irc.js
@@ -1,14 +1,15 @@
require('tinycolor');
var Channel = require('dynobot/channel.js');
-var cmdopt = require('cmdopt')
-var cp = require('child_process');
var EventEmitter = require('events').EventEmitter;
var FakeSocket = require('./FakeSocket.js');
var IrcClient = require('./irc-client').IrcClient;
-var os = require('os')
-var _ = require('underscore');
var Service = require('dynobot/service.js');
+var _ = require('underscore');
+var cmdopt = require('cmdopt')
+var cp = require('child_process');
+var os = require('os')
var util = require('util');
+var watchTree = require("fs-watch-tree").watchTree;
var parser = new cmdopt.Parser();
parser.option("-h, --help", "Show this help");
@@ -82,35 +83,53 @@ var ircService = new Service('irc', irc);
irc.setDebugLevel(3);
-function Plugin(name, script) {
- this.name = name;
- this.script = script;
+function Plugin(dir, config) {
+ this.dir = dir;
+ this.config = config;
this.channel = undefined;
+// this.watch = undefined;
+
+ // TODO: Resolve plugin.script. Dir is relative to the plugin's
+ // installation directory.
+ this.script = 'index.js';
}
-var plugins = [
-// new Plugin('echo', './echo-bot/index.js')
- new Plugin('atom', './atom-bot/index.js')
-];
+Plugin.prototype.start = function(name) {
+ info('Starting ' + name);
-_.each(plugins, function(plugin) {
- info('Starting ' + plugin.name);
- // TODO: Resolve plugin.script
// TODO: set cwd option to the plugin's directory.
var args = [];
var options = {
- silent: true
+ silent: true,
+ cwd: this.dir
};
- var child = cp.fork(plugin.script, args, options);
+ var child = cp.fork(this.script, args, options);
var channel = new Channel(child);
ircService.handle(channel);
child.on('exit', function() {
- info(plugin.name + ' exited..');
+ info(name + ' exited..');
ircService.release(channel);
channel.close();
});
// TODO: set up consumers for child.stdout and color it before
// piping to process.stdout
+
+// this.watch = watchTree(this.dir);
+ info(name + ' started..');
+}
+
+Plugin.prototype.stop = function(name) {
+ log("Stooping pulugin " + name);
+// this.watch && this.watch.end();
+}
+
+var plugins = {
+// new Plugin('echo', './echo-bot')
+ atom: new Plugin('./atom-bot')
+};
+
+_.each(plugins, function(plugin, name) {
+ plugin.start(name);
});
irc.join(config.channel, function(name) {