3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00

add word to the actual record

This commit is contained in:
reality 2013-10-22 14:25:53 +00:00
parent 35c59d4c72
commit 903427e1ef
2 changed files with 31 additions and 0 deletions

View File

@ -46,6 +46,7 @@ var api = function(dbot) {
'createTrackedWord': function(word, callback) {
var tWord = {
'word': word,
'total': 0,
'channels': {},
'users': {},

View File

@ -171,6 +171,36 @@ var sstats = function(dbot) {
}
}.bind(this));
}.bind(this));
dbot.api.event.addHook('~mergeusers', function(server, oldUser, newUser) {
this.api.getUserStats(oldUser.id, function(ouStats) {
this.api.getUserStats(newUser.id, function(nuStats) {
_.each(ouStats, function(stat, key) {
if(_.isObject(stat) && key != 'creation') {
_.each(ouStats[key], function(stat, sKey) {
nuStats[key][sKey] += stat;
});
} else {
nuStats[key] += stat;
}
});
this.db.del('user_stats', oldUser.id, function() {});
this.db.save('user_stats', newUser.id, function() {});
});
});
this.db.scan('tracked_words', function(tWord) {
if(_.has(tWord.users, oldUser.id)) {
if(_.has(tWord.users, newUser.id)) {
tWord.users[newUser.id] += tWord.users[oldUser.id];
} else {
tWord.users[newUser.id] = tWord.users[oldUser.id];
}
delete tWord.users[oldUser.id];
this.db.save('tracked_words', tWord.word, tWord, function() {});
}
});
}.bind(this));
}.bind(this);
};