3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 19:52:36 +01:00

Merge pull request #403 from SamStudio8/database

Profile onLoad check [#331][Close #398]
This commit is contained in:
reality 2013-04-21 08:13:27 -07:00
commit 840f110317
3 changed files with 34 additions and 5 deletions

View File

@ -35,7 +35,7 @@ var api = function(dbot) {
callback(false, user, profile); callback(false, user, profile);
} }
else{ else{
callback(true, null, null); callback(true, user, null);
} }
}); });
} }
@ -45,6 +45,22 @@ var api = function(dbot) {
}.bind(this)); }.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){ 'getAllProfiles': function(callback){
var profiles = []; var profiles = [];
this.db.scan('profiles', function(profile){ this.db.scan('profiles', function(profile){

View File

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

View File

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