コード例 #1
0
ファイル: Greetings.php プロジェクト: pavel-voronin/slacky
 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);
     }
 }
コード例 #2
0
ファイル: Bot.php プロジェクト: pavel-voronin/slacky
 /**
  * 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();
 }