mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
record daily last used [#650]
This commit is contained in:
parent
fd0d3829d8
commit
a3fd5e71f3
@ -137,12 +137,23 @@ var users = function(dbot) {
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
var checkUserTime = function(user, done) {
|
||||
if(!_.has(user, 'lastUsed') || (_.has(user, 'lastUsed') && moment(user.lastUsed).diff(moment(user.lastUsed).add(1, day), 'days') > 0)) {
|
||||
dbot.api.log.log('tripsit', 'tripbot', '[USERDEBUG] Updating last used date for ' + user.primaryNick);
|
||||
user.lastUsed = moment().unix();
|
||||
this.db.save('users', user.id, user, done);
|
||||
} else {
|
||||
done(null)
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
dbot.instance.addPreEmitHook(function(event, callback) {
|
||||
if(event.user && _.include(['JOIN', 'PRIVMSG'], event.action)) {
|
||||
checkUser(event, function(err, user) {
|
||||
event.rUser = user;
|
||||
callback(null);
|
||||
checkUserTime(user, function() {
|
||||
event.rUser = user;
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
|
Loading…
Reference in New Issue
Block a user