From c0c10f894957e5061910a0e640a945227fe21bdf Mon Sep 17 00:00:00 2001 From: Buster Neece Date: Tue, 7 Nov 2023 09:44:59 -0600 Subject: [PATCH] Add periodic donate notifications to dashboard. --- config/events.php | 4 ++ src/Notification/Check/DonateAdvisorCheck.php | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Notification/Check/DonateAdvisorCheck.php diff --git a/config/events.php b/config/events.php index 5f0047197..ebd90cb77 100644 --- a/config/events.php +++ b/config/events.php @@ -158,6 +158,10 @@ return static function (CallableEventDispatcherInterface $dispatcher) { Event\GetNotifications::class, App\Notification\Check\ProfilerAdvisorCheck::class ); + $dispatcher->addCallableListener( + Event\GetNotifications::class, + App\Notification\Check\DonateAdvisorCheck::class + ); $dispatcher->addCallableListener( Event\GetNotifications::class, App\Notification\Check\ServiceCheck::class diff --git a/src/Notification/Check/DonateAdvisorCheck.php b/src/Notification/Check/DonateAdvisorCheck.php new file mode 100644 index 000000000..8578c9867 --- /dev/null +++ b/src/Notification/Check/DonateAdvisorCheck.php @@ -0,0 +1,41 @@ +getRequest(); + + $rateLimit = $request->getRateLimit(); + try { + $rateLimit->checkRequestRateLimit($request, 'notification:donate', 600, 1); + } catch (RateLimitExceededException) { + return; + } + + $notification = new Notification(); + $notification->title = __('AzuraCast is free and open-source software.'); + $notification->body = __( + 'If you are enjoying AzuraCast, please consider donating to support our work. We depend ' . + 'on donations to build new features, fix bugs, and keep AzuraCast modern, accessible and free.', + ); + $notification->type = FlashLevels::Info->value; + + $notification->actionLabel = __('Donate to AzuraCast'); + $notification->actionUrl = 'https://donate.azuracast.com/'; + + $event->addNotification($notification); + } +}