From 7bcb136e266711f1d5adfd05239f5f72c5e9dce4 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 22 Mar 2013 11:44:27 +0000 Subject: [PATCH] some initial work on users api over to databank [#272] --- modules/users/api.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index 19c62a6..4d13814 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -7,9 +7,21 @@ var api = function(dbot) { var api = { 'resolveUser': function(server, nick, useLowerCase) { - var knownUsers = this.getServerUsers(server); var user = nick; + if(this.api.isPrimaryUser(nick)) { + return user; + } else { + this.db.search('user', { 'server': server }, function(user) { + if(_.include(user.aliases, nick)) user = user.primaryNick; + }.bind(this), function(err) { + if(err instanceof NotImplementedError) { + // QQ + } + }); + return user; + } + /** TODO: Re-add lowercase support if(!useLowerCase) { if(!_.include(knownUsers.users, nick) && _.has(knownUsers.aliases, nick)) { user = knownUsers.aliases[nick]; @@ -34,9 +46,11 @@ var api = function(dbot) { } } return user; + **/ }, 'getRandomChannelUser': function(server, channel) { + this.db.get('channel_users', { '' }) var channelUsers = this.getServerUsers(server).channelUsers[channel]; if(!_.isUndefined(channelUsers)) { return channelUsers[_.random(0, channelUsers.length - 1)]; @@ -46,7 +60,16 @@ var api = function(dbot) { }, 'getServerUsers': function(server) { - return dbot.db.knownUsers[server].users; + var users = []; + this.db.search('user', { 'server': server }, function(user) { + users.push(user.primaryNick); + }.bind(this), function(err) { + if(err instanceof NotImplementedError) { + // QQ + } + }); + + return users; }, 'getAllUsers': function() {