From 0a4240f3db8559f01dd1fd0ade28ee6a312e76de Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 09:36:57 +0000 Subject: [PATCH] replace users with new modules --- modules/users/api.js | 209 +++++++-------------------- modules/users/commands.js | 269 +++++++++++----------------------- modules/users/newapi.js | 65 --------- modules/users/newcommands.js | 111 -------------- modules/users/newusers.js | 142 ------------------ modules/users/users.js | 273 ++++++++++++----------------------- 6 files changed, 226 insertions(+), 843 deletions(-) delete mode 100644 modules/users/newapi.js delete mode 100644 modules/users/newcommands.js delete mode 100644 modules/users/newusers.js diff --git a/modules/users/api.js b/modules/users/api.js index 00ec82e..86f48be 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -1,172 +1,65 @@ -var _ = require('underscore')._, - uuid = require('node-uuid'), - databank = require('databank'); +var _ = require('underscore')._; var api = function(dbot) { - var escapeRegexen = function(str) { - return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); - }; - - var api = { - // Return a user record given a primary nick or an alias - 'resolveUser': function(server, nick, callback, lc) { - var user = false; - if(lc) nick = nick.toLowerCase(); - if(_.has(this.userCache[server], nick)) { - this.api.getUser(this.userCache[server][nick], callback); - } else { - this.db.search('users', { 'server': server }, function(result) { - if(lc) { - result.primaryNick = result.primaryNick.toLowerCase(); - _.each(result.aliases, function(v, k) { - result.aliases[k] = v.toLowerCase(); - }); - } - - if(result.primaryNick == nick || _.include(result.aliases, nick)) { - user = result; - } - }.bind(this), function(err) { - if(user) { - if(!_.has(this.userCache[server], nick)) { - this.userCache[server][nick] = user.id; - } else if(this.userCache[server][nick] !== user.id) { - this.userCache[server][nick] = user.id; + this.api = { + // Retrieve a user record given a server and nickname + 'resolveUser': function(server, nick, callback) { + var id = nick + '.' + server; + this.api.getUser(id, function(err, result) { + if(!err) { + callback(null, result); + } else { + this.db.read('user_aliases', id, function(err, result) { + if(!err) { + this.api.getUser(result.user, callback); + } else { + callback(true, null); } - } - callback(user); - }.bind(this)); - } - }, - - // Return many user records given primary nicks of aliases - 'resolveUsers': function(server, nicks, callback) { - var users = []; - this.db.search('users', { 'server': server }, function(result) { - var pNicks = result.aliases.slice(0).unshift(result.primaryNick); - for(var i=0;i