diff --git a/modules/profile/api.js b/modules/profile/api.js index 2bf7b05..d9ac410 100644 --- a/modules/profile/api.js +++ b/modules/profile/api.js @@ -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){ diff --git a/modules/profile/config.json b/modules/profile/config.json index ce23b0f..9984f3e 100644 --- a/modules/profile/config.json +++ b/modules/profile/config.json @@ -1,6 +1,6 @@ { "ignorable": false, - "dbType": "memory", + "dbType": "redis", "help": "https://github.com/reality/depressionbot/blob/master/modules/profile/README.md", "schema": { "profile": { diff --git a/modules/profile/profile.js b/modules/profile/profile.js index f2fb088..2a28d5c 100644 --- a/modules/profile/profile.js +++ b/modules/profile/profile.js @@ -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); }; };