Пример #1
0
 public function run()
 {
     /*
      * Create the event loop
      */
     $eventLoop = Factory::create();
     /*
      * Create our Slack client
      */
     $client = new SlackRTMClient($eventLoop);
     $client->setToken(getenv('BOT_TOKEN'));
     /*
      * Setup command bindings
      */
     $commandBindings = ['help' => HelpCommand::class, 'setoption' => SetOptionCommand::class, 'new' => NewCommand::class, 'join' => JoinCommand::class, 'leave' => LeaveCommand::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) {
         $message = new Message($data);
         if ($message->getSubType() == 'channel_join') {
             $client->refreshChannel($message->getChannel());
         } else {
             if ($message->getSubType() == 'channel_leave') {
                 $client->refreshChannel($message->getChannel());
             } else {
                 $gameManager->input($message);
             }
         }
     });
     /*
      * 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();
 }
Пример #2
0
 public function run()
 {
     /*
      * Create the event loop
      */
     $eventLoop = Factory::create();
     /*
      * @var \Slackwolf\SlackRTMClient
      */
     $client = new SlackRTMClient($eventLoop);
     $client->setToken($this->token);
     /*
      * Create the game manager
      */
     $gameManager = new GameManager($client);
     /*
      * Route incoming Slack messages
      */
     $client->on('message', function ($data) use($client, $gameManager) {
         $message = new Message($data);
         if ($message->getSubType() == 'channel_join') {
             $client->refreshChannel($message->getChannel());
         } else {
             if ($message->getSubType() == 'channel_leave') {
                 $client->refreshChannel($message->getChannel());
             } else {
                 $gameManager->input($message);
             }
         }
     });
     /*
      * 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();
 }