예제 #1
0
파일: Philip.php 프로젝트: epochblue/philip
 /**
  * Loads default event handlers for basic IRC commands that won't be
  * unique to each bot.
  */
 private function addDefaultHandlers()
 {
     $log = $this->log;
     // When the server PINGs us, just respond with PONG and the server's host
     $this->onPing(function (Event $event) {
         $event->addResponse(Response::pong($event->getRequest()->getMessage()));
     });
     // If an ERROR message is encountered, just log it for now.
     $this->onError(function (Event $event) use($log) {
         $log->debug("--- ERROR: {$event->getRequest()->getMessage()}");
     });
     $plugins =& $this->plugins;
     $this->onMessages('/^!help\\s*$/', function (Event $event) use(&$plugins) {
         foreach ($plugins as $plugin) {
             $messages = $plugin->displayHelp($event);
             // Surely there's a better way to do this... <sadface>
             if (is_array($messages)) {
                 foreach ($messages as $message) {
                     $event->addResponse(Response::msg($event->getRequest()->getSendingUser(), $message));
                 }
             } else {
                 $event->addResponse(Response::msg($event->getRequest()->getSendingUser(), $messages));
             }
         }
     });
 }
예제 #2
0
 public function testClass()
 {
     $this->string(TestedClass::pong($host = uniqid()))->isEqualTo('PONG :' . $host)->string(TestedClass::quit($message = uniqid()))->isEqualTo('QUIT :' . $message)->string(TestedClass::join($channel = '#' . uniqid()))->isEqualTo('JOIN ' . $channel)->string(TestedClass::leave($channel))->isEqualTo('PART ' . $channel)->string(TestedClass::msg($who = uniqid(), $message))->isEqualTo('PRIVMSG ' . $who . ' :' . $message)->string(TestedClass::notice($channel, $message))->isEqualTo('NOTICE ' . $channel . ' :' . $message)->string(TestedClass::action($channel, $message))->isEqualTo('PRIVMSG ' . $channel . ' :' . "ACTION " . $message . "")->string(TestedClass::user($nick = uniqid(), $name = uniqid()))->isEqualTo('USER ' . $nick . ' 8 * :' . $name)->string(TestedClass::nick($nick))->isEqualTo('NICK :' . $nick)->string(TestedClass::pass($pass = uniqid()))->isEqualTo('PASS ' . $pass);
 }