Alex Monk has uploaded a new change for review.

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

Change subject: Simplify command handling section
......................................................................

Simplify command handling section

Change-Id: I2871437dac136130365089dfbefab27c47f747f7
---
M src/relay.js
1 file changed, 44 insertions(+), 42 deletions(-)


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

diff --git a/src/relay.js b/src/relay.js
index 2c51552..c534981 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -171,69 +171,71 @@
 
     ircClient.whois(from, function(info){
         try {
-            var command_restart = text.indexOf(ircClient.nick + ': ' + 
'restart') === 0;
-            var command_force_restart = text.indexOf(ircClient.nick + ': ' + 
'force-restart') === 0;
-            var command_nick = text.indexOf(ircClient.nick + ': ' + 'nick') 
=== 0;
             var from_trusted = info.host ? info.host.match(whitelist_cloaks) : 
false;
-            var using_intended_nick = config.nick.indexOf(ircClient.nick) === 
0;
 
-            if (command_restart && from_trusted) {
-                console.log(from + ' => ' + to  + ' ' + text);
+            if (text.indexOf(ircClient.nick + ': ' + 'restart') === 0) {
+                if (from_trusted) {
+                    console.log(from + ' => ' + to  + ' ' + text);
 
-                logging.info('re-connecting to gerrit..');
+                    logging.info('re-connecting to gerrit..');
 
-                ircClient.say(to, "re-connecting to gerrit");
+                    ircClient.say(to, "re-connecting to gerrit");
 
-                if (sshConn) {
-                    sshConn.end();
+                    if (sshConn) {
+                        sshConn.end();
+                    }
+
+                    ircClient.say(to, "reconnected to gerrit");
+                } else {
+                    ircClient.say(to, "Permission is denied.");
                 }
-
-                ircClient.say(to, "reconnected to gerrit");
-            } else if (command_restart && !from_trusted) {
-               ircClient.say(to, "Permission is denied.");
             }
 
-            if (command_force_restart && from_trusted) {
-                console.log(from + ' => ' + to  + ' ' + text);
+            if (text.indexOf(ircClient.nick + ': ' + 'force-restart') === 0) {
+                if (from_trusted) {
+                    console.log(from + ' => ' + to  + ' ' + text);
 
-                ircClient.say(to, "re-connecting to gerrit and irc.");
+                    ircClient.say(to, "re-connecting to gerrit and irc.");
 
-                logging.info('Disconnecting from irc.');
+                    logging.info('Disconnecting from irc.');
 
-                ircClient.send('QUIT', "quit");
+                    ircClient.send('QUIT', "quit");
 
-                logging.info('re-connecting to gerrit..');
+                    logging.info('re-connecting to gerrit..');
 
-                if (sshConn) {
-                    sshConn.end();
+                    if (sshConn) {
+                        sshConn.end();
+                    }
+
+                    logging.info('re-connected to gerrit.');
+
+                    setTimeout(function(){ ircClient.say(to, "re-connected to 
gerrit and irc."); }, 17000);
+
+                    logging.info('re-connected to irc.');
+                } else {
+                    ircClient.say(to, "Permission is denied.");
                 }
-
-                logging.info('re-connected to gerrit.');
-
-                setTimeout(function(){ ircClient.say(to, "re-connected to 
gerrit and irc."); }, 17000);
-
-                logging.info('re-connected to irc.');
-            } else if (command_force_restart && !from_trusted) {
-               ircClient.say(to, "Permission is denied.");
             }
 
-            if (command_nick && from_trusted && using_intended_nick) {
-                console.log(from + ' => ' + to  + ' ' + text);
+            if (text.indexOf(ircClient.nick + ': ' + 'nick') === 0) {
+                if (!from_trusted) {
+                    ircClient.say(to, "Permission is denied.");
+                } else if (config.nick.indexOf(ircClient.nick) === 0) {
+                    console.log(from + ' => ' + to  + ' ' + text);
 
-                ircClient.say(to, "Nick is already " + ircClient.nick + " not 
changing the nick.");
-            } else if (command_nick && from_trusted) {
-                console.log(from + ' => ' + to  + ' ' + text);
+                    ircClient.say(to, "Nick is already " + ircClient.nick + " 
not changing the nick.");
+                } else {
+                    console.log(from + ' => ' + to  + ' ' + text);
 
-                logging.info('Changing nick');
+                    logging.info('Changing nick');
 
-                ircClient.send('NICK', config.nick);
+                    ircClient.send('NICK', config.nick);
 
-                if (ircClient.pass) {
-                    ircClient.pass(config.password);
+                    if (ircClient.pass) {
+                        ircClient.pass(config.password);
+                    }
+                    logging.info('changed nick to' + ' ' + config.nick);
                 }
-                logging.info('changed nick to' + ' ' + config.nick);
-            } else if (command_nick && !from_trusted) {
-                ircClient.say(to, "Permission is denied.");
             }
 
             if (text.indexOf(ircClient.nick + ': ' + 'help') === 0) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2871437dac136130365089dfbefab27c47f747f7
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <a...@wikimedia.org>

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

Reply via email to