Efficiency improvements in users, return of isKnownUser API function [#331]

This commit is contained in:
reality 2013-05-02 18:25:10 +00:00
parent e426f4fae9
commit da5e79ebeb
3 changed files with 37 additions and 15 deletions

View File

@ -93,6 +93,16 @@ var api = function(dbot) {
callback(isOnline);
}
});
},
'isKnownUser': function(server, nick, callback) {
this.api.resolveUser(server, nick, function(isKnown) {
if(isKnown == false) {
callback(false);
} else {
callback(true);
}
});
}
};

View File

@ -5,7 +5,7 @@
"nl": "{alias} is een alias van {user}"
},
"primary": {
"en": "{user} ({currentNick}) is a primary user with {count} aliases, ",
"en": "{user} (currently {currentNick}) is a primary user with {count} aliases, ",
"na'vi": "{user} ({currentNick}) lu txin ulte {count}a stxo lu poru, ",
"nl": "{user} ({currentNick}) is een primaire gebruiker met {count} aliassen, "
},

View File

@ -73,22 +73,34 @@ var users = function(dbot) {
this.listener = function(event) {
if(event.action == 'JOIN' && event.user != dbot.config.name) {
this.api.resolveUser(event.server, event.user, function(user) {
if(!user) { // User does not yet exist
this.internalAPI.createUser(event.server, event.user, event.channel.name, function(result) {
this.internalAPI.addChannelUser(result, event.channel.name, function(err) { });
}.bind(this));
} else {
if(!_.include(user.channels, event.channel.name)) { // User not yet channel user
user.channels.push(event.channel.name);
this.internalAPI.addChannelUser(user, event.channel.name, function(err) { });
}
var needsUpdating = false;
if(!user) { // User does not yet exist
user = {
'id': uuid.v4(),
'primaryNick': event.user,
'currentNick': event.user,
'server': event.server,
'channels': [],
'aliases': []
};
this.internalAPI.addChannelUser(user, event.channel.name, function(err) { });
needsUpdating = true;
}
if(!_.include(user.channels, event.channel.name)) { // User not yet channel user
user.channels.push(event.channel.name);
this.internalAPI.addChannelUser(user, event.channel.name, function(err) { });
needsUpdating = true;
}
if(user.currentNick != event.user) {
user.currentNick = event.user;
this.db.save('users', user.id, user, function(err) {
if(err) {
// QQ
}
});
needsUpdating = true;
}
if(needsUpdating == true) {
this.db.save('users', user.id, user, function(err) { });
}
}.bind(this));
} else if(event.action == 'NICK') {