Skip to content

Commit

Permalink
message discord with timetable
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rn0 committed Apr 27, 2024
1 parent 8f05118 commit d8b16e1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/Models/EventTimetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use DateTime;
use Auth;

use Spatie\WebhookServer\WebhookCall;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

Expand Down Expand Up @@ -37,6 +39,20 @@ protected static function boot()
$builder->where('status', 'PUBLISHED');
});
}

self::updated(function ($model) {
if (config('app.discord_bot_url') != '' && strtolower($model->status) == "published" && $model->event->discord_link_enabled) {
WebhookCall::create()
->url(config('app.discord_bot_url') . '/message/channel')
->payload([
'channel_id' => $model->event->discord_channel_id,
'message' => "The timetable for " . $model->event->display_name . " is now live! " . config('app.url') . "/events/" . $model->event->slug
])
->useSecret(config('app.discord_bot_secret'))
->dispatch();
}
return true;
});
}

/*
Expand Down

0 comments on commit d8b16e1

Please sign in to comment.