Skip to content

Commit

Permalink
Add timestamp into embed footer (#25)
Browse files Browse the repository at this point in the history
* Add a timestamp function to embeds

* Add tests for timestamp function
  • Loading branch information
Shaggy84675 authored Sep 16, 2022
1 parent 52466f4 commit 953feb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/DiscordLogger/Discord/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Embed implements Arrayable
/** @var array */
public $fields;

/** @var string */
public $timestamp;

/** Static factory method */
public static function make(): Embed
{
Expand Down Expand Up @@ -104,6 +107,12 @@ public function field(string $name, string $value, bool $inline = false): Embed
return $this;
}

public function timestamp(string $timestamp): Embed
{
$this->timestamp = $timestamp;
return $this;
}

public function toArray(): array
{
return array_filter(
Expand All @@ -117,6 +126,7 @@ public function toArray(): array
'thumbnail' => $this->thumbnail,
'author' => $this->author,
'fields' => $this->serializeFields(),
'timestamp' => $this->timestamp,
],
static function ($value) {
return $value !== null && $value !== [];
Expand Down
4 changes: 3 additions & 1 deletion tests/Discord/EmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function can_convert_to_array()
->thumbnail('thumbnail.url')
->field('first-field', 'foo', true)
->field('second-field', 'bar', false)
->footer('my footer', 'footer-icon.url');
->footer('my footer', 'footer-icon.url')
->timestamp('2000-01-01T12:13:14.000Z');

$this->assertEquals(
['title' => 'my title',
Expand All @@ -52,6 +53,7 @@ public function can_convert_to_array()
['name' => 'second-field',
'value' => 'bar',
'inline' => false,],],
'timestamp' => '2000-01-01T12:13:14.000Z',
],
$embed->toArray());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Discord/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function can_convert_to_array()
->thumbnail('thumbnail.url')
->field('first-field', 'foo', true)
->field('second-field', 'bar', false)
->footer('my footer', 'footer-icon.url');
->footer('my footer', 'footer-icon.url')
->timestamp('2000-01-01T12:13:14.000Z');

$message = Message::make()
->content('my content')
Expand Down

0 comments on commit 953feb6

Please sign in to comment.