[MediaWiki-commits] [Gerrit] labs...grrrit[master]: Reduce code duplication

2016-11-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Reduce code duplication
..


Reduce code duplication

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

Approvals:
  Paladox: Looks good to me, but someone else must approve
  Zppix: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/relay.js b/src/relay.js
index 3d65672..21daea6 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 + ': ' + 
'force-restart') === 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: merged
Gerrit-Change-Id: Ib8cb22537432e28676b680c63d190592bf8d966b
Gerrit-PatchSet: 2
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: Paladox 
Gerrit-Reviewer: Chad 
Gerrit-Reviewer: Dzahn 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: MarkTraceur 
Gerrit-Reviewer: Merlijn van Deen 
Gerrit-Reviewer: Paladox 
Gerrit-Reviewer: 

[MediaWiki-commits] [Gerrit] labs...grrrit[master]: Reduce code duplication

2016-11-10 Thread Paladox (Code Review)
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 

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


[MediaWiki-commits] [Gerrit] labs...grrrit[master]: Reduce code duplication and also reply to the command nick i...

2016-11-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Reduce code duplication and also reply to the command nick if 
the nick does not need to change
..


Reduce code duplication and also reply to the command nick if the nick does not 
need to change

Change-Id: I42dc790fa6e026b3375f9fa355c709b3fe2bc2b0
---
M src/relay.js
1 file changed, 15 insertions(+), 9 deletions(-)

Approvals:
  Paladox: Looks good to me, approved
  Zppix: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/relay.js b/src/relay.js
index 78a37c3..3d65672 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -225,21 +225,27 @@
  ircClient.say(to, "Permission is denied.");
   }
 
-  if (
-  text.indexOf(ircClient.nick + ': ' + 'nick') === 0 &&
-  (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-  ) {
+  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) {
+  console.log(from + ' => ' + to  + ' ' + text);
+
+  ircClient.say(to, "Nick is already " + ircClient.nick + " not 
changing the nick.");
+  } else if ($irc_nick1 && $irc_nick2) {
   console.log(from + ' => ' + to  + ' ' + text);
 
   logging.info('Changing nick');
 
   ircClient.send('NICK', config.nick);
 
-  logging.info('changed nick to' + config.nick);
-  } else if (text.indexOf(ircClient.nick + ': ' + 'nick') === 0 &&
-  !(info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-  ) {
- ircClient.say(to, "Permission is denied.");
+  if (ircClient.pass) {
+  ircClient.pass(config.password);
+  }
+  logging.info('changed nick to' + ' ' + config.nick);
+  } else if ($irc_nick1 && !$irc_nick2) {
+  ircClient.say(to, "Permission is denied.");
   }
 
   if (text.indexOf(ircClient.nick + ': ' + 'help') === 0) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I42dc790fa6e026b3375f9fa355c709b3fe2bc2b0
Gerrit-PatchSet: 5
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: Paladox 
Gerrit-Reviewer: Merlijn van Deen 
Gerrit-Reviewer: Paladox 
Gerrit-Reviewer: Zppix 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] labs...grrrit[master]: Reduce code duplication and also reply to the command nick i...

2016-11-10 Thread Paladox (Code Review)
Paladox has uploaded a new change for review.

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

Change subject: Reduce code duplication and also reply to the command nick if 
the nick does not need to change
..

Reduce code duplication and also reply to the command nick if the nick does not 
need to change

Change-Id: I42dc790fa6e026b3375f9fa355c709b3fe2bc2b0
---
M src/relay.js
1 file changed, 13 insertions(+), 9 deletions(-)


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

diff --git a/src/relay.js b/src/relay.js
index 78a37c3..e4e7bd8 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -224,22 +224,26 @@
   ) {
  ircClient.say(to, "Permission is denied.");
   }
+ 
+ $irc_nick1 = text.indexOf(ircClient.nick + ': ' + 'nick') === 
0;
+ $irc_nick2 = (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0);
+ $irc_nick3 = config.nick.indexOf(ircClient.nick) >= 0;
 
-  if (
-  text.indexOf(ircClient.nick + ': ' + 'nick') === 0 &&
-  (info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-  ) {
+  if ($irc_nick1 && $irc_nick2 && $irc_nick3) {
+  ircClient.say(to, "Nick is already " + ircClient.nick + " not 
changing the nick.");
+  } else if ($irc_nick1 && $irc_nick2) {
   console.log(from + ' => ' + to  + ' ' + text);
 
   logging.info('Changing nick');
 
   ircClient.send('NICK', config.nick);
 
-  logging.info('changed nick to' + config.nick);
-  } else if (text.indexOf(ircClient.nick + ': ' + 'nick') === 0 &&
-  !(info.host.match(whitelist_cloaks) || 
whitelist_nicks.indexOf(from) >= 0)
-  ) {
- ircClient.say(to, "Permission is denied.");
+  if (ircClient.pass) {
+  ircClient.pass(config.password);
+  }
+  logging.info('changed nick to' + ' ' + config.nick);
+  } else if ($irc_nick1 && !$irc_nick2) {
+  ircClient.say(to, "Permission is denied.");
   }
 
   if (text.indexOf(ircClient.nick + ': ' + 'help') === 0) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I42dc790fa6e026b3375f9fa355c709b3fe2bc2b0
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: Paladox 

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