api = $api; $this->id = (int)$data['id']; $this->username = $data['username']; if (!empty($data['badge'])) { $this->badge = new Badge($data['badge']); } if (!empty($data['content'])) { $this->avatar_image = new Image($data['content']['avatar_image']); $this->cover_image = new Image($data['content']['cover_image']); } if (!empty($data['name'])) { $this->name = $data['name']; } if (!empty($data['presence'])) { if (is_string($data['presence']) || is_int($data['presence'])) { $this->presence = !($data['presence'] == "offline" || $data['presence'] === 0); } } } public function getPresenceInt(): int { if ($this->presence === true) { return 1; } elseif ($this->presence === false) { return 0; } else { return -1; } } public function getPresenceString() { if ($this->presence === true) { return "online"; } elseif ($this->presence === false) { return "offline"; } else { return "presence unknown"; } } public function getAvatarUrl( ?int $width = null, ?int $height = null ): string { if (empty($this->avatar_image)) { return $this->api->getAvatarUrl($this->id, $width, $height); } $query = ''; if (!empty($width)) { $query = '?w='.$width; } elseif (!empty($height)) { $query = '?h='.$height; } return $this->avatar_image->link.$query; } public function getProfileLink(?string $display_name = null): string { $display_name ??= $this->username; return User::getProfileLinkForUsername($this->username, $display_name); } public static function getProfileLinkForUsername(string $username, ?string $display_name = null): string { $display_name ??= $username; return ''.$username.''; } }