3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00

Merge pull request #238 from SamStudio8/master

Profile onLoad to use own createProfile API [#220]
This commit is contained in:
Luke Slater 2013-01-27 17:39:34 -08:00
commit b4fbc8d258
2 changed files with 22 additions and 21 deletions

View File

@ -8,11 +8,23 @@ var api = function(dbot) {
* If the server does not already exist, create it.
*/
"createProfile": function(server, primary){
var primaryLower = primary.toLowerCase();
if(!_.has(this.profiles, server)){
this.profiles[server] = {};
}
this.profiles[server][primary.toLowerCase()] = {};
_.defaults(this.profiles[server][primary.toLowerCase()], this.config.schema);
if(!_.has(this.profiles[server], primaryLower)){
this.profiles[server][primaryLower] = {
"profile": {},
"preferences": {}
};
this.profiles[server][primaryLower].profile.primary = primary;
}
// Ensure all profiles have the keys specified by config.json
//TODO(samstudio8) Currently only handles "top-level"
_.defaults(this.profiles[server][primaryLower].profile, this.config.schema.profile);
_.defaults(this.profiles[server][primaryLower].preferences, this.config.schema.preferences);
},
/**
@ -25,10 +37,12 @@ var api = function(dbot) {
var profiles = dbot.db.profiles[server];
if(_.has(profiles, alias)){
var primary = dbot.api.users.resolveUser(server, alias, true).toLowerCase();
var primary = dbot.api.users.resolveUser(server, alias, true);
var primaryLower = primary.toLowerCase();
alias = alias.trim().toLowerCase();
profiles[primary] = profiles[alias];
profiles[primaryLower] = profiles[alias];
profiles[primaryLower].profile.primary = primary;
delete profiles[alias];
}
},

View File

@ -9,27 +9,14 @@ var profile = function(dbot) {
* required properties as defined in the configuation.
*/
this.onLoad = function(){
var api = this.api;
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;
_.each(server, function(primary, primaryi){
console.log(primary);
api.createProfile(serverName, primary);
});
});
dbot.save();