var _                  = require('underscore'),
    ClearwingNamespace = require('./clearwingnamespace');

/**
 * @constructor
 * @augments ClearwingNamespace
 */
function Channel(network, name) {
	/** {@link Clearwing} instance */
	this.client = network.client;

	/** {@link Network} instance */
	this.network = network;

	/** {@link User} list */
	this.users = [];

	name = Channel.sanitize(name);

	/**
	 * Lowercase channel name
	 * @private
	 */
	this._name = name.toLowerCase();

	/**
	 * Namespace
	 * @private
	 * @static
	 */
	this._namespace = this.network._namespace.concat({ channel: this._name });

	/* set up data */
	this
		.set('name', name)
		.set('topic', '')
		.set('mode', '')
		.set('joined', false);
}


/**
 * Sanitize channel name
 * @todo Implement RFC-2812 enforcement
 * @param {string} name Channel name
 * @return {string}
 */
Channel.sanitize = function(name) {
	return name.replace(/^([^#+!&])/, '#$1');
};


Channel.prototype = new ClearwingNamespace();
Channel.prototype.constructor = Channel;


/**
 * Lookup a user by name
 * Note: This function will also create a new {@link User} if one is not found
 * @param {string} user User name
 * @return {User}
 */
Channel.prototype.user = function(user) {
	return this.users.filter(function(n) { return n._name == user.toLowerCase(); }).pop() ||
	       this.users[this.users.push(this.network.user(user)) - 1];
};


/**
 * See if a user exists
 * @param {string} user User name
 * @return {bool} True if user exists, false if it does not
 */
Channel.prototype.hasUser = function(user) {
	return !!this.users.filter(function(n) { return n._name == user.toLowerCase(); }).length;
};

module.exports = Channel;

@@ -714,16 +714,271 @@
  false);
+%0A%0A%09var that = this;%0A%09this.network.on('raw:join', function(event) %7B%0A%09%09that.set('joined', true);%0A%09%09that.emit('join', _.clone(event));%0A%09%7D);%0A%0A%09this.network.on('raw:part', function(event) %7B%0A%09%09that.set('joined', false);%0A%09%09that.emit('part', _.clone(event));%0A%09%7D);
 %0A%7D%0A%0A%0A/**
@@ -1910,16 +1910,412 @@
 th;%0A%7D;%0A%0A
+%0A/**%0A * Join channel if we aren't already joined%0A * @return %7Bthis%7D%0A */%0AChannel.prototype.join = function() %7B%0A%09if (!this.get('joined'))%0A%09%09this.network.send('join', this.get('name'));%0A%0A%09return this;%0A%7D;%0A%0A%0A/**%0A * Part channel if we're joined%0A * @return %7Bthis%7D%0A */%0AChannel.prototype.part = function(message) %7B%0A%09if (this.get('joined'))%0A%09%09this.network.send('part', this.get('name'));%0A%0A%09return this;%0A%7D;%0A%0A
 module.e

Add join/part events and methods