forked from GitHub/dbot
create resolveUsers and user in users listener, changed logic and automatic channel record creation in jsbot preEmit hook [#537]
This commit is contained in:
parent
bb3d846cad
commit
0e5cfa56fb
@ -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) {
|
||||
|
@ -2,5 +2,5 @@
|
||||
"ignorable": false,
|
||||
"dependencies": [ "event" ],
|
||||
"dbKeys": [ "knownUsers" ],
|
||||
"dbType": "redis"
|
||||
"dbType": "memory"
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user