/**
  * Adds !quit, !join, and !leave commands to the bot:
  *
  * !quit <quit message> -- Tells the bot to quit the IRC server
  * Example usage:
  *      !quit ...aaand boom goes the dynamite.
  *
  * !join <channels>
  * Example usage:
  *      !join #example-room
  *      !join #example-room1 #example-room2
  *
  * !leave <channels> -- Tells the bot to leave channels
  * Example usage:
  *      !leave #example-room
  *      !leave #example-room1 #example-room2
  *
  * !say <channel> <msg> -- Tells the bot to send a message to the given channel
  * Example usage:
  *      !say #example-room Look I can talk.
  *  
  * These commands only work via private message and only if the issuer
  * is in the ops array in the bot's configuration.
  */
 public function init()
 {
     $bot = $this->bot;
     $config = $bot->getConfig();
     // Allow the bot to join rooms
     $this->bot->onPrivateMessage("/^!join(.*)/", function (Event $event) use($config, $bot) {
         $matches = $event->getMatches();
         $user = $event->getRequest()->getSendingUser();
         $rooms = explode(' ', $matches[0]);
         if ($bot->isAdmin($user)) {
             $event->addResponse(Response::join(implode(',', $rooms)));
         } else {
             $event->addResponse(Response::msg($user, "You're not the boss of me."));
         }
     });
     // Allow the bot to leave rooms
     $this->bot->onPrivateMessage("/^!leave(.*)/", function (Event $event) use($config, $bot) {
         $matches = $event->getMatches();
         $user = $event->getRequest()->getSendingUser();
         $rooms = explode(' ', $matches[0]);
         if ($bot->isAdmin($user)) {
             $event->addResponse(Response::leave(implode(',', $rooms)));
         } else {
             $event->addResponse(Response::msg($user, "You're not the boss of me."));
         }
     });
     // Echo things into channels
     $this->bot->onPrivateMessage("/^!say ([#&][^,\\s]{0,200}) (.+)/", function (Event $event) use($config, $bot) {
         $matches = $event->getMatches();
         $user = $event->getRequest()->getSendingUser();
         if ($bot->isAdmin($user)) {
             $event->addResponse(Response::msg($matches[0], $matches[1]));
         } else {
             $event->addResponse(Response::msg($user, "You're not the boss of me."));
         }
     });
     // Quit gracefully
     $this->bot->onPrivateMessage("/^!quit(.*)/", function (Event $event) use($config, $bot) {
         $matches = $event->getMatches();
         $user = $event->getRequest()->getSendingUser();
         $msg = $matches[0] ? trim($matches[0]) : 'Later, kids.';
         if ($bot->isAdmin($user)) {
             $event->addResponse(Response::quit($msg));
         } else {
             $event->addResponse(Response::msg($user, "You're not the boss of me."));
         }
     });
 }
Exemple #2
0
 /**
  * Joins the channels specified in the config.
  */
 private function join()
 {
     if (!is_array($this->config['channels'])) {
         $this->config['channels'] = array($this->config['channels']);
     }
     $channels = array();
     $passwords = array();
     $without_passwords = array();
     // Separate them into groups to make it easier to deal with
     foreach ($this->config['channels'] as $channel) {
         if (is_array($channel)) {
             foreach ($channel as $chan => $pass) {
                 $channels[] = $chan;
                 $passwords[] = $pass;
             }
         } else {
             $without_passwords[] = $channel;
         }
     }
     $join = sprintf('%s %s', implode(',', array_merge($channels, $without_passwords)), implode(',', $passwords));
     $this->send(Response::join($join));
 }
Exemple #3
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);
 }