Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add blacklist and whitelist commands

  • Loading branch information...
commit 6ac185c9e31b7c13bbec8a40f7c078b872f2b5d2 1 parent 87c8ae3
@rehandalal rehandalal authored
Showing with 79 additions and 9 deletions.
  1. +1 −1  auth.js
  2. +11 −0 migrations/2.js
  3. +67 −8 standup-irc.js
View
2  auth.js
@@ -51,7 +51,7 @@ AuthManager.prototype.checkUser = function(nick) {
AuthManager.prototype._askNickserv = function(nick) {
var msg = 'status ' + nick;
- client.say('nickserv', msg);
+ irc_client.say('nickserv', msg);
};
exports.AuthManager = AuthManager;
View
11 migrations/2.js
@@ -0,0 +1,11 @@
+exports.upgrade = function(client) {
+ client.query("CREATE TABLE blacklist (id character varying(100) NOT NULL, " +
+ "blacklisted_by character varying(100), " +
+ "blacklisted_at timestamp with time zone DEFAULT now());");
+ client.query("ALTER TABLE ONLY blacklist ADD CONSTRAINT " +
+ "blacklist_pkey PRIMARY KEY (id);");
+}
+
+exports.downgrade = function(client) {
+ client.query("DROP blacklist");
+}
View
75 standup-irc.js
@@ -23,7 +23,8 @@ var defaults = {
},
pg: {
enabled: false
- }
+ },
+ blacklist: []
};
var existsSync = fs.existsSync || path.existsSync;
@@ -49,9 +50,6 @@ logger = new (winston.Logger)({
transports: transports
});
-// Global authentication manager
-authman = new auth.AuthManager();
-
/********** PG Client **********/
// Check if PG is enabled and if so connect
@@ -68,6 +66,14 @@ if (config.pg.enabled) {
var pg_client = new pg.Client(config.pg.connstring);
pg_client.connect();
}
+
+ if (pg_client) {
+ var query = pg_client.query("SELECT id FROM blacklist");
+
+ query.on('row', function(row) {
+ config.blacklist.push(row.id);
+ });
+ }
}
/********** IRC Client **********/
@@ -77,6 +83,9 @@ irc_client = new irc.Client(config.irc.host, config.irc.nick, {
channels: config.irc.channels
});
+// Global authentication manager
+authman = new auth.AuthManager();
+
// Connected to IRC server
irc_client.on('registered', function(message) {
logger.info('Connected to IRC server.');
@@ -139,6 +148,10 @@ irc_client.on('kick', function(channel, user, by) {
irc_client.on('message', function(user, channel, message) {
var match, nick, targetMessageRegex;
+ if (config.blacklist.indexOf(user) !== -1) {
+ return false;
+ }
+
nick = utils.escapeRegExp(config.irc.realNick);
targetMessageRegex = new RegExp('^' + nick + '[:,]\\s*?(.*)$');
@@ -194,6 +207,36 @@ var commands = {
}
},
+ /* Blacklist a user to ignore their messages */
+ 'blacklist': {
+ help: "Blacklist a user or show a list of blacklisted users.",
+ usage: "[<user>]",
+ func: function(user, channel, message, args) {
+ utils.ifAuthorized(user, channel, function() {
+ var nick = args[0];
+
+ if (nick) {
+ if (config.blacklist.indexOf(nick) === -1) {
+ pg_client.query("INSERT INTO blacklist" +
+ "(id, blacklisted_by) values " +
+ "('" + nick + "', '" + user + "')");
+
+ config.blacklist.push(nick);
+
+ irc_client.action(channel, 'Ignores ' + nick);
+ }
+ } else {
+ if (config.blacklist.length > 0) {
+ irc_client.say(channel, 'Blacklisted users:');
+ irc_client.say(channel, config.blacklist.join(', '));
+ } else {
+ irc_client.say(channel, 'No blacklisted users.');
+ }
+ }
+ });
+ }
+ },
+
/* Every bot loves botsnacks. */
'botsnack': {
func: function(user, channel, message, args) {
@@ -257,8 +300,8 @@ var commands = {
response.once('error', function(code, data) {
data = JSON.parse(data);
if (code === 403) {
- irc_client.say(channel, "You don't have permission to do " +
- "that. Did you post that status?");
+ irc_client.say(channel, "You don't have permission " +
+ " to do that. Did you post that status?");
} else {
var error = "I'm a failure, I couldn't do it.";
if (data.error) {
@@ -402,8 +445,8 @@ var commands = {
response.once('error', function(code, data) {
if (code === 403) {
- irc_client.say(channel, "You don't have permission to do " +
- "that.");
+ irc_client.say(channel, "You don't have " +
+ "permission to do that.");
} else {
var error = "I'm a failure, I couldn't do it.";
if (data.error) {
@@ -417,6 +460,22 @@ var commands = {
}
},
+ 'whitelist': {
+ help: "Whitelist a user.",
+ usage: "<user>",
+ func: function(user, channel, message, args) {
+ utils.ifAuthorized(user, channel, function() {
+ var nick = args[0];
+
+ if (nick) {
+ config.blacklist = _.without(config.blacklist, nick);
+ pg_client.query("DELETE FROM blacklist WHERE id='" + nick + "'");
+ irc_client.say('Will do!');
+ }
+ });
+ }
+ },
+
/* The default action. Return an error. */
'default': {
func: function(user, channel, message) {
Please sign in to comment.
Something went wrong with that request. Please try again.