mirror of
https://github.com/reality/dbot.git
synced 2024-12-27 05:02:36 +01:00
fix for nick tracking wrt new jsbot
This commit is contained in:
parent
e22133d685
commit
0d233f69b7
@ -33,10 +33,12 @@ var users = function(dbot) {
|
|||||||
'user': user.id
|
'user': user.id
|
||||||
}, function(err, result) {
|
}, function(err, result) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
dbot.api.event.emit('new_user_alias', [ result, alias ]);
|
|
||||||
user.aliases.push(alias);
|
user.aliases.push(alias);
|
||||||
|
console.log(user);
|
||||||
this.db.save('users', user.id, user, function() {
|
this.db.save('users', user.id, user, function() {
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
|
console.log('created alias');
|
||||||
|
dbot.api.event.emit('new_user_alias', [ result, alias ]);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(true, null);
|
callback(true, null);
|
||||||
@ -106,14 +108,15 @@ var users = function(dbot) {
|
|||||||
// Track nick changes
|
// Track nick changes
|
||||||
this.listener = function(event) {
|
this.listener = function(event) {
|
||||||
// Update current nick
|
// Update current nick
|
||||||
|
console.log(event);
|
||||||
this.api.resolveUser(event.server, event.user, function(err, user) {
|
this.api.resolveUser(event.server, event.user, function(err, user) {
|
||||||
if(user) {
|
if(user) {
|
||||||
this.api.resolveUser(event.server, event.newNick, function(err, eUser) {
|
this.api.resolveUser(event.server, event.message, function(err, eUser) {
|
||||||
if(!eUser) {
|
if(!eUser) {
|
||||||
this.internalAPI.createAlias(event.newNick, user, function(){});
|
this.internalAPI.createAlias(event.message, user, function(){});
|
||||||
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
this.internalAPI.updateCurrentNick(user, event.message, function(){});
|
||||||
} else if(user.id === eUser.id) {
|
} else if(user.id === eUser.id) {
|
||||||
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
this.internalAPI.updateCurrentNick(user, event.message, function(){});
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -140,7 +143,7 @@ var users = function(dbot) {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
var checkUserTime = function(user, done) {
|
var checkUserTime = function(user, done) {
|
||||||
if(!_.has(user, 'lastUsed') || (_.has(user, 'lastUsed') && moment(user.lastUsed).diff(moment(user.lastUsed).add(1, 'day'), 'days') > 0)) {
|
if(user && !_.has(user, 'lastUsed') || (_.has(user, 'lastUsed') && moment(user.lastUsed).diff(moment(user.lastUsed).add(1, 'day'), 'days') > 0)) {
|
||||||
user.lastUsed = moment().unix();
|
user.lastUsed = moment().unix();
|
||||||
this.db.save('users', user.id, user, done);
|
this.db.save('users', user.id, user, done);
|
||||||
} else {
|
} else {
|
||||||
@ -148,6 +151,16 @@ var users = function(dbot) {
|
|||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
dbot.instance.addPreEmitHook(function(event, callback) {
|
||||||
|
if((event.user == 'telegram' || event.user == 'discord') && event.message) {
|
||||||
|
var bit = event.message.split('> ')
|
||||||
|
event.user = bit.shift().replace('<','').replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, '');
|
||||||
|
event.message = bit.join('> ');
|
||||||
|
event.params = event.message.split(' ');
|
||||||
|
}
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
|
||||||
dbot.instance.addPreEmitHook(function(event, callback) {
|
dbot.instance.addPreEmitHook(function(event, callback) {
|
||||||
if(event.user && _.include(['JOIN', 'PRIVMSG', 'QUIT'], event.action)) {
|
if(event.user && _.include(['JOIN', 'PRIVMSG', 'QUIT'], event.action)) {
|
||||||
checkUser(event, function(err, user) {
|
checkUser(event, function(err, user) {
|
||||||
|
Loading…
Reference in New Issue
Block a user