2013-01-22 21:44:45 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var profile = function(dbot) {
|
|
|
|
|
|
|
|
this.onLoad = function(){
|
|
|
|
var schema = this.config.schema;
|
|
|
|
|
2013-04-21 17:10:24 +02:00
|
|
|
// 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));
|
|
|
|
|
2013-01-25 16:13:12 +01:00
|
|
|
// Add API Hooks
|
2013-04-21 17:10:24 +02:00
|
|
|
dbot.api.event.addHook('new_user', this.api.createProfile);
|
|
|
|
|
2013-10-24 22:31:49 +02:00
|
|
|
dbot.instance.addPreEmitHook(function(event, callback) {
|
|
|
|
if(!event.rUser) return callback();
|
|
|
|
this.api.getProfileByUUID(event.rUser.id, function(uProfile) {
|
|
|
|
if(uProfile) {
|
|
|
|
event.rProfile = uProfile.profile;
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
|
2013-04-20 23:51:36 +02:00
|
|
|
//TODO(@samstudio8) Profile Merging
|
|
|
|
//dbot.api.command.addHook('~mergeusers', this.api.mergeProfile);
|
2013-01-22 21:44:45 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new profile(dbot);
|
|
|
|
};
|