From 8ba4db33a7647c9062b796035984c5be683925d5 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 10:15:52 +0000 Subject: [PATCH] some bug fixes --- modules/users/api.js | 4 +++- modules/users/commands.js | 12 +++++++----- modules/users/users.js | 18 +++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index 1e25abb..af6a644 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -1,7 +1,7 @@ var _ = require('underscore')._; var api = function(dbot) { - this.api = { + var api = { // Retrieve a user record given a server and nickname 'resolveUser': function(server, nick, callback) { var id = nick + '.' + server; @@ -62,6 +62,8 @@ var api = function(dbot) { }); } }; + + return api; }; exports.fetch = function(dbot) { diff --git a/modules/users/commands.js b/modules/users/commands.js index 82e2445..2d4cd41 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -1,7 +1,7 @@ var _ = require('underscore')._; var commands = function(dbot) { - this.commands = { + var commands = { '~alias': function(event) { var nick = event.params[1] || event.user; this.api.resolveUser(event.server, nick, function(err, user) { @@ -124,10 +124,12 @@ var commands = function(dbot) { }.bind(this)); } }; - this.commands['~setaliasparent'].access = 'moderator'; - this.commands['~addalias'].access = 'moderator'; - this.commands['~rmalias'].access = 'moderator'; - this.commands['~mergeusers'].access = 'moderator'; + commands['~setaliasparent'].access = 'moderator'; + commands['~addalias'].access = 'moderator'; + commands['~rmalias'].access = 'moderator'; + commands['~mergeusers'].access = 'moderator'; + + return commands; }; exports.fetch = function(dbot) { diff --git a/modules/users/users.js b/modules/users/users.js index 7fae6ca..1cbf32f 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -24,7 +24,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Add new user alias 'createAlias': function(alias, user, callback) { @@ -41,7 +41,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Remove an alias record 'removeAlias': function(server, alias) { @@ -49,7 +49,7 @@ var users = function(dbot) { this.db.del('user_aliases', id, function(err) { callback(err); }); - }, + }.bind(this), // Update current nick of user record 'updateCurrentNick': function(user, newNick, callback) { @@ -62,7 +62,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Merge two user records and aliases 'mergeUsers': function(oldUser, newUser, callback) { @@ -82,7 +82,7 @@ var users = function(dbot) { callback(true); } }); - }, + }.bind(this), // Set a new nick as the parent for a user (so just recreate and merge) 'reparentUser': function(user, newPrimary, callback) { @@ -91,7 +91,7 @@ var users = function(dbot) { callback(err); }); }.bind(this)); - } + }.bind(this) }; /*** Listener ***/ @@ -114,7 +114,7 @@ var users = function(dbot) { this.onLoad = function() { // Create non-existing users and update current nicks - var checkUser = function(done) { + var checkUser = function(event, done) { this.api.resolveUser(event.server, event.user, function(err, user) { if(!user) { this.internalAPI.createUser(event.server, event.user, done); @@ -126,11 +126,11 @@ var users = function(dbot) { } } }.bind(this)); - }; + }.bind(this); dbot.instance.addPreEmitHook(function(event, callback) { if(event.user && _.include(['JOIN', 'PRIVMSG'], event.action)) { - checkUser(function(err, user) { + checkUser(event, function(err, user) { event.rUser = user; callback(null); });