forked from GitHub/dbot
Merge branch 'master' of github.com:reality/depressionbot
This commit is contained in:
commit
e587725322
@ -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];
|
||||
}
|
||||
},
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user