Admin and Discord Notification Improvements (#1407)
* Backend changes Sorting for : Airlines, Subfleets, Type Ratings and exported Flights Blade : Added WYSIWYG editor to flight remarks/notes field Notifications : Mails > Added enabled/disabled settings for mails. Discord > Dashed out PirepPreFiled, re-enabled PirepStatusChanged with reduced messages * Update PirepStatusChanged.php * Update NotificationEventsHandler.php * in_array fix * Fix Discord Notifications * Discord Notifications Removed the pirep url from message as it is mostly private at phpvms side. Also removed the Flight Ident from fields 'cause it is being used in the title. Added the user avatar as thumbnail, and pirep filed message uses the airline logo as the main image. Even though the outgoing pirep status messages are reduced, it is still possible to enable/disable them from admin settings. Pirep Filed is always being sent (if the webhook is defined) * StyleFix
This commit is contained in:
@@ -11,14 +11,16 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class DiscordMessage
|
||||
{
|
||||
const COLOR_SUCCESS = '#0B6623';
|
||||
const COLOR_WARNING = '#FD6A02';
|
||||
const COLOR_ERROR = '#ED2939';
|
||||
const COLOR_SUCCESS = '0B6623';
|
||||
const COLOR_WARNING = 'FD6A02';
|
||||
const COLOR_ERROR = 'ED2939';
|
||||
|
||||
public $webhook_url;
|
||||
|
||||
protected $title;
|
||||
protected $url;
|
||||
protected $thumbnail = [];
|
||||
protected $image = [];
|
||||
protected $description;
|
||||
protected $timestamp;
|
||||
protected $footer;
|
||||
@@ -26,30 +28,43 @@ class DiscordMessage
|
||||
protected $author = [];
|
||||
protected $fields = [];
|
||||
|
||||
/**
|
||||
* Supply the webhook URL that this should be going to
|
||||
*/
|
||||
// Supply the webhook URL that this should be going to
|
||||
public function webhook(string $url): self
|
||||
{
|
||||
$this->webhook_url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Title of the notification
|
||||
*/
|
||||
// Title of the embed
|
||||
public function title(string $title): self
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// URL of the Title
|
||||
public function url(string $url): self
|
||||
{
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Thumbnail image (placed right side of embed)
|
||||
// ['url' => '']
|
||||
public function thumbnail(array $thumbnail): self
|
||||
{
|
||||
$this->thumbnail = $thumbnail;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Main image (placed bottom of embed)
|
||||
// ['url' => '']
|
||||
public function image(array $image): self
|
||||
{
|
||||
$this->image = $image;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $descriptionLines
|
||||
*/
|
||||
@@ -63,22 +78,15 @@ class DiscordMessage
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the author information:
|
||||
* [
|
||||
* 'name' => '',
|
||||
* 'url' => '',
|
||||
* 'icon_url' => '',
|
||||
*/
|
||||
// Author details
|
||||
// ['name' => '', 'url' => '', 'icon_url' => '']
|
||||
public function author(array $author): self
|
||||
{
|
||||
$this->author = $author;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields
|
||||
*/
|
||||
// Fields
|
||||
public function fields(array $fields): self
|
||||
{
|
||||
$this->fields = [];
|
||||
@@ -99,32 +107,45 @@ class DiscordMessage
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Fixed Success Color
|
||||
public function success(): self
|
||||
{
|
||||
$this->color = static::COLOR_SUCCESS;
|
||||
$this->color = hexdec('0B6623'); // static::COLOR_SUCCESS;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Fixed Warning
|
||||
public function warning(): self
|
||||
{
|
||||
$this->color = static::COLOR_WARNING;
|
||||
$this->color = hexdec('FD6A02'); // static::COLOR_WARNING;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Fixed Error
|
||||
public function error(): self
|
||||
{
|
||||
$this->color = static::COLOR_ERROR;
|
||||
$this->color = hexdec('ED2939'); // static::COLOR_ERROR;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Custom Color
|
||||
public function color(string $embed_color): self
|
||||
{
|
||||
$this->color = hexdec($embed_color);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$embeds = [
|
||||
'type' => 'rich',
|
||||
'color' => $this->color,
|
||||
'title' => $this->title,
|
||||
'url' => $this->url,
|
||||
'type' => 'rich',
|
||||
'thumbnail' => $this->thumbnail,
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'image' => $this->image,
|
||||
'timestamp' => Carbon::now('UTC'),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user