Ejemplo n.º 1
0
 public function onMention(Message $message, ChannelInterface $channel, User $user)
 {
     if ($message->matchesAny('/hello/i', '/greetings/i')) {
         $greetings = sprintf('%s, %s!', $this->greeting, $user->getUsername());
         $this->bot->say($greetings, $channel);
     }
 }
Ejemplo n.º 2
0
 /**
  * Runs the bot.
  */
 public function run()
 {
     $this->client->on('message', function (Payload $data) {
         $message = new Message($this->client, $data->getData());
         $this->app->getLogger()->info('Noticed message', ['text' => $message->getText()]);
         $this->emit('message', [$message]);
         if ($message->matchesAny('/' . $this->botUser->getUsername() . '/i')) {
             $this->app->getLogger()->debug('Mentioned in message', [$message]);
             $this->emit('mention', [$message]);
         }
     });
     $this->client->connect()->then(function () {
         return $this->client->getAuthedUser();
     })->then(function (User $user) {
         $this->botUser = $user;
         $this->app->getLogger()->info('Bot user name is configured as ' . $user->getUsername());
     });
     $this->loop->run();
 }