3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 03:33:07 +01:00

Profile onLoad check [#331][Close #398]

This commit is contained in:
Sam Nicholls 2013-04-21 16:10:24 +01:00
parent 3130350f58
commit 0ccd0c6301
3 changed files with 34 additions and 5 deletions

View File

@ -35,7 +35,7 @@ var api = function(dbot) {
callback(false, user, profile);
}
else{
callback(true, null, null);
callback(true, user, null);
}
});
}
@ -45,6 +45,22 @@ var api = function(dbot) {
}.bind(this));
},
'getProfileByUUID': function(uuid, callback){
if(uuid){
this.db.read('profiles', uuid, function(err, profile){
if(!err){
callback(false, uuid, profile);
}
else{
callback(true, uuid, null);
}
});
}
else{
callback(true, null, null);
}
},
'getAllProfiles': function(callback){
var profiles = [];
this.db.scan('profiles', function(profile){

View File

@ -1,6 +1,6 @@
{
"ignorable": false,
"dbType": "memory",
"dbType": "redis",
"help": "https://github.com/reality/depressionbot/blob/master/modules/profile/README.md",
"schema": {
"profile": {

View File

@ -3,14 +3,27 @@ var _ = require('underscore')._;
var profile = function(dbot) {
this.onLoad = function(){
var api = this.api;
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.command.addHook('~setaliasparent', this.api.renameProfile);
dbot.api.event.addHook('new_user', this.api.createProfile);
//TODO(@samstudio8) Profile Merging
//dbot.api.command.addHook('~mergeusers', this.api.mergeProfile);
dbot.api.event.addHook('new_user', this.api.createProfile);
};
};