Skip to content

Commit

Permalink
Merge pull request #38 from Tennu/actions
Browse files Browse the repository at this point in the history
Lots of little nice things, but also lots of missing tests and documentation.
  • Loading branch information
Havvy committed Jan 20, 2015
2 parents 7712faf + 2215a38 commit 7068a7a
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 480 deletions.
12 changes: 6 additions & 6 deletions src/lib/bisubscriber.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ BiEventSubscriber.prototype = {
_onString : function (type, listener) {
type.split(' ').forEach(function (event) {
if (event[0] === '!') {
this._secondary.on(event.substr(1), listener);
this._secondary.on(event.substr(1).toLowerCase(), listener);
} else {
this._primary.on(event, listener);
this._primary.on(event.toLowerCase(), listener);
}
}.bind(this));
},
Expand All @@ -66,9 +66,9 @@ BiEventSubscriber.prototype = {
_offString : function (type, listener) {
type.split(' ').forEach(function (event) {
if (event[0] === '!') {
this._secondary[this._secondaryOff](event, listener);
this._secondary[this._secondaryOff](event.substr(1).toLowerCase(), listener);
} else {
this._primary[this._primaryOff](event, listener);
this._primary[this._primaryOff](event.toLowerCase(), listener);
}
}.bind(this));
},
Expand All @@ -82,9 +82,9 @@ BiEventSubscriber.prototype = {
_onceString : function (type, listener) {
type.split(' ').forEach(function (event) {
if (event[0] === '!') {
this._secondary.once(event.substr(1), listener);
this._secondary.once(event.substr(1).toLowerCase(), listener);
} else {
this._primary.once(event, listener);
this._primary.once(event.toLowerCase(), listener);
}
}.bind(this));
},
Expand Down
67 changes: 39 additions & 28 deletions src/lib/client.sjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const lodash = require("lodash");
const packagejson = require("../package.json")[""]

// delegate x y -> function () { this.x.y.apply(this.x, arguments); return this; }
macro delegate {
rule { $property:ident $method:ident } => {
function () {
Expand All @@ -10,10 +11,18 @@ macro delegate {
}
}

// delegate_ret x y -> function () { return this.x.y.apply(this.x, arguments); }
macro delegate_ret {
rule { $property:ident $method:ident } => {
function () {
return this . $property . $method . apply (this . $property, arguments);
}
}
}

const defaultFactoryConfiguration = {
"NetSocket" : require("net").Socket,
"IrcSocket" : require("irc-socket"),
"IrcOutputSocket" : require("./output-socket.js"),
"MessageHandler" : require("./message-handler.js"),
"CommandHandler" : require("./command-handler.js"),
"Plugins" : require("tennu-plugins"),
Expand Down Expand Up @@ -81,9 +90,6 @@ const defaultClientConfiguration = {
// the factory function does not use `this`.
client._nickname = di.NicknameTracker(config.nickname, client._messageHandler);

// The output socket wraps the `raw` method of the client._socket.
client._outputSocket = new di.IrcOutputSocket(client._socket, client._messageHandler, client._nickname, client._logger);

// Create the listener to private messages from the IRCMessageEmitter
// The commander will parse these private messages for commands, and
// emit those commands, also parsed.
Expand All @@ -95,16 +101,19 @@ const defaultClientConfiguration = {
client._subscriber = new di.BiSubscriber(client._messageHandler, commandHandler);
client._subscriber.on("privmsg", function (privmsg) { commandHandler.parse(privmsg); });

// And finally, the module system.
// Configure the plugin system.
client._plugins = new di.Plugins("tennu", client);
client._plugins.addHook("handlers", function (module, handlers) {
client._subscriber.on(handlers);
});
client.note("Tennu", "Loading default plugins");
client._plugins.use(["server", "help", "user", "channel", "startup"], __dirname);
client._plugins.use(["server", "action", "help", "user", "channel", "startup"], __dirname);
client.note("Tennu", "Loading your plugins");
client._plugins.use(config.plugins || [], process.cwd());

// Grab a reference to the "action" plugin exports, so that the client
// can delegate the actions to it.
client._actionExports = client.getPlugin("action");

client.out = client._outputSocket;
client.events = client._subscriber;
Expand Down Expand Up @@ -160,34 +169,35 @@ Client.prototype.disconnect = disconnect;
Client.prototype.end = disconnect;

// implements IRC Output Socket
Client.prototype.act = delegate _outputSocket act;
Client.prototype.ctcp = delegate _outputSocket ctcp;
Client.prototype.join = delegate _outputSocket join;
Client.prototype.mode = delegate _outputSocket mode;
Client.prototype.nick = delegate _outputSocket nick;
Client.prototype.notice = delegate _outputSocket notice;
Client.prototype.part = delegate _outputSocket part;
Client.prototype.quit = delegate _outputSocket quit;
Client.prototype.say = delegate _outputSocket say;
Client.prototype.userhost = delegate _outputSocket userhost;
Client.prototype.who = delegate _outputSocket who;
Client.prototype.whois = delegate _outputSocket whois;
Client.prototype.raw = delegate _outputSocket raw;
Client.prototype.rawf = delegate _outputSocket rawf;
Client.prototype.act = delegate_ret _actionExports act;
Client.prototype.ctcp = delegate_ret _actionExports ctcp;
Client.prototype.join = delegate_ret _actionExports join;
Client.prototype.kick = delegate_ret _actionExports kick;
Client.prototype.mode = delegate_ret _actionExports mode;
Client.prototype.nick = delegate_ret _actionExports nick;
Client.prototype.notice = delegate_ret _actionExports notice;
Client.prototype.part = delegate_ret _actionExports part;
Client.prototype.quit = delegate_ret _actionExports quit;
Client.prototype.say = delegate_ret _actionExports say;
Client.prototype.userhost = delegate_ret _actionExports userhost;
Client.prototype.who = delegate_ret _actionExports who;
Client.prototype.whois = delegate_ret _actionExports whois;
Client.prototype.raw = delegate_ret _actionExports raw;
Client.prototype.rawf = delegate_ret _actionExports rawf;

// implements BiSubscriber
Client.prototype.on = delegate _subscriber on;
Client.prototype.once = delegate _subscriber once;
Client.prototype.off = delegate _subscriber off;

// implements PluginSystem
Client.prototype.use = delegate _plugins use;
Client.prototype.getModule = delegate _plugins getPlugin;
Client.prototype.getPlugin = delegate _plugins getPlugin
Client.prototype.getRole = delegate _plugins getRole;
Client.prototype.initializePlugin = delegate _plugins initialize;
Client.prototype.isPluginInitializable = delegate _plugins isInitializable;
Client.prototype.addHook = delegate _plugins addHook;
Client.prototype.use = delegate _plugins use;
Client.prototype.getModule = delegate_ret _plugins getPlugin;
Client.prototype.getPlugin = delegate_ret _plugins getPlugin
Client.prototype.getRole = delegate_ret _plugins getRole;
Client.prototype.initializePlugin = delegate _plugins initialize;
Client.prototype.isPluginInitializable = delegate_ret _plugins isInitializable;
Client.prototype.addHook = delegate _plugins addHook;

// implements Logger
Client.prototype.debug = delegate _logger debug;
Expand All @@ -201,7 +211,8 @@ Client.prototype.emerg = delegate _logger emerg;

Client.prototype.log = function (level) {
const args = Array.prototype.slice.call(arguments, 1);
this[level].apply(this, args);
this._logger[level].apply(this._logger, args);
return this;
};

// Export the factory.
Expand Down
Loading

0 comments on commit 7068a7a

Please sign in to comment.