Merge pull request #222 from SamStudio8/master

Add ~profile command [Close #219]
This commit is contained in:
Sam Nicholls 2013-01-25 11:57:42 -08:00
commit 9a74077b98
3 changed files with 25 additions and 5 deletions

View File

@ -11,8 +11,8 @@ var api = function(dbot) {
if(!_.has(this.profiles, server)){
this.profiles[server] = {};
}
this.profiles[server][primary] = {};
_.defaults(this.profiles[server][primary], this.config.schema);
this.profiles[server][primary.toLowerCase()] = {};
_.defaults(this.profiles[server][primary.toLowerCase()], this.config.schema);
},
/**

View File

@ -5,7 +5,8 @@ var commands = function(dbot){
"~getprop": function(event){
if(event.params[1]){
var res = dbot.db.profiles[event.server][event.user.toLowerCase()].profile[event.params[1]];
var primary = dbot.api.users.resolveUser(event.server, event.user);
var res = dbot.db.profiles[event.server][primary.toLowerCase()].profile[event.params[1]];
if(res){
event.reply(res);
}
@ -18,13 +19,32 @@ var commands = function(dbot){
"~setprop": function(event){
if(event.input[1] && event.input[2]){
if(_.has(this.config.schema.profile, event.input[1])){
dbot.db.profiles[event.server][event.user.toLowerCase()].profile[event.input[1]] = event.input[2];
var primary = dbot.api.users.resolveUser(event.server, event.user);
dbot.db.profiles[event.server][primary.toLowerCase()].profile[event.input[1]] = event.input[2];
event.reply("Property set, maybe?");
}
else{
event.reply("Invalid property. Go home.");
}
}
},
"~profile": function(event){
if(event.params[1]){
var primary = dbot.api.users.resolveUser(event.server, event.params[1]);
if(_.has(dbot.db.profiles[event.server], primary.toLowerCase())){
event.reply("http://"+dbot.config.web.webHost+":"+dbot.config.web.webPort+"/profile/"+event.server+"/"+primary.toLowerCase());
}
else{
event.reply("No profile found for "+event.params[1]);
}
}
else{
event.message = '~profile ' + event.user;
event.action = 'PRIVMSG';
event.params = event.message.split(' ');
dbot.instance.emit(event);
}
}
};
commands['~setprop'].regex = [/~setprop ([^ ]+) (.+)/, 3];

View File

@ -17,5 +17,5 @@
"timezone": null
}
},
"dependencies": [ "quotes", "command" ]
"dependencies": [ "quotes", "users", "command" ]
}