Skip to content

Commit a3fde2f

Browse files
committed
[Feature] Notify Discord user when speedtest threshold is breached
1 parent fe93d5b commit a3fde2f

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

app/Filament/Pages/Settings/NotificationPage.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ public function form(Form $form): Form
176176
->url(),
177177
])
178178
->columnSpanFull(),
179+
Forms\Components\Fieldset::make('discord_user_mention')
180+
->label('User Id to mention if threshold is hit')
181+
->schema([
182+
Forms\Components\TextInput::make('discord_user_mention')
183+
->label('Mention ID')
184+
->maxLength(18),
185+
]),
179186
Forms\Components\Actions::make([
180187
Forms\Components\Actions\Action::make('test discord')
181188
->label('Test Discord webhook')

app/Listeners/Discord/SendSpeedtestThresholdNotification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function handle(SpeedtestCompleted $event): void
7171
'metrics' => $failed,
7272
'speedtest_url' => $event->result->result_url,
7373
'url' => url('/admin/results'),
74+
'mentionUser' => $notificationSettings->discord_user_mention,
7475
])->render(),
7576
];
7677

app/Settings/NotificationSettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class NotificationSettings extends Settings
4646

4747
public ?array $discord_webhooks;
4848

49+
public ?string $discord_user_mention;
50+
4951
public bool $ntfy_enabled;
5052

5153
public bool $ntfy_on_speedtest_run;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Spatie\LaravelSettings\Migrations\SettingsMigration;
4+
5+
return new class extends SettingsMigration
6+
{
7+
public function up(): void
8+
{
9+
$this->migrator->add('notification.discord_user_mention', null);
10+
}
11+
12+
public function down(): void
13+
{
14+
$this->migrator->delete('notification.discord_user_mention');
15+
}
16+
};

resources/views/discord/speedtest-threshold.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
**Speedtest Threshold Breached - #{{ $id }}**
22

3+
@if (!empty($mentionUser))
4+
{!! "<@{$mentionUser}>" !!}
5+
@endif
6+
37
A new speedtest on **{{ config('app.name') }}** was completed using **{{ $service }}** on **{{ $isp }}** but a threshold was breached.
48

59
@foreach ($metrics as $item)

0 commit comments

Comments
 (0)