3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 06:19:24 +01:00

fix profiles. also the fact it was getting all the users onLoad is probably a badthing

This commit is contained in:
reality 2014-09-05 12:06:10 +00:00
parent bea3283b05
commit 64cdd374bc
3 changed files with 22 additions and 28 deletions

View File

@ -14,11 +14,7 @@ var api = function(dbot) {
'id': user.id,
'profile': this.config.schema.profile,
'preferences': this.config.schema.preferences
}, function(err, result){
if(err){
console.log(err);
}
});
}, callback);
}
},
@ -32,11 +28,17 @@ var api = function(dbot) {
if(user){
this.db.read('profiles', user.id, function(err, profile){
if(!err){
callback(false, user, profile);
if(profile) {
callback(false, user, profile);
} else {
this.api.createProfile(user, function(err, profile) {
callback(null, user, profile);
});
}
} else {
callback(true, user, null);
}
});
}.bind(this));
}
else{
callback(true, null, null);
@ -44,10 +46,16 @@ var api = function(dbot) {
}.bind(this));
},
'getProfileByUUID': function(uuid, callback){
this.db.read('profiles', uuid, function(err, profile){
callback(profile);
});
'getProfileByUser': function(user, callback){
this.db.read('profiles', user.id, function(err, profile){
if(profile) {
callback(profile);
} else {
this.api.createProfile(user, function(err, profile) {
callback(profile);
});
}
}.bind(this));
},
'getAllProfiles': function(callback){

View File

@ -5,30 +5,16 @@ var profile = function(dbot) {
this.onLoad = function(){
var schema = this.config.schema;
// Ensure all users have a profile
dbot.api.users.getAllUsers(function(users){
if(users){
_.each(users, function(user){
this.api.getProfileByUUID(user.id, function(err, uuid, profile){
// If function returns an error and uuid, create a new profile
if(err && uuid){
this.api.createProfile(user);
}
}.bind(this));
}.bind(this));
}
}.bind(this));
// Add API Hooks
dbot.api.event.addHook('new_user', this.api.createProfile);
dbot.instance.addPreEmitHook(function(event, callback) {
if(!event.rUser) return callback();
this.api.getProfileByUUID(event.rUser.id, function(uProfile) {
this.api.getProfileByUser(event.rUser, function(uProfile) {
if(uProfile) {
event.rProfile = uProfile.profile;
callback();
}
callback();
}.bind(this));
}.bind(this));

View File

@ -44,7 +44,7 @@ var api = function(dbot) {
}
});
},
// Check if a nick is online under a given alias
'isOnline': function(server, channel, nick, callback) {
this.api.resolveUser(server, nick, function(err, user) {