-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
325 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Discord\Parts\Embed; | ||
|
||
use Discord\Parts\Part; | ||
|
||
/** | ||
* The author of an embed object. | ||
* | ||
* @property string $name The name of the author. | ||
* @property string $url The URL to the author. | ||
* @property string $icon_url The source of the author icon. Must be https. | ||
* @property string $proxy_icon_url A proxied version of the icon url. | ||
*/ | ||
class Author extends Part | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $fillable = ['name', 'url', 'icon_url', 'proxy_icon_url']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
namespace Discord\Parts\Embed; | ||
|
||
use Carbon\Carbon; | ||
use Discord\Helpers\Collection; | ||
use Discord\Parts\Part; | ||
|
||
/** | ||
* An embed object to be sent with a message. | ||
* | ||
* @property string $title The title of the embed. | ||
* @property string $description A description of the embed. | ||
* @property string $url The URL of the embed. | ||
* @property Carbon|string $timestamp A timestamp of the embed. | ||
* @property int $color The color of the embed. | ||
* @property Footer $footer The footer of the embed. | ||
* @property Image $image The image of the embed. | ||
* @property Image $thumbnail The thumbnail of the embed. | ||
* @property Video $video The video of the embed. | ||
* @property array $provider The provider of the embed. | ||
* @property Author $author The author of the embed. | ||
* @property Collection[Field] $fields A collection of embed fields. | ||
*/ | ||
class Embed extends Part | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $fillable = ['title', 'type', 'description', 'url', 'timestamp', 'color', 'footer', 'image', 'thumbnail', 'video', 'provider', 'author', 'fields']; | ||
|
||
/** | ||
* Gets the timestamp attribute. | ||
* | ||
* @return Carbon The timestamp attribute. | ||
*/ | ||
public function getTimestampAttribute() | ||
{ | ||
if (! array_key_exists('timestamp', $this->attributes)) { | ||
return Carbon::now(); | ||
} | ||
|
||
return Carbon::parse($this->attributes['timestamp']); | ||
} | ||
|
||
/** | ||
* Gets the footer attribute. | ||
* | ||
* @return Footer The footer attribute. | ||
*/ | ||
public function getFooterAttribute() | ||
{ | ||
return $this->attributeHelper('footer', Footer::class); | ||
} | ||
|
||
/** | ||
* Gets the image attribute. | ||
* | ||
* @return Image The image attribute. | ||
*/ | ||
public function getImageAttribute() | ||
{ | ||
return $this->attributeHelper('image', Image::class); | ||
} | ||
|
||
/** | ||
* Gets the thumbnail attribute. | ||
* | ||
* @return Thumbnail The thumbnail attribute. | ||
*/ | ||
public function getThumbnailAttribute() | ||
{ | ||
return $this->attributeHelper('thumbnail', Image::class); | ||
} | ||
|
||
/** | ||
* Gets the video attribute. | ||
* | ||
* @return Video The video attribute. | ||
*/ | ||
public function getVideoAttribute() | ||
{ | ||
return $this->attributeHelepr('video', Video::class); | ||
} | ||
|
||
/** | ||
* Gets the author attribute. | ||
* | ||
* @return Author The author attribute. | ||
*/ | ||
public function getAuthorAttribute() | ||
{ | ||
return $this->attributeHelper('author', Author::class); | ||
} | ||
|
||
/** | ||
* Gets the fields attribute. | ||
* | ||
* @return Collection[Field] The fields attribute. | ||
*/ | ||
public function getFieldsAttribute() | ||
{ | ||
$fields = new Collection(); | ||
|
||
foreach ($this->attributes['fields'] as $field) { | ||
if (! ($field instanceof Field)) { | ||
$field = $this->discord->factory(Field::class, $field, true); | ||
} | ||
|
||
$fields->push($field); | ||
} | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Helps with getting embed attributes. | ||
* | ||
* @param string $key The attribute key. | ||
* @param string $class The attribute class. | ||
* | ||
* @return mixed | ||
*/ | ||
protected function attributeHelper($key, $class) | ||
{ | ||
if ($this->attributes[$key] instanceof $class) { | ||
return $this->attributes[$key]; | ||
} | ||
|
||
return $this->discord->factory($class, $this->attributes[$key], true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Discord\Parts\Embed; | ||
|
||
use Discord\Parts\Part; | ||
|
||
/** | ||
* A field of an embed object. | ||
* | ||
* @property string $name The name of the field. | ||
* @property string $value The value of the field. | ||
* @property bool $inline Whether the field should be displayed in-line. | ||
*/ | ||
class Field extends Part | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $fillable = ['name', 'value', 'inline']; | ||
|
||
/** | ||
* Gets the inline attribute. | ||
* | ||
* @return bool The inline attribute. | ||
*/ | ||
public function getInlineAttribute() | ||
{ | ||
if (! array_key_exists('inline', $this->attributes)) { | ||
return false; | ||
} | ||
|
||
return $this->attributes['inline']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Discord\Parts\Embed; | ||
|
||
use Discord\Parts\Part; | ||
|
||
/** | ||
* The footer section of an embed. | ||
* | ||
* @property string $text Footer text. | ||
* @property string $icon_url URL of an icon for the footer. Must be https. | ||
* @property string $proxy_icon_url Proxied version of the icon URL. | ||
*/ | ||
class Footer extends Part | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $fillable = ['text', 'icon_url', 'proxy_icon_url']; | ||
} |
Oops, something went wrong.