diff --git a/composer.json b/composer.json index 7eaff93..3fc445a 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/DiscordWebhookBundle/DependencyInjection/DiscordWebhookExtension.php b/src/DiscordWebhookBundle/DependencyInjection/DiscordWebhookExtension.php index 85c8c8d..dd462bf 100644 --- a/src/DiscordWebhookBundle/DependencyInjection/DiscordWebhookExtension.php +++ b/src/DiscordWebhookBundle/DependencyInjection/DiscordWebhookExtension.php @@ -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 @@ -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]); diff --git a/src/DiscordWebhookBundle/DiscordWebhook.php b/src/DiscordWebhookBundle/DiscordWebhook.php index 2b6ca4a..995124a 100644 --- a/src/DiscordWebhookBundle/DiscordWebhook.php +++ b/src/DiscordWebhookBundle/DiscordWebhook.php @@ -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