forked from GitHub/dbot
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
var _ = require('underscore')._;
|
|
|
|
var profile = function(dbot) {
|
|
|
|
this.profiles = dbot.db.profiles;
|
|
|
|
/**
|
|
* Iterate over known user profiles and ensure they contain all the
|
|
* required properties as defined in the configuation.
|
|
*/
|
|
this.onLoad = function(){
|
|
var schema = this.config.schema;
|
|
|
|
// Ensure all known users have a profile
|
|
_.each(dbot.api.users.getAllUsers(), function(server, serverName){
|
|
if(!_.has(dbot.db.profiles, serverName)){
|
|
dbot.db.profiles[serverName] = {}
|
|
}
|
|
_.each(server, function(userName){
|
|
var primary = userName;
|
|
userName = userName.toLowerCase();
|
|
// TODO why isn't this calling the profile create API function
|
|
if(!_.has(dbot.db.profiles[serverName], userName)){
|
|
dbot.db.profiles[serverName][userName] = {
|
|
"profile": {},
|
|
"preferences": {}
|
|
};
|
|
}
|
|
//TODO(samstudio8) Currently only handles "top-level"
|
|
_.defaults(dbot.db.profiles[serverName][userName].profile, schema.profile);
|
|
_.defaults(dbot.db.profiles[serverName][userName].preferences, schema.preferences);
|
|
dbot.db.profiles[serverName][userName].profile.primary = primary;
|
|
});
|
|
});
|
|
dbot.save();
|
|
|
|
// Add API Hooks
|
|
dbot.api.command.addHook('~setaliasparent', this.api.renameProfile);
|
|
dbot.api.command.addHook('~mergeusers', this.api.mergeProfile);
|
|
};
|
|
};
|
|
|
|
exports.fetch = function(dbot) {
|
|
return new profile(dbot);
|
|
};
|