Slackwolf\Game\Formatter\ChannelIdFormatter::format PHP Method

format() public static method

public static format ( $userId ) : string
$userId
return string
    public static function format($userId)
    {
        $trimmed = trim($userId, "<>#\t\n\r\v");
        if (strpos($trimmed, '|') !== false) {
            $trimmed = substr($trimmed, 0, strpos($trimmed, '|'));
        }
        return $trimmed;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * Constructs a new Kill command.
  */
 public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null)
 {
     parent::__construct($client, $gameManager, $message, $args);
     $client = $this->client;
     if ($this->channel[0] != 'D') {
         throw new Exception("You may only !kill privately.");
     }
     if (count($this->args) < 2) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Invalid command. Usage: !kill #channel @user", $channel);
         });
         throw new InvalidArgumentException("Not enough arguments");
     }
     $client = $this->client;
     $channelId = null;
     $channelName = "";
     if (strpos($this->args[0], '#C') !== false) {
         $channelId = ChannelIdFormatter::format($this->args[0]);
     } else {
         if (strpos($this->args[0], '#') !== false) {
             $channelName = substr($this->args[0], 1);
         } else {
             $channelName = $this->args[0];
         }
     }
     if ($channelId != null) {
         $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Invalid channel specified. Usage: !kill #channel @user", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->game = $this->gameManager->getGame($channelId);
     if (!$this->game) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: No game in progress.", $channel);
         });
         throw new Exception("No game in progress.");
     }
     $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers());
 }
All Usage Examples Of Slackwolf\Game\Formatter\ChannelIdFormatter::format
ChannelIdFormatter