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:
parent
35c59d4c72
commit
903427e1ef
@ -46,6 +46,7 @@ var api = function(dbot) {
|
||||
|
||||
'createTrackedWord': function(word, callback) {
|
||||
var tWord = {
|
||||
'word': word,
|
||||
'total': 0,
|
||||
'channels': {},
|
||||
'users': {},
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user