mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 04:02:39 +01:00
rewrite nick tracking basically, remove a bunch of unused shite [#537]
This commit is contained in:
parent
e04ffa5f25
commit
74558aea20
@ -69,57 +69,6 @@ var users = function(dbot) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
|
||||||
'modChannelStaff': function(channel, user, staff, callback) {
|
|
||||||
var needsUpdating = false;
|
|
||||||
|
|
||||||
if(!channel.op) {
|
|
||||||
channel.op = [];
|
|
||||||
needsUpdating = true;
|
|
||||||
}
|
|
||||||
if(!channel.voice) {
|
|
||||||
channel.voice = [];
|
|
||||||
needsUpdating = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!_.include(channel.op, user.id) && staff.op) {
|
|
||||||
channel.op.push(user.id);
|
|
||||||
needsUpdating = true;
|
|
||||||
} else if(!_.include(channel.voice, user.id) && staff.voice) {
|
|
||||||
channel.voice.push(user.id);
|
|
||||||
needsUpdating = true;
|
|
||||||
} else if(_.include(channel.op, user.id) && !staff.op) {
|
|
||||||
channel.op = _.without(channel.op, user.id);
|
|
||||||
needsUpdating = true;
|
|
||||||
} else if(_.include(channel.voice, user.id) && !staff.voice) {
|
|
||||||
channel.voice = _.without(channel.voice, user.id);
|
|
||||||
needsUpdating = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(needsUpdating) {
|
|
||||||
this.db.save('channel_users', channel.id, channel, function(err) {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}.bind(this),
|
|
||||||
|
|
||||||
'updateChannelPrimaryUser': function(server, oldUser, newUser) {
|
|
||||||
this.db.search('channel_users', { 'server': server }, function(channel) {
|
|
||||||
channel.users = _.without(channel.users, oldUser);
|
|
||||||
if(!_.include(channel.users, newUser)) channel.users.push(newUser);
|
|
||||||
this.db.save('channel_users', channel.id, channel, function(err) {
|
|
||||||
if(err) {
|
|
||||||
// QQ
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}.bind(this), function(err) {
|
|
||||||
if(err) {
|
|
||||||
// QQ
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}.bind(this),
|
|
||||||
|
|
||||||
'mergeChannelUsers': function(oldUser, newUser) {
|
'mergeChannelUsers': function(oldUser, newUser) {
|
||||||
newUser.channels = _.union(oldUser.channels, newUser.channels);
|
newUser.channels = _.union(oldUser.channels, newUser.channels);
|
||||||
_.each(newUser.channels, function(uuid) {
|
_.each(newUser.channels, function(uuid) {
|
||||||
@ -172,61 +121,97 @@ var users = function(dbot) {
|
|||||||
|
|
||||||
this.onLoad = function() {
|
this.onLoad = function() {
|
||||||
dbot.instance.addPreEmitHook(function(event, callback) {
|
dbot.instance.addPreEmitHook(function(event, callback) {
|
||||||
if(event.user) {
|
// 1. Attempt to resolve channel
|
||||||
this.api.resolveUser(event.server, event.user, function(user) {
|
// 2. Create channel if it doesn't exist
|
||||||
event.rUser = user;
|
// 3. Attempt to resolve user
|
||||||
if(event.rUser.currentNick !== event.user) {
|
// 4. Create user if it doesn't exist
|
||||||
event.rUser.currentNick = event.user;
|
// 5. Make sure channel objects are up to date
|
||||||
this.db.save('users', event.rUser.id, event.rUser, callback);
|
// 6. Update staff channel lists
|
||||||
|
|
||||||
|
var checkChannel = function(done) {
|
||||||
|
this.api.resolveChannel(event.server, event.channel.name, function(channel) {
|
||||||
|
if(!channel) {
|
||||||
|
this.internalAPI.createChannel(event.server, event.channel.name, done);
|
||||||
} else {
|
} else {
|
||||||
callback(false);
|
done(channel);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
}.bind(this);
|
||||||
callback(false);
|
var checkUser = function(done) {
|
||||||
}
|
this.api.resolveUser(event.server, event.user, function(user) {
|
||||||
}.bind(this));
|
if(!user) {
|
||||||
|
this.internalAPI.createUser(event.server, event.user, done);
|
||||||
dbot.instance.addPreEmitHook(function(event, callback) {
|
} else {
|
||||||
if(event.channel) {
|
if(event.user != user.currentNick) {
|
||||||
this.api.resolveChannel(event.server, event.channel.name, function(channel) {
|
user.currentNick = event.user;
|
||||||
event.rChannel = channel;
|
this.db.save('users', user.id, user, function() {
|
||||||
callback(false);
|
done(user);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
callback(false);
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
dbot.instance.addListener('366', 'users', function(event) {
|
|
||||||
var checkChannel = function(channel) {
|
|
||||||
async.eachSeries(_.keys(event.channel.nicks), function(nick, next) {
|
|
||||||
var staff = event.channel.nicks[nick];
|
|
||||||
|
|
||||||
this.api.resolveUser(event.server, nick, function(user) {
|
|
||||||
var checkChannelUser = function(user) {
|
|
||||||
if(!_.include(channel.users, user.id)) {
|
|
||||||
this.internalAPI.addChannelUser(channel, user, staff, next);
|
|
||||||
} else {
|
|
||||||
this.internalAPI.modChannelStaff(channel, user, staff, next);
|
|
||||||
}
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
if(user) {
|
|
||||||
checkChannelUser(user);
|
|
||||||
} else {
|
} else {
|
||||||
this.internalAPI.createUser(event.server, nick, checkChannelUser);
|
done(user);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this);
|
||||||
|
var checkChannelUsers = function(done) {
|
||||||
|
var needsUpdating = false;
|
||||||
|
|
||||||
|
if(!_.include(event.rUser.channels, event.rChannel.id)) {
|
||||||
|
event.rUser.channels.push(event.rChannel.id);
|
||||||
|
event.rChannel.users.push(event.rUser.id);
|
||||||
|
needsUpdating = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_.has(event.channel, 'nicks') || !_.has(event.channel.nicks, event.rUser.currentNick)) {
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
var cUser = event.channel.nicks[event.rUser.currentNick];
|
||||||
|
|
||||||
|
if(!_.include(event.rChannel.op, event.rUser.id) && cUser.op) {
|
||||||
|
event.rChannel.op.push(event.rUser.id);
|
||||||
|
needsUpdating = true;
|
||||||
|
} else if(!_.include(event.rChannel.voice, event.rUser.id) && cUser.voice) {
|
||||||
|
event.rChannel.voice.push(event.rUser.id);
|
||||||
|
needsUpdating = true;
|
||||||
|
} else if(_.include(event.rChannel.op, event.rUser.id) && !cUser.op) {
|
||||||
|
event.rChannel.op = _.without(event.rChannel.op, event.rUser.id);
|
||||||
|
needsUpdating = true;
|
||||||
|
} else if(_.include(event.rChannel.voice, event.rUser.id) && !cUser.voice) {
|
||||||
|
event.rChannel.voice = _.without(event.rChannel.voice, event.rUser.id);
|
||||||
|
needsUpdating = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(needsUpdating) {
|
||||||
|
this.db.save('users', event.rUser.id, event.rUser, function() {
|
||||||
|
this.db.save('channel_users', event.rChannel.id, event.rChannel, done);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this), function(err) {
|
} else {
|
||||||
console.log('Finished checking ' + channel.name);
|
done();
|
||||||
});
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
if(!event.rChannel) {
|
if(event.user && event.channel && _.include(['JOIN', 'MODE', 'PRIVMSG'], event.action)) {
|
||||||
this.internalAPI.createChannel(event.server, event.channel.name, checkChannel);
|
checkChannel(function(channel) {
|
||||||
} else {
|
event.rChannel = channel;
|
||||||
checkChannel(event.rChannel);
|
checkUser(function(user) {
|
||||||
|
event.rUser = user;
|
||||||
|
checkChannelUsers(function() {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else if(event.user) {
|
||||||
|
this.api.resolveUser(event.server, event.user, function(user) {
|
||||||
|
if(user) event.rUser = user;
|
||||||
|
if(event.channel) {
|
||||||
|
this.api.resolveChannel(event.server, event.channel.name, function(channel) {
|
||||||
|
if(channel) event.rChannel = channel;
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user