PiRSquared17 has submitted this change and it was merged.

Change subject: Add status checker to bot-operator
......................................................................


Add status checker to bot-operator

Change-Id: Ic90c82e631b1ca5d43444b0b7ece1d81dd20306d
---
M masters/bot-operator.php
1 file changed, 33 insertions(+), 3 deletions(-)

Approvals:
  PiRSquared17: Verified; Looks good to me, approved



diff --git a/masters/bot-operator.php b/masters/bot-operator.php
old mode 100644
new mode 100755
index 044b815..3fd6294
--- a/masters/bot-operator.php
+++ b/masters/bot-operator.php
@@ -24,6 +24,7 @@
 include $prefix.'class/socket.class.php';
 include $prefix.'class/Irc.class.php';
 include '/data/project/irc-wmt/bots/include/config/irc_conf.php';
+$bots_file = "/data/project/irc-wmt/bots.json"; // use SQL instead?
 
 $bot_channel_bots = "#wmt-bots";
 $bot_channel = "#wmt-op";
@@ -63,14 +64,43 @@
                                $irc-> AutreCommande ( "PONG $tab[1]" ) ;
                                echo "PING PONG OK\n" ;
                        }
-               
-                       if ( $tab[0] == "ERROR" )
+                       elseif ( $tab[0] == "ERROR" )
                        {
                                // Restarts the current process
                                $irc->quit() ;
                                $wm->quit() ;
                                # Removed the system instruction - the file 
will be automatically restarted by daemon
                                exit(3); 
+                       }
+                       elseif (preg_match ('#^:(wmtbot-.*?)![^ ]* JOIN 
.wmt-bots$#' , $data , $matches))
+                       {
+                               $string = file_get_contents($bots_file);
+                               $json = json_decode($string,true);
+                               if (array_key_exists($matches[1], $json))
+                               {
+                                       $json[$matches[1]]["status"] = "up";
+                                       file_put_contents($bots_file, 
json_encode($json));
+                               }
+                       }
+                       elseif (preg_match ('#^:(wmtbot-.*?)![^ ]* QUIT( 
.*)?$#' , $data , $matches))
+                       {
+                               $string = file_get_contents($bots_file);
+                               $json = json_decode($string,true);
+                               if (array_key_exists($matches[1], $json))
+                               {
+                                       $json[$matches[1]]["status"] = "down";
+                                       file_put_contents($bots_file, 
json_encode($json));
+                               }
+                       }
+                       elseif (preg_match ('#^:(wmtbot-.*?)![^ ]* NICK .*$#' , 
$data , $matches))
+                       {
+                               $string = file_get_contents($bots_file);
+                               $json = json_decode($string,true);
+                               if (array_key_exists($matches[1], $json))
+                               {
+                                       $json[$matches[1]]["status"] = "down";
+                                       file_put_contents($bots_file, 
json_encode($json));
+                               }
                        }
                }
        }
@@ -79,7 +109,7 @@
        
        
        else usleep(500000); // wait 0.5 seconds
-       
+
        unset($data); // free memory
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic90c82e631b1ca5d43444b0b7ece1d81dd20306d
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/WMT
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com>
Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com>
Gerrit-Reviewer: PiRSquared17 <pirsquare...@gmail.com>

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

Reply via email to