示例#1
0
文件: BotOperation.php 项目: mmr/b1n
 /**
  * Test the event against the trigger to check if the operation is to be fired.
  * @return <code>true</code> if the operation did trigger, <code>false</code> otherwise.
  */
 public final function isTriggered(BotEvent $event)
 {
     $match = array();
     $message = $event->getMessage();
     if (preg_match("#^(\\s*" . $this->trigger . "(\\s+|\$))#i", $message, $match)) {
         $message = substr($message, strlen($match[1]));
         $event->setMessage($message);
         return true;
     }
     return false;
 }
示例#2
0
文件: SayOperation.php 项目: mmr/b1n
 /**
  * Reply to operation.
  * @param $event event that triggered this operation.
  * @return BotMessage with the reply.
  */
 public function reply(BotEvent $event)
 {
     if ($event->isPrivate()) {
         return;
     }
     $message = $event->getMessage();
     $reply = trim($message);
     if (!empty($reply)) {
         return new BotMessage($event->getDestination(), $reply);
     }
 }
示例#3
0
 /**
  * Reply to the operation.
  * @param $event event that triggered the operation.
  * @return BotMessage with magic 8's answer.
  */
 public function reply(BotEvent $event)
 {
     $sender = $event->getSender();
     $message = $event->getMessage();
     if (preg_match("/([^\\s]+)\\s+ou\\s+([^\\s?]+)/i", $message)) {
         $responses = spliti(" ou ", $message);
     } else {
         $responses = $this->responses;
     }
     $response = mt_rand(0, count($responses) - 1);
     $reply = $responses[$response];
     $reply = trim(str_replace("?", "", $reply));
     if ($event->isPrivate()) {
         $destination = $sender;
     } else {
         $reply = "{$sender}: {$reply}";
         $destination = $event->getDestination();
     }
     return new BotMessage($destination, $reply);
 }