2012-12-23 17:19:01 +01:00
|
|
|
/**
|
|
|
|
* Name: Users
|
|
|
|
* Description: Track known users
|
|
|
|
*/
|
|
|
|
var users = function(dbot) {
|
|
|
|
var knownUsers = dbot.db.knownUsers;
|
2012-12-23 18:11:56 +01:00
|
|
|
var getServerUsers = function(event) {
|
|
|
|
if(!knownUsers.hasOwnProperty(event.server)) {
|
2012-12-23 17:19:01 +01:00
|
|
|
knownUsers[event.server] = {};
|
|
|
|
}
|
2012-12-23 18:11:56 +01:00
|
|
|
return knownUsers[event.server];
|
2012-12-23 17:19:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
dbot.instance.addListener('366', 'users', function(event) {
|
2012-12-23 18:11:56 +01:00
|
|
|
var knownUsers = getServerUsers(event);
|
2012-12-23 17:19:01 +01:00
|
|
|
for(var nick in event.channel.nicks) {
|
2012-12-23 18:11:56 +01:00
|
|
|
if(!knownUsers.hasOwnProperty(nick) && event.channel.nicks.hasOwnProperty(nick)) {
|
|
|
|
knownUsers[nick] = {};
|
2012-12-23 17:19:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': 'users',
|
|
|
|
'ignorable': false,
|
|
|
|
|
|
|
|
'listener': function(event) {
|
2012-12-23 18:11:56 +01:00
|
|
|
var knownUsers = getServerUsers(event);
|
|
|
|
if(!knownUsers.hasOwnProperty(event.user)) {
|
|
|
|
knownUsers[event.user] = {};
|
2012-12-23 17:19:01 +01:00
|
|
|
}
|
|
|
|
},
|
2012-12-23 17:46:33 +01:00
|
|
|
'on': 'JOIN',
|
|
|
|
|
|
|
|
'onLoad': function() {
|
|
|
|
// Trigger updateNickLists to stat current users in channel
|
|
|
|
var connections = dbot.instance.connections;
|
|
|
|
for(var conn in connections) {
|
|
|
|
if(connections.hasOwnProperty(conn)) {
|
|
|
|
connections[conn].updateNickLists();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-23 17:19:01 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return users(dbot);
|
|
|
|
};
|