From 45af08b92e12cd5adff2e51c008572b9f1bc777e Mon Sep 17 00:00:00 2001 From: unek Date: Mon, 5 May 2014 13:35:58 +0200 Subject: [PATCH] new faster way of checking if user is identified --- bin/tipbot.js | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/bin/tipbot.js b/bin/tipbot.js index 7d7896c..60ccc14 100644 --- a/bin/tipbot.js +++ b/bin/tipbot.js @@ -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;