2012-12-23 17:19:01 +01:00
|
|
|
/**
|
|
|
|
* Name: Users
|
|
|
|
* Description: Track known users
|
|
|
|
*/
|
|
|
|
var users = function(dbot) {
|
|
|
|
var knownUsers = dbot.db.knownUsers;
|
|
|
|
var getChanUsers = function(event) {
|
|
|
|
if(!knownUsers.hasOwnProperty(event.server)) {
|
|
|
|
knownUsers[event.server] = {};
|
|
|
|
}
|
|
|
|
var serverUsers = knownUsers[event.server];
|
|
|
|
|
|
|
|
if(!serverUsers.hasOwnProperty(event.channel.name)) {
|
|
|
|
serverUsers[event.channel.name] = [];
|
|
|
|
}
|
|
|
|
return serverUsers[event.channel.name];
|
|
|
|
};
|
|
|
|
|
|
|
|
dbot.instance.addListener('366', 'users', function(event) {
|
|
|
|
var chanUsers = getChanUsers(event);
|
|
|
|
for(var nick in event.channel.nicks) {
|
|
|
|
if(!chanUsers.include(nick) && event.channel.nicks.hasOwnProperty(nick)) {
|
|
|
|
chanUsers.push(nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': 'users',
|
|
|
|
'ignorable': false,
|
|
|
|
|
|
|
|
'listener': function(event) {
|
|
|
|
var chanusers = getChanUsers(event);
|
|
|
|
if(!chanUsers.include(event.user)) {
|
|
|
|
chanUsers.push(event.user);
|
|
|
|
}
|
|
|
|
},
|
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);
|
|
|
|
};
|