girc
Version:
IRC Client library
75 lines (60 loc) • 1.87 kB
JavaScript
"use strict";
var User = require('./user');
var utils = require('./utils');
var Channel = module.exports = function (name, connection) {
this.name = name;
this.connection = connection;
this.topic = {};
this.names = {};
};
Channel.prototype.toString = function () {
return this.name;
};
Channel.prototype.getName = function () {
return this.name;
};
Channel.prototype.getTopic = function () {
return this.topic;
};
Channel.prototype.getNames = function () {
return this.names; // {'nick': ['~']}
};
User.prototype.getConnection = function () {
return this.connection;
};
Channel.prototype.userHasMode = function (user, mode) {
user = typeof user === "string" ? user : user.getNick();
if (this.names.hasOwnProperty(user)) {
return this.names[user].indexOf(mode) > -1;
}
return false;
};
Channel.prototype.isUserInChannel = function (user) {
user = typeof user === "string" ? user : user.getNick();
return this.names.hasOwnProperty(user);
};
Channel.prototype.notice = function (msg) {
this.connection.notice(this.getName(), msg);
return this;
};
Channel.prototype.say = function (msg) {
this.connection.send(this.getName(), msg);
return this;
};
Channel.prototype.reply = function (user, msg) {
user = typeof user === "string" ? user : user.getNick();
this.say(user + ': ' + msg);
return this;
};
Channel.prototype.kick = function (user, reason) {
this.connection.kick(this.getName(), user, reason);
return this;
};
Channel.prototype.ban = function (mask) {
this.connection.write('MODE ' + this.getName() + ' +b ' + mask);
return this;
};
Channel.prototype.unban = function (mask) {
this.connection.write('MODE ' + this.getName() + ' -b ' + mask);
return this;
};