mirror of
https://github.com/reality/dbot.git
synced 2024-12-26 04:32:37 +01:00
41 lines
1.4 KiB
JavaScript
41 lines
1.4 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();
|
||
|
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();
|
||
|
};
|
||
|
};
|
||
|
|
||
|
exports.fetch = function(dbot) {
|
||
|
return new profile(dbot);
|
||
|
};
|