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) { var found = false; if(_.has(this.userCache[server], nick)) { this.api.getUser(this.userCache[server][nick], callback); } else { this.db.search('users', { 'server': server }, function(result) { if(result.primaryNick == nick || _.include(result.aliases, nick)) { this.userCache[server][nick] = result.id; found = true; callback(result); } }.bind(this), function(err) { if(!found) callback(false); }); } }, // 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