Paladox has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/320860

Change subject: Reduce code duplication
......................................................................

Reduce code duplication

Change-Id: Ib8cb22537432e28676b680c63d190592bf8d966b
---
M src/relay.js
1 file changed, 17 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/grrrit 
refs/changes/60/320860/1

diff --git a/src/relay.js b/src/relay.js
index 3d65672..b3ced5c 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -177,10 +177,14 @@
 
     ircClient.whois(from, function(info){
 
-          if (
-              text.indexOf(ircClient.nick + ': ' + 'restart') === 0 &&
-                  (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-          ) {
+          var $irc_nick_restart = text.indexOf(ircClient.nick + ': ' + 
'restart') === 0;
+          var $irc_nick_force_restart = text.indexOf(ircClient.nick + ': ' + 
'nick') === 0;
+          var $irc_nick_nick = text.indexOf(ircClient.nick + ': ' + 'nick') 
=== 0;
+          var $irc_nick_help = text.indexOf(ircClient.nick + ': ' + 'help') 
=== 0;
+          var $irc_nick1 = (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0);
+          var $irc_nick2 = config.nick.indexOf(ircClient.nick) >= 0;
+
+          if ($irc_nick_restart && $irc_nick1) {
               console.log(from + ' => ' + to  + ' ' + text);
 
               logging.info('re-connecting to gerrit..');
@@ -192,16 +196,11 @@
               }
 
               ircClient.say(to, "reconnected to gerrit");
-          } else if (text.indexOf(ircClient.nick + ': ' + 'restart') === 0 &&
-                        !(info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-          ) {
+          } else if ($irc_nick_restart && !$irc_nick1) {
              ircClient.say(to, "Permission is denied.");
           }
 
-          if (
-              text.indexOf(ircClient.nick + ': ' + 'force-restart') === 0 &&
-                  (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-          ) {
+          if ($irc_nick_force_restart && $irc_nick1) {
               console.log(from + ' => ' + to  + ' ' + text);
 
               ircClient.say(to, "re-connecting to gerrit and irc.");
@@ -219,21 +218,17 @@
               logging.info('re-connected to gerrit.');
 
               setTimeout(function(){ ircClient.say(to, "re-connected to gerrit 
and irc."); }, 17000);
-          } else if (text.indexOf(ircClient.nick + ': ' + 'force-restart') === 
0 &&
-                        !(info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-          ) {
+
+              logging.info('re-connected to irc.');
+          } else if ($irc_nick_force_restart && !$irc_nick1) {
              ircClient.say(to, "Permission is denied.");
           }
 
-          var $irc_nick1 = text.indexOf(ircClient.nick + ': ' + 'nick') === 0;
-          var $irc_nick2 = (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0);
-          var $irc_nick3 = config.nick.indexOf(ircClient.nick) >= 0;
-
-          if ($irc_nick1 && $irc_nick2 && $irc_nick3) {
+          if ($irc_nick_nick && $irc_nick1 && $irc_nick2) {
               console.log(from + ' => ' + to  + ' ' + text);
 
               ircClient.say(to, "Nick is already " + ircClient.nick + " not 
changing the nick.");
-          } else if ($irc_nick1 && $irc_nick2) {
+          } else if ($irc_nick_nick && $irc_nick1) {
               console.log(from + ' => ' + to  + ' ' + text);
 
               logging.info('Changing nick');
@@ -244,11 +239,11 @@
                   ircClient.pass(config.password);
               }
               logging.info('changed nick to' + ' ' + config.nick);
-          } else if ($irc_nick1 && !$irc_nick2) {
+          } else if ($irc_nick_nick && !$irc_nick1) {
               ircClient.say(to, "Permission is denied.");
           }
 
-          if (text.indexOf(ircClient.nick + ': ' + 'help') === 0) {
+          if ($irc_nick_help) {
              ircClient.say(to, "My current commands are: " + ircClient.nick + 
": restart" + ", " + ircClient.nick  + ": force-restart" + ", " + " and " + 
ircClient.nick + ": nick");
           }
     });

-- 
To view, visit https://gerrit.wikimedia.org/r/320860
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8cb22537432e28676b680c63d190592bf8d966b
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to