3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00
dbot/modules/profile/commands.js

73 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-04-02 20:37:52 +02:00
var _ = require('underscore')._,
moment = require('moment-timezone');
var commands = function(dbot){
var commands = {
2013-10-23 21:53:14 +02:00
'~get': function(event){
if(event.params[1]){
if(_.has(this.config.schema.profile, event.params[1])){
this.api.getProperty(event.server, event.user, event.params[1], function(reply){
event.reply(reply);
});
2013-06-27 20:43:52 +02:00
} else {
event.reply('Invalid property. Go home.');
}
}
},
2013-10-23 21:53:14 +02:00
'~set': function(event){
2013-01-23 23:55:06 +01:00
if(event.input[1] && event.input[2]){
if(_.has(this.config.schema.profile, event.input[1])){
2015-04-02 20:35:40 +02:00
if(event.input[1] === 'timezone') { // eugh
if(moment.tz.zone(event.input[2]) !== null) {
this.api.setProperty(event.server, event.user, event.input[1], event.input[2], function(reply){
event.reply(reply);
});
} else {
event.reply('Invalid timezone! See the pretty graph here: http://momentjs.com/timezone/');
}
} else {
this.api.setProperty(event.server, event.user, event.input[1], event.input[2], function(reply){
event.reply(reply);
});
}
2013-06-27 20:43:52 +02:00
} else {
event.reply('Invalid property. Go home.');
2013-01-23 20:13:10 +01:00
}
}
2013-01-25 20:57:04 +01:00
},
2013-06-27 20:43:52 +02:00
'~profile': function(event) {
var user = event.params[1] || event.user;
event.reply(dbot.api.web.getUrl('profile/' + event.server + '/' + user));
2015-04-02 20:35:40 +02:00
},
'~time': function(event) {
2016-01-29 23:33:58 +01:00
var target = event.params[1] || event.user;
dbot.api.profile.getProfile(event.server, target, function(err, user, profile) {
2015-04-02 20:35:40 +02:00
if(!err) {
2015-04-02 20:44:37 +02:00
var tz = profile.profile.timezone;
2015-04-02 20:35:40 +02:00
if(tz) {
2016-01-29 23:33:58 +01:00
event.reply('The time for ' + target + ' in ' + tz + ' is ' + moment().tz(tz).format('HH:mm:ss on DD/MM/YYYY'));
2015-04-02 20:35:40 +02:00
} else {
2015-04-02 20:46:42 +02:00
event.reply(user.currentNick + ' needs to set a timezone with "~set timezone x"');
2015-04-02 20:35:40 +02:00
}
} else {
if(!user) {
event.reply('No idea who that is mate');
} else {
2015-04-02 20:46:42 +02:00
event.reply(user.currentNick + ' needs to set a timezone with "~set timezone x"');
2015-04-02 20:35:40 +02:00
}
}
});
2013-06-27 20:43:52 +02:00
}
2013-01-23 23:55:06 +01:00
};
2013-12-29 19:38:24 +01:00
commands['~set'].regex = [/set ([^ ]+) (.+)/, 3];
2013-01-23 23:55:06 +01:00
return commands;
};
exports.fetch = function(dbot){
return commands(dbot);
};