flush
authorMichael Wallner <mike@php.net>
Thu, 28 May 2015 07:51:04 +0000 (09:51 +0200)
committerMichael Wallner <mike@php.net>
Thu, 28 May 2015 08:44:24 +0000 (10:44 +0200)
bot/bot.php

index 1eff46540467d4f23641ac7a3c3bff067cecf6cc..45ab8ae9a7203ca3ef48b38f7c66d8e51f7d3a3b 100644 (file)
@@ -20,35 +20,40 @@ class Robot extends Session
                parent::__construct($this->config->nick, $this->config->user, $this->config->real);
        }
        
-       function run() {
+       function run($watch_stdin = false) {
                printf("Connecting to %s...\n", $this->config->host);
                $this->doConnect($this->config->ipv6, $this->config->host, $this->config->port ?: 6667);
                
-               for (   stream_set_blocking(STDIN, 0), $i = 0, $x = ["–","\\","|","/"];
-                               false !== ($fds = @parent::run(array(STDIN), null, 1));
-                               ++$i) {
-                       if (!$this->isConnected()) {
-                               printf("  %s \r", $x[$i%4]);
-                       }
-                       if ($fds[0]) {
-                               switch ($command = fgets(STDIN)) {
-                               case "quit\n":
-                                       $this->disconnect();
-                                       break 2;
-                               case "reload\n":
-                                       $this->reload();
-                                       break;
-                               case "update\n":
-                                       $this->update();
-                                       break;
-                               default:
-                                       $this->doRaw($command);
+               if ($watch_stdin) {
+                       for (   stream_set_blocking(STDIN, 0), $i = 0, $x = ["–","\\","|","/"];
+                                       false !== ($fds = @parent::run(array(STDIN), null, 1));
+                                       ++$i) {
+                               if (!$this->isConnected()) {
+                                       printf("  %s \r", $x[$i%4]);
+                               }
+                               if ($fds[0]) {
+                                       switch ($command = fgets(STDIN)) {
+                                       case "quit\n":
+                                               $this->disconnect();
+                                               break 2;
+                                       case "reload\n":
+                                               $this->reload();
+                                               break;
+                                       case "update\n":
+                                               $this->update();
+                                               break;
+                                       default:
+                                               $this->doRaw($command);
+                                       }
+                               } else {
+                                       $this->work();
                                }
-                       } else {
+                       }
+               } else {
+                       while (false !== parent::run(null, null, 1)) {
                                $this->work();
                        }
                }
-               
                printf("Bye!\n");
        }