Permalink
Browse files

Version updates. See the changelog. All tests passing.

  • Loading branch information...
1 parent 95b049c commit 38de58ea9bbbcd4147a09602773607e06bdd24c1 @Havvy Havvy committed Mar 11, 2013
View
@@ -1,21 +1,21 @@
Interfaces
-IRCCommandHandler implements EventSubscriber, EventEmitter
- parseMessage(IRCMessage)
- emits(single-arbitrary-word, IRCCommand, NRC)
+IrcCommandHandler implements EventSubscriber, EventEmitter
+ parseMessage(IrcMessage)
+ emits(single-arbitrary-word, IrcCommand, NRC)
-IRCCommand
+IrcCommand
get sender
get args
get channel
get name
get isQuery
-IRCMessage
+IrcMessage
get receiver:NRC
Receiver of the message. The NRC object in most cases.
get prefix
- If an IRC message starts with a :, the first word is called the prefix.
+ If an Irc message starts with a :, the first word is called the prefix.
get sender
Sender of the message. Usually a Hostmask.
get type
@@ -32,27 +32,27 @@ Actor
Channel
get channel: String
-IRCUserMessage implements IRCMessage, Actor
-IRCChannelUserMessage implements IRCMessage, Channel, Actor
-IRCChannelMessage implements IRCMessage, Channel
-IRCJoinPartMessage implements IRCChannelUserMessage
+IrcUserMessage implements IrcMessage, Actor
+IrcChannelUserMessage implements IrcMessage, Channel, Actor
+IrcChannelMessage implements IrcMessage, Channel
+IrcJoinPartMessage implements IrcChannelUserMessage
-IRCPrivMsgMessage implements IRCChannelUserMessage
+IrcPrivMsgMessage implements IrcChannelUserMessage
get isQuery: boolean
True if message sent in a query.
-IRCQuitMessage implements IRCUserMessage
+IrcQuitMessage implements IrcUserMessage
get reason: String
-IRCNickMessage implements IRCUserMessage
+IrcNickMessage implements IrcUserMessage
get newNick: String
New nick for the user changing nick.
-IRCChannelNamesMessage implements IRCChannelMessage
+IrcChannelNamesMessage implements IrcChannelMessage
get users: List[String]
List of users in channel.
-NRC implements ModuleSubscriber, ModuleStorage, BiEventSubscriber, ConfigurationStorage, IRCClient
+NRC implements ModuleSubscriber, ModuleStorage, BiEventSubscriber, ConfigurationStorage, IrcOutputClient
ModuleSubscriber
require(Module)
@@ -75,12 +75,15 @@ SimpleReadSocket extends EventSubscriber, EventEmitter
end()
emits('data', String)
-IRCSocket extends SimpleReadSocket
+IrcSocket extends SimpleReadSocket
raw(String)
+ start aliases connect
+ disconnect aliases end
onConnect(Callback[])
onDisconnect(Callback[])
Logger
input
output
error
+ debug
View
@@ -26,6 +26,24 @@ Changelog
+ dependencies(undefined U ModuleExports): List[String] U undefined
* Only the server module works.
+0.4.1:
+ * Added a new test for Message Handlers.
+
+0.4.2: (Unreleased)
+ * Renamed classes.
+ * Added an IrcOutputSocket class. NRC absorbs it of course.
+ * Added everything to the index.
+ * Got Dependency Injection for all non-structure objects.
+ * Added `userhost` method to IrcOutputSocket/NRC.
+
+0.4.3:
+ * Nrc class renamed to Client.
+ * `whois` method added to IrcOutputSocket/Client
+ * Moved startup stuff from IrcMessageHandler to Client.
+ ** Removed config parameter from its constructor. :)
+ * Testing of 'say', 'part', and 'quit' of the IrcOutputSocket.
+ ** Feel free to add more tests!
+
Future:
* Executable tool to start a new NRC bot.
Ex: nrc ./my-server-config.json
@@ -34,5 +52,7 @@ Future:
optional 'modules' field. Absolute or relative URLs to modules that
are required.
* Get modules rewritten properly.
- * Move startup code out of Message Handler. [Why did I put it there?]
- ** Refactor the IRC Socket to be multi-stage.
+ * Refactor the IRC Socket to have a Startup class.
+ * ChunkedMessageParser to chunk MessageParser parsed messagse when
+ applicable.
+ * Whatever is in the Contributors section of readme.md
View
@@ -0,0 +1,57 @@
+/**
+ *
+ * Command Handler
+ *
+ */
+
+var events = require('events');
+var util = require('util');
+
+var Command = require('./structures/command');
+
+/**
+ * ctx: NRC interface
+ */
+var Commander = function (name, config) {
+ events.EventEmitter.call(this);
+ var that = this;
+ this._name = name;
+ this.trigger = config.trigger || "!";
+};
+
+Commander.prototype = new events.EventEmitter();
+Commander.prototype.constructor = Commander;
+
+Commander.prototype.parseMessage = function (msg) {
+ var command = this.getCommandString(msg);
+
+ if (command) {
+ command = Object.freeze(new Command(msg.actor, command,
+ msg. channel, msg.isQuery));
+ this.emit(command.name, command);
+ }
+};
+
+Commander.prototype.getCommandString = function (privmsg) {
+ if (privmsg.message[0] === this.trigger[0]) {
+ return privmsg.message.substr(1);
+ }
+
+ if (privmsg.isQuery) {
+ return privmsg.message;
+ }
+
+ if (privmsg.message.indexOf(this._name()) === 0) {
+ var msg = privmsg.message.substr(privmsg.message.indexOf(" ") + 1);
+
+ if (msg[0] === this.trigger[0]) {
+ return msg.substr(1);
+ } else {
+ return msg;
+ }
+ }
+
+ return false;
+};
+
+module.exports = Commander;
View
@@ -1,28 +1,52 @@
/**
*
- * Command Handler
+ * Command Handlers parse incoming messages and emit commands for valid
+ * command messages. Valid commands are any of the following:
*
+ * 1. Starts with the trigger character.
+ * 2. Starts with the receiver's name as determined by the name function.
+ * 3. Is a private message.
+ *
+ * The constructor takes two arguments:
+ * 1. A no-arg function that returns the name of the receiver
+ * 2. Trigger configuration: Either a one character string or an object with
+ * a property trigger which has a one character string.
*/
+/*
+This needs a unit test suite. But since its only job is to implement an
+interface, maybe I can find an interface test suite?
+*/
+
var events = require('events');
var util = require('util');
var Command = require('./structures/command');
-/**
- * ctx: NRC interface
- */
-var Commander = function (name, config) {
+var CommandParser = function (name, config) {
events.EventEmitter.call(this);
var that = this;
this._name = name;
+
+ switch (typeof config) {
+ case "string":
+ this.trigger = config;
+ break;
+ case "object":
+ this.trigger = (typeof config.trigger === "string" ?
+ config.trigger : '!');
+
+ break;
+ default:
+ this.trigger = '!';
+ }
this.trigger = config.trigger || "!";
};
-Commander.prototype = new events.EventEmitter();
-Commander.prototype.constructor = Commander;
+CommandParser.prototype = new events.EventEmitter();
+CommandParser.prototype.constructor = CommandParser;
-Commander.prototype.parseMessage = function (msg) {
+CommandParser.prototype.parse = function (msg) {
var command = this.getCommandString(msg);
if (command) {
@@ -32,15 +56,8 @@ Commander.prototype.parseMessage = function (msg) {
}
};
-Commander.prototype.getCommandString = function (privmsg) {
- if (privmsg.message[0] === this.trigger[0]) {
- return privmsg.message.substr(1);
- }
-
- if (privmsg.isQuery) {
- return privmsg.message;
- }
-
+// Returns the command string with the name and trigger removed or false.
+CommandParser.prototype.getCommandString = function (privmsg) {
if (privmsg.message.indexOf(this._name()) === 0) {
var msg = privmsg.message.substr(privmsg.message.indexOf(" ") + 1);
@@ -51,7 +68,15 @@ Commander.prototype.getCommandString = function (privmsg) {
}
}
+ if (privmsg.message[0] === this.trigger[0]) {
+ return privmsg.message.substr(1);
+ }
+
+ if (privmsg.isQuery) {
+ return privmsg.message;
+ }
+
return false;
};
-module.exports = Commander;
+module.exports = CommandParser;
View
@@ -1,9 +1,22 @@
-module.exports = {
- NRC : require('./nrc'),
- Message : require('./structures/message'),
- Command : require('./structures/command'),
- Socket : require('./socket'),
- MessageListener : require('./irc-message-emitter'),
- Commander : require('./commander'),
- Modules : require('./modules')
+var index = {
+ NRC : "nrc",
+ nrc : "nrc",
+ Nrc : "nrc",
+ Client: "nrc",
+ Message : 'structures/message',
+ Command : 'structures/command',
+ Hostmask : 'structures/hostmask',
+ Socket : 'socket',
+ OutputSocket : 'output-socket',
+ MessageParser : 'irc-message-emitter',
+ // ChunkedMessageParser: 'chunked-message-parser',
+ CommandParser : 'commander',
+ Modules : 'modules',
+ Bisubscriber : 'bisubscriber'
};
+
+for (var m in index) {
+ index[m] = require('./' + index[m]);
+}
+
+module.exports = index;
View
@@ -1,61 +0,0 @@
-/**
- * This event emitter listens to an IRC Socket, emitting parsed messages.
- * Here are some example messages:
- * join
- * error (when quitting/forced to quit)
- * 005
- *
- * This one also joins all channels and identifies to nickserv.
- * It probably shouldn't...
- *
- * The constructor takes three arguments:
- * IRCSocket - implementing the IRCSocket interface.
- * Config - A data object with the following fields:
- * password
- * nickserv
- * channels
- * (It shouldn't need to know any of these!)
- * IRCClient - An object that abstracts the sending of messages to the socket.
- * Should be - Object that `receives` the message.
- */
-
- var events = require('events');
- var util = require('util');
-
- var Message = require('./structures/message');
-
- var IRCMessageHandler = function (IRCMessageEmitter, config, client) {
- this.nrc = client;
- IRCMessageEmitter.on('data', this._onData.bind(this));
- IRCMessageEmitter.on('ready', this._onReady(config.password, config.nickserv, config.channels).bind(this));
-};
-
-IRCMessageHandler.prototype = new events.EventEmitter();
-IRCMessageHandler.prototype.constructor = IRCMessageHandler;
-
-IRCMessageHandler.prototype._onData = function (raw) {
- var message = Object.freeze(new Message(raw, this.nrc));
- this.emit(message.name, message);
-};
-
-// This should be handled by the Socket.
-IRCMessageHandler.prototype._onReady = function (password, nickserv, channels) {
- var that = this;
- return function () {
- if (password) {
- this.nrc.say(nickserv, "identify " + password);
- }
-
- for (var ix = 0; ix < channels.length; ix++) {
- this.nrc.join(channels[ix]);
- }
-
- that.emit("ready");
- };
-};
-
-IRCMessageHandler.prototype.toString = function () {
- return "[Object IRCMessageHandler]";
-};
-
-module.exports = IRCMessageHandler;
Oops, something went wrong.

0 comments on commit 38de58e

Please sign in to comment.