Skip to content

Commit

Permalink
[InternalBot] Fixed Embed converter.
Browse files Browse the repository at this point in the history
- DiscordPHP has completely null embed classes instead of null :(
  • Loading branch information
JaxkDev committed Aug 21, 2023
1 parent 749549d commit 30733db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/InternalBot/ModelConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,14 @@ static public function genModelEmbed(DiscordEmbed $discordEmbed): Embed{
$discordEmbed->description,
$discordEmbed->url,
$discordEmbed->timestamp instanceof Carbon ? $discordEmbed->timestamp->getTimestamp() : (int)$discordEmbed->timestamp,
$discordEmbed->color, $discordEmbed->footer === null ? null : self::genModelEmbedFooter($discordEmbed->footer),
$discordEmbed->image === null ? null : self::genModelEmbedImage($discordEmbed->image),
$discordEmbed->thumbnail === null ? null : self::genModelEmbedImage($discordEmbed->thumbnail),
$discordEmbed->color,
($discordEmbed->footer === null || $discordEmbed->footer->text === null) ? null : self::genModelEmbedFooter($discordEmbed->footer),
($discordEmbed->image === null || $discordEmbed->image->url === null) ? null : self::genModelEmbedImage($discordEmbed->image),
($discordEmbed->thumbnail === null || $discordEmbed->thumbnail->url === null) ? null : self::genModelEmbedImage($discordEmbed->thumbnail),
$discordEmbed->video === null ? null : self::genModelEmbedVideo($discordEmbed->video),
/** @phpstan-ignore-next-line Poorly documented provider object */
$discordEmbed->provider === null ? null : new Provider($discordEmbed->provider?->name, $discordEmbed->provider?->url),
$discordEmbed->author === null ? null : self::genModelEmbedAuthor($discordEmbed->author),
($discordEmbed->author === null || $discordEmbed->author->name === null) ? null : self::genModelEmbedAuthor($discordEmbed->author),
$fields);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Models/Messages/Embed/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
*/
class Image implements BinarySerializable{

private ?string $url;
private string $url;

private ?string $proxy_url;

private ?int $width;

private ?int $height;

public function __construct(?string $url, ?string $proxy_url = null, ?int $width = null, ?int $height = null){
public function __construct(string $url, ?string $proxy_url = null, ?int $width = null, ?int $height = null){
$this->setUrl($url);
$this->setProxyUrl($proxy_url);
$this->setWidth($width);
$this->setHeight($height);
}

public function getUrl(): ?string{
public function getUrl(): string{
return $this->url;
}

public function setUrl(?string $url): void{
public function setUrl(string $url): void{
$this->url = $url;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ public function setHeight(?int $height): void{

public function binarySerialize(): BinaryStream{
$stream = new BinaryStream();
$stream->putNullableString($this->getUrl());
$stream->putString($this->getUrl());
$stream->putNullableString($this->getProxyUrl());
$stream->putNullableInt($this->getWidth());
$stream->putNullableInt($this->getHeight());
Expand All @@ -80,7 +80,7 @@ public function binarySerialize(): BinaryStream{

public static function fromBinary(BinaryStream $stream): self{
return new self(
$stream->getNullableString(), // url
$stream->getString(), // url
$stream->getNullableString(), // proxy_url
$stream->getNullableInt(), // width
$stream->getNullableInt() // height
Expand Down

0 comments on commit 30733db

Please sign in to comment.