Skip to content

Commit

Permalink
wip Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Jan 30, 2024
1 parent b690478 commit 5275664
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
10 changes: 8 additions & 2 deletions src/Discord/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

namespace Guanguans\Notify\Discord;

use Guanguans\Notify\Foundation\Credentials\NullCredential;
use Guanguans\Notify\Foundation\Credentials\UriTemplateCredential;

class Credential extends NullCredential {}
class Credential extends UriTemplateCredential
{
public function __construct(string $threadId, string $token)
{
parent::__construct(['threadId' => $threadId, 'token' => $token]);
}
}
41 changes: 6 additions & 35 deletions src/Discord/Messages/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ class Message extends \Guanguans\Notify\Foundation\Message
'embeds' => 'array',
];

public function setEmbeds(array $embeds): self
{
return $this->addEmbeds($embeds);
}

public function addEmbeds(array $embeds): self
{
foreach ($embeds as $embed) {
$this->addEmbed($embed);
}

return $this;
}

public function setEmbed(array $embed): self
{
return $this->addEmbed($embed);
}

public function addEmbed(array $embed): self
{
$this->options['embeds'][] = configure_options(
Expand All @@ -88,28 +69,18 @@ static function (OptionsResolver $optionsResolver): void {
->setAllowedTypes('thumbnail', 'array')
->setAllowedTypes('author', 'array')
->setAllowedTypes('fields', 'array')
->setNormalizer('color', static fn (OptionsResolver $optionsResolver, $value) => \is_int($value) ? $value : hexdec($value));
->setNormalizer('color', static fn (
OptionsResolver $optionsResolver,
$value
) => \is_int($value) ? $value : hexdec($value));
}
);

return $this;
}

public function toHttpUri(): void
{
// TODO: Implement httpUri() method.
}

protected function configureOptionsResolver(OptionsResolver $optionsResolver): OptionsResolver
public function toHttpUri(): string
{
return tap(
parent::configureOptionsResolver($optionsResolver),
static function (OptionsResolver $resolver): void {
$resolver->setNormalizer(
'embeds',
static fn (OptionsResolver $optionsResolver, array $value): array => isset($value[0]) ? $value : [$value]
);
}
);
return 'https://discord.com/api/webhooks/{threadId}/{token}';
}
}

0 comments on commit 5275664

Please sign in to comment.