3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00

Rudimentary alias tracking with ~alias command [#73]

This commit is contained in:
reality 2012-12-24 00:42:28 +00:00
parent 6db6c804e5
commit f59c09f9ea

View File

@ -6,7 +6,7 @@ var users = function(dbot) {
var knownUsers = dbot.db.knownUsers; var knownUsers = dbot.db.knownUsers;
var getServerUsers = function(event) { var getServerUsers = function(event) {
if(!knownUsers.hasOwnProperty(event.server)) { if(!knownUsers.hasOwnProperty(event.server)) {
knownUsers[event.server] = {}; knownUsers[event.server] = { 'users': [], 'aliases': {} };
} }
return knownUsers[event.server]; return knownUsers[event.server];
}; };
@ -14,8 +14,9 @@ var users = function(dbot) {
dbot.instance.addListener('366', 'users', function(event) { dbot.instance.addListener('366', 'users', function(event) {
var knownUsers = getServerUsers(event); var knownUsers = getServerUsers(event);
for(var nick in event.channel.nicks) { for(var nick in event.channel.nicks) {
if(!knownUsers.hasOwnProperty(nick) && event.channel.nicks.hasOwnProperty(nick)) { if(!knownUsers.users.include(nick) && !knownUsers.aliases.hasOwnProperty(nick) &&
knownUsers[nick] = {}; event.channel.nicks.hasOwnProperty(nick)) {
knownUsers.users.push(nick);
} }
} }
}); });
@ -24,13 +25,30 @@ var users = function(dbot) {
'name': 'users', 'name': 'users',
'ignorable': false, 'ignorable': false,
'listener': function(event) { 'commands': {
var knownUsers = getServerUsers(event); '~alias': function(event) {
if(!knownUsers.hasOwnProperty(event.user)) { var knownUsers = getServerUsers(event);
knownUsers[event.user] = {}; var alias = event.params[1].trim();
if(knownUsers.aliases.hasOwnProperty(alias)) {
event.reply(alias + ' is an alias of ' + knownUsers.aliases[alias]);
} else {
event.reply(alias + ' is not known as an alias to me.');
}
} }
}, },
'on': 'JOIN',
'listener': function(event) {
var knownUsers = getServerUsers(event);
if(event.action == 'JOIN') {
if(!knownUsers.users.include(event.user)) {
knownUsers.users.push(event.user);
}
} else if(event.action == 'NICK') {
var newNick = event.params.substr(1);
knownUsers.aliases[newNick] = event.user;
}
},
'on': ['JOIN', 'NICK'],
'onLoad': function() { 'onLoad': function() {
// Trigger updateNickLists to stat current users in channel // Trigger updateNickLists to stat current users in channel