Compare commits

...

1 Commits

3 changed files with 50 additions and 31 deletions

View File

@ -25,6 +25,27 @@ var api = function(dbot) {
});
},
// Return many user records given primary nicks of aliases
'resolveUsers': function(server, nicks, callback) {
var users = [];
this.db.search('users', { 'server': server }, function(result) {
var pNicks = result.aliases.slice(0).unshift(result.primaryNick);
for(var i=0;i<pNicks.length;i++) {
var n = _.indexOf(nicks, pNicks[i]);
if(n != -1) {
users.push(result);
nicks = _.without(nicks, nicks[n]);
break;
}
}
}, function(err) {
if(!err) {
console.log(nicks);
callback(users, nicks);
}
});
},
// Return a user record given a UUID
'getUser': function(uuid, callback) {
this.db.read('users', uuid, function(err, user) {

View File

@ -2,5 +2,5 @@
"ignorable": false,
"dependencies": [ "event" ],
"dbKeys": [ "knownUsers" ],
"dbType": "redis"
"dbType": "memory"
}

View File

@ -185,44 +185,42 @@ var users = function(dbot) {
dbot.instance.addPreEmitHook(function(event, callback) {
if(event.channel) {
this.api.getChannel(event.server, event.channel.name, function(channel) {
if(!channel) {
this.internalAPI.createChannel(event.server, event.channel.name, function(channel) {
event.rChannel = channel;
callback(false);
});
} else {
event.rChannel = channel;
callback(false);
}
}.bind(this));
} 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];
var channel = event.rChannel;
this.api.resolveUsers(event.server, _.keys(event.channel.nicks), function(users, missing) {
// Create missing users
async.each(missing, function(nick, done) {
this.internalAPI.createUser(event.server, nick, done);
}.bind(this), function() {
// Check users
async.eachSeries(users, function(user, next) {
var staff = event.channel.nicks[user.currentNick];
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 {
this.internalAPI.createUser(event.server, nick, checkChannelUser);
}
}.bind(this));
}.bind(this), function(err) {
console.log('finished checking ' + channel);
event.reply('DEBUG: Finished checking ' + event.channel.name);
});
}.bind(this);
if(!event.rChannel) {
this.internalAPI.createChannel(event.server, event.channel.name, checkChannel);
} else {
checkChannel(event.rChannel);
}
}.bind(this));
}.bind(this));
}.bind(this));
_.each(dbot.instance.connections, function(connection) {