mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 22:39:26 +01:00
Add rudimentary users module to track known users in a channel
This commit is contained in:
parent
118c91549d
commit
0f6aadc07b
2
jsbot
2
jsbot
@ -1 +1 @@
|
||||
Subproject commit 4e5c470a20044416fc1a912b7a3c9ee42be942cb
|
||||
Subproject commit 00157e15c9f15e8fcb343c924978616bb6315ee7
|
3
modules/users/config.json
Normal file
3
modules/users/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"dbKeys": [ "knownUsers" ]
|
||||
}
|
44
modules/users/users.js
Normal file
44
modules/users/users.js
Normal 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);
|
||||
};
|
Loading…
Reference in New Issue
Block a user