var _ = require('underscore')._, uuid = require('node-uuid'), databank = require('databank'); 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)) { this.userCache[server][nick] = result.id; user = result; } }.bind(this), function(err) { callback(user); }); } }, // 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