Esempio n. 1
0
 public function run()
 {
     /*
      * Create the event loop
      */
     $eventLoop = Factory::create();
     /*
      * Create our Slack client
      */
     $client = new RealTimeClient($eventLoop);
     $client->setToken(getenv('BOT_TOKEN'));
     /*
      * Setup command bindings
      */
     $commandBindings = ['help' => HelpCommand::class, 'start' => StartCommand::class, 'end' => EndCommand::class, 'see' => SeeCommand::class, 'vote' => VoteCommand::class, 'kill' => KillCommand::class, 'guard' => GuardCommand::class];
     /*
      * Create the game manager
      */
     $gameManager = new GameManager($client, $commandBindings);
     /*
      * Route incoming Slack messages
      */
     $client->on('message', function ($data) use($client, $gameManager) {
         $gameManager->input(new Message($data));
     });
     /*
      * Connect to Slack
      */
     echo "Connecting...\r\n";
     $client->connect()->then(function () {
         echo "Connected.\n";
     }, function (ConnectionException $e) {
         echo $e->getMessage();
         exit;
     });
     /*
      * Start the event loop
      */
     $eventLoop->run();
 }
Esempio n. 2
0
 /**
  * Run the bot process.
  *
  * @return void
  */
 public function run()
 {
     $loop = \React\EventLoop\Factory::create();
     $client = new RealTimeClient($loop);
     $client->setToken($this->token);
     // Respond to RTM messages
     $client->on('message', function ($payload) use($client) {
         // Output debug
         $this->debug('Message received', $payload->getData());
         // Create a message entity from payload
         $message = new Message($client, $payload);
         // Certain message types are blocked
         if (!$message->isValidForReaction()) {
             return;
         }
         // Execute relevant command
         $this->react($message);
     });
     $this->debug('Connecting to RTM socket');
     $client->connect()->then(function () {
         $this->debug('Connected to RTM socket');
     });
     $loop->run();
 }