Add rudimentary users module to track known users in a channel

This commit is contained in:
reality 2012-12-23 16:19:01 +00:00
parent 118c91549d
commit 0f6aadc07b
3 changed files with 48 additions and 1 deletions

2
jsbot

@ -1 +1 @@
Subproject commit 4e5c470a20044416fc1a912b7a3c9ee42be942cb
Subproject commit 00157e15c9f15e8fcb343c924978616bb6315ee7

View File

@ -0,0 +1,3 @@
{
"dbKeys": [ "knownUsers" ]
}

44
modules/users/users.js Normal file
View File

@ -0,0 +1,44 @@
/**
* 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);
}
},
'on': 'JOIN'
};
};
exports.fetch = function(dbot) {
return users(dbot);
};