Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": "^8.0",
"labymod/discord-webhook": "^2.0 || ^3.0",
"labymod/discord-webhook": "^2.1.3 || ^3.1.3",
"symfony/framework-bundle": "^5.0 || ^6.0",
"symfony/string": "^5.0 || ^6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
->register(DiscordWebhook::class, DiscordWebhook::class)
->setPublic(true)
->setArgument('$url', $config['default_url'])
->setArgument('$serviceName', DiscordWebhook::class)
->addTag('discord_webhook.client', ['key' => DiscordWebhook::class]);

// configure the additional named clients
Expand All @@ -47,6 +48,7 @@ private function configureClients(array $config, ContainerBuilder $container, Fi
->register($name, DiscordWebhook::class)
->setPublic(true)
->setArgument('$url', $clientConfig['webhook_url'])
->setArgument('$serviceName', $name)
->addMethodCall('setUsername', [$clientConfig['username']])
->addMethodCall('setAvatar', [$clientConfig['avatar_url']])
->addTag('discord_webhook.client', ['key' => $name]);
Expand Down
20 changes: 19 additions & 1 deletion src/DiscordWebhookBundle/DiscordWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@
*/
class DiscordWebhook extends Webhook
{
public function __construct(array|string $url = [])
private string $serviceName;

public function __construct(array|string $url = [], string $serviceName = DiscordWebhook::class)
{
parent::__construct($url);

$this->serviceName = $serviceName;
}

public function send(): bool
{
$status = parent::send(false);
$ignoredFields = [];

if ($this->serviceName !== DiscordWebhook::class) {
$ignoredFields = ['username', 'avatarUrl'];
}

$this->reset($ignoredFields);

return $status;
}

public function setUrl(string $webhook): void
Expand Down