new faster way of checking if user is identified

This commit is contained in:
unek
2014-05-05 13:35:58 +02:00
parent 2f8ccf7ae5
commit 45af08b92e
+6 -24
View File
@@ -75,28 +75,10 @@ var client = new irc.Client(settings.connection.host, settings.login.nickname, {
});
// gets user's login status
irc.Client.prototype.getLoginStatus = function(nickname, callback) {
// request login status
this.say('NickServ', settings.connection.status_command + ' ' + nickname);
// wait for response
var listener = function(from, to, message) {
// proceed only on NickServ's ACC response
var regexp = new RegExp('^(\\S+) ' + settings.connection.status_command + ' (\\d)');
if(from != undefined && from.toLowerCase() == 'nickserv' && regexp.test(message)) {
var match = message.match(regexp);
var user = match[1];
var level = match[2];
// if the right response, call the callback and remove this listener
if(user.toLowerCase() == nickname.toLowerCase()) {
callback(Number(level));
this.removeListener('notice', listener);
}
}
}
this.addListener('notice', listener);
irc.Client.prototype.isIdentified = function(nickname, callback) {
client.whois(nick, function(reply) {
callback(!!reply.account);
});
}
// gets a empty coin address
@@ -167,10 +149,10 @@ client.addListener('message', function(from, channel, message) {
// if not that, message will be undefined for some reason
// todo: find a fix for that
var msg = message;
client.getLoginStatus(from, function(status) {
client.isIdentified(from, function(status) {
var message = msg;
// check if the sending user is logged in (identified) with nickserv
if(status != 3) {
if(!status) {
winston.info('%s tried to use command `%s`, but is not identified.', from, message);
client.say(channel, settings.messages.not_identified.expand({name: from}));
return;