[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