상속: extends slack\ClientObject
예제 #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);
     }
 }
예제 #2
0
 public function testGetPresence()
 {
     $presence = $this->faker->boolean ? 'active' : 'away';
     $user = new User($this->client, ['id' => $this->faker->uuid]);
     $this->mockResponse(200, null, ['ok' => true, 'presence' => $presence]);
     $this->watchPromise($user->getPresence()->then(function ($actual) use($presence) {
         $this->assertEquals($presence, $actual);
     }));
 }
예제 #3
0
 public function testGetCreator()
 {
     $creator = new User($this->client, ['id' => $this->faker->uuid]);
     $channel = new Channel($this->client, ['creator' => $creator->getId()]);
     $this->mockResponse(200, null, ['ok' => true, 'user' => ['id' => $creator->data['id']]]);
     $this->watchPromise($channel->getCreator()->then(function (User $user) use($creator) {
         $this->assertEquals($creator->data, $user->data);
     }));
 }
예제 #4
0
 /**
  * Connect to slack server
  */
 protected function connect()
 {
     $this->client->connect()->then(function () {
         return $this->client->getAuthedUser();
     })->then(function (User $user) {
         $this->botUser = $user;
         $this->logger->info("Connected as " . $this->botUser->getUsername());
     });
 }
예제 #5
0
 /**
  * Welcomes a user to the team.
  *
  * @param array $data Event data.
  */
 protected function welcomeUser(User $user)
 {
     // Open a DM with the user and talk about the Slack team a bit.
     $this->client->getDMbyUserId($user->getId())->then(function (DirectMessageChannel $channel) {
         return $this->client->getDMById($channel->getId());
     })->then(function (DirectMessageChannel $channel) use($user) {
         return $this->client->send(sprintf("Hi there, %s! Thanks for signing up! I'm sure my friend <@USLACKBOT> is helping you set up your account right now.", $user->getUsername()), $channel)->then(function () use($user, $channel) {
             sleep(3);
             return $this->client->send("I just want to informally introduce you to the team." . " First, you will see a list of channels on the left. There's the <#C025YTX9D>" . " channel, which is a great place to discuss normal goings-on. If you want to just" . " hang out and talk about random things, the <#C025YTX9F> channel is perfect for that.", $channel);
         })->then(function () use($user, $channel) {
             sleep(6);
             return $this->client->send("If you're looking to start a group project, private groups are" . " perfect for that. You can create a new group by clicking on the \"+\" next to \"PRIVATE" . " GROUPS\" on the left.", $channel);
         })->then(function () use($user, $channel) {
             sleep(5);
             return $this->client->send("If you have any questions, feel free to ask one of the humans in <#C025YTX9D>.", $channel);
         });
     });
 }
예제 #6
0
 /**
  * Messaging helper. Sends message to last message channel with sender username mentioning.
  *
  * @param $message
  */
 public function reply($message)
 {
     $this->bot->say(sprintf('%s, %s', $this->lastMessageUser->getUsername(), $message), $this->lastMessageChannel);
 }
예제 #7
0
 /**
  * Sets the user the message is sent from.
  *
  * @param User $user A user.
  * @return $this
  */
 public function setUser(User $user)
 {
     $this->data['user'] = $user->getId();
     return $this;
 }
예제 #8
0
 /**
  * Gets a direct message channel for a given user.
  *
  * @param User $user The user to get a DM for.
  *
  * @return \React\Promise\PromiseInterface A promise for a DM object.
  */
 public function getDMByUser(User $user)
 {
     return $this->getDMByUserId($user->getId());
 }
예제 #9
0
 /**
  * If the lobby is open, adds a user to it.
  *
  * @param User $user
  *   The user to add to the lobby.
  *
  * @return bool
  *   If successful, returns TRUE, otherwise, FALSE.
  */
 public function addLobbyPlayer(User $user)
 {
     if ($this->state == GameState::LOBBY) {
         $player_id = $user->getId();
         if (!isset($this->lobbyPlayers[$player_id])) {
             $this->lobbyPlayers[$player_id] = $user;
             return TRUE;
         }
     }
 }
예제 #10
0
 /**
  * Kicks a user from the channel.
  *
  * @param User The user to kick.
  *
  * @return \React\Promise\PromiseInterface
  */
 public function kickUser(User $user)
 {
     return $this->client->apiCall('channels.kick', ['channel' => $this->getId(), 'user' => $user->getId()])->then(function () use($user) {
         unset($this->data['members'][$user->getId()]);
     });
 }