예제 #1
0
 /**
  * @param Message $message
  * @throws InvalidArgumentException
  */
 protected function onMessage(Message $message)
 {
     $collection = $this->karma->validate($message);
     foreach ($collection as $state) {
         $user = $state->getUser();
         if ($state->isIncrement()) {
             $message->user->addKarmaTo($user, $message);
         }
         if ($state->isIncrement() || $state->isTimeout() || $state->isSelf()) {
             echo "\r" . '[' . $message->created_at . '] ' . $state->getTranslation($user->karma_text) . "\n";
         }
     }
 }
예제 #2
0
 /**
  * @param Message $message
  * @return mixed
  */
 public function handle(Message $message)
 {
     $collection = $this->validator->validate($message);
     $hasAnswers = false;
     foreach ($collection as $state) {
         $user = $state->getUser();
         if ($state->isIncrement()) {
             $message->user->addKarmaTo($user, $message);
             if ($user->id === \Auth::user()->id) {
                 $message->answer(\Lang::get('karma.bot', ['user' => $message->user->login]));
             }
         }
         if (!$state->isNothing()) {
             $hasAnswers = true;
             $message->italic($state->getTranslation($user->karma_text));
         }
     }
     if (!$hasAnswers) {
         return $message;
     }
     return Storage::SIGNAL_STOP;
 }