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

43 lines
1.3 KiB
JavaScript

var _ = require('underscore')._;
var api = function(dbot) {
var api = {
'resolveUser': function(server, nick, useLowercase) {
var knownUsers = this.getServerUsers(server);
var user = nick;
if(!_.include(knownUsers.users, nick) && _.has(knownUsers.aliases, nick)) {
user = knownUsers.aliases[nick];
}
if(useLowercase) user = user.toLowerCase();
return user;
},
'isKnownUser': function(server, nick) {
var knownUsers = this.getServerUsers(server);
return (_.include(knownUsers.users, nick) || _.has(knownUsers.aliases, nick));
},
'isPrimaryUser': function(server, nick) {
var knownUsers = this.getServerUsers(server);
return _.include(knownUsers.users, nick);
},
'getAliases': function(server, nick) {
var knownUsers = this.getServerUsers(server);
return _.chain(knownUsers.aliases)
.keys()
.filter(function(user) {
return knownUsers.aliases[user] == nick;
}, this)
.value();
}
};
return api;
};
exports.fetch = function(dbot) {
return api(dbot);
};