Exemple #1
0
 /**
  * Reply to the operation.
  * @param $event event that triggered the operation.
  * @return BotMessage with bot statistics.
  */
 public function reply(BotEvent $event)
 {
     $sender = $event->getSender();
     $uptime = time() - $event->getBot()->getStartTime();
     $repliesAmount = $event->getBot()->getRepliesCounter();
     $timeUnits = array('dia' => 86400, 'hora' => 3600, 'minuto' => 60, 'segundo' => 1);
     $tmp = $uptime;
     $msg = "";
     foreach ($timeUnits as $name => $seconds) {
         $calc = floor($tmp / $seconds);
         $tmp -= $calc * $seconds;
         if ($calc > 0) {
             $msg .= "{$calc} {$name}";
             if ($calc > 1) {
                 $msg .= "s";
             }
             $msg .= " e ";
         }
     }
     $reply = "Estou vivo ha {$msg} respondi a {$replies} mensagens ate agora.";
     if ($event->isPrivate()) {
         $destination = $sender;
     } else {
         $reply = "{$sender}: {$reply}";
         $destination = $event->getDestination();
     }
     return new BotMessage($destination, $reply);
 }
Exemple #2
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);
 }