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
|
// Return a user record given a UUID
|
||||||
'getUser': function(uuid, callback) {
|
'getUser': function(uuid, callback) {
|
||||||
this.db.read('users', uuid, function(err, user) {
|
this.db.read('users', uuid, function(err, user) {
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
"ignorable": false,
|
"ignorable": false,
|
||||||
"dependencies": [ "event" ],
|
"dependencies": [ "event" ],
|
||||||
"dbKeys": [ "knownUsers" ],
|
"dbKeys": [ "knownUsers" ],
|
||||||
"dbType": "redis"
|
"dbType": "memory"
|
||||||
}
|
}
|
||||||
|
@ -185,44 +185,42 @@ var users = function(dbot) {
|
|||||||
dbot.instance.addPreEmitHook(function(event, callback) {
|
dbot.instance.addPreEmitHook(function(event, callback) {
|
||||||
if(event.channel) {
|
if(event.channel) {
|
||||||
this.api.getChannel(event.server, event.channel.name, function(channel) {
|
this.api.getChannel(event.server, event.channel.name, function(channel) {
|
||||||
event.rChannel = channel;
|
if(!channel) {
|
||||||
callback(false);
|
this.internalAPI.createChannel(event.server, event.channel.name, function(channel) {
|
||||||
});
|
event.rChannel = channel;
|
||||||
|
callback(false);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
event.rChannel = channel;
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
dbot.instance.addListener('366', 'users', function(event) {
|
dbot.instance.addListener('366', 'users', function(event) {
|
||||||
var checkChannel = function(channel) {
|
var channel = event.rChannel;
|
||||||
async.eachSeries(_.keys(event.channel.nicks), function(nick, next) {
|
this.api.resolveUsers(event.server, _.keys(event.channel.nicks), function(users, missing) {
|
||||||
var staff = event.channel.nicks[nick];
|
// Create missing users
|
||||||
|
async.each(missing, function(nick, done) {
|
||||||
this.api.resolveUser(event.server, nick, function(user) {
|
this.internalAPI.createUser(event.server, nick, done);
|
||||||
var checkChannelUser = function(user) {
|
}.bind(this), function() {
|
||||||
if(!_.include(channel.users, user.id)) {
|
// Check users
|
||||||
this.internalAPI.addChannelUser(channel, user, staff, next);
|
async.eachSeries(users, function(user, next) {
|
||||||
} else {
|
var staff = event.channel.nicks[user.currentNick];
|
||||||
this.internalAPI.modChannelStaff(channel, user, staff, next);
|
|
||||||
}
|
if(!_.include(channel.users, user.id)) {
|
||||||
}.bind(this);
|
this.internalAPI.addChannelUser(channel, user, staff, next);
|
||||||
|
|
||||||
if(user) {
|
|
||||||
checkChannelUser(user);
|
|
||||||
} else {
|
} else {
|
||||||
this.internalAPI.createUser(event.server, nick, checkChannelUser);
|
this.internalAPI.modChannelStaff(channel, user, staff, next);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this), function(err) {
|
||||||
}.bind(this), function(err) {
|
event.reply('DEBUG: Finished checking ' + event.channel.name);
|
||||||
console.log('finished checking ' + channel);
|
});
|
||||||
});
|
}.bind(this));
|
||||||
}.bind(this);
|
}.bind(this));
|
||||||
|
|
||||||
if(!event.rChannel) {
|
|
||||||
this.internalAPI.createChannel(event.server, event.channel.name, checkChannel);
|
|
||||||
} else {
|
|
||||||
checkChannel(event.rChannel);
|
|
||||||
}
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
_.each(dbot.instance.connections, function(connection) {
|
_.each(dbot.instance.connections, function(connection) {
|
||||||
|
Loading…
Reference in New Issue
Block a user