mirror of
https://gitlab.com/ArkHost/WHMCS-Discord-Notifications.git
synced 2026-07-24 07:45:54 +02:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace WHMCS\Module\Notification\Discord;
|
||||
|
||||
class Embed
|
||||
{
|
||||
public $title = "";
|
||||
public $url = "";
|
||||
public $description = "";
|
||||
public $fields = null;
|
||||
public $timestamp = "";
|
||||
public $color = "";
|
||||
public $footer = array();
|
||||
|
||||
public function title($title)
|
||||
{
|
||||
$this->title = trim($title);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function url($url)
|
||||
{
|
||||
$this->url = trim($url);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function description($description)
|
||||
{
|
||||
$this->description = trim($description);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function timestamp($timestamp)
|
||||
{
|
||||
$this->timestamp = trim($timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function color($color)
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function footer($footertext, $icon = "")
|
||||
{
|
||||
$this->footer["text"] = trim($footertext);
|
||||
if (!empty($icon)) {
|
||||
$this->footer["icon_url"] = trim($icon);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addField(Field $field)
|
||||
{
|
||||
if ($this->fields === null) {
|
||||
$this->fields = array();
|
||||
}
|
||||
$this->fields[] = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$embed = [];
|
||||
|
||||
if (!empty($this->title)) {
|
||||
$embed["title"] = $this->title;
|
||||
}
|
||||
if (!empty($this->url)) {
|
||||
$embed["url"] = $this->url;
|
||||
}
|
||||
if (!empty($this->description)) {
|
||||
$embed["description"] = $this->description;
|
||||
}
|
||||
if (!empty($this->timestamp)) {
|
||||
$embed["timestamp"] = $this->timestamp;
|
||||
}
|
||||
if (!empty($this->color)) {
|
||||
$embed["color"] = $this->color;
|
||||
}
|
||||
if (!empty($this->footer)) {
|
||||
$embed["footer"] = $this->footer;
|
||||
}
|
||||
|
||||
if (!empty($this->fields)) {
|
||||
$embed["fields"] = array_map(function (Field $field) {
|
||||
return $field->toArray();
|
||||
}, $this->fields);
|
||||
}
|
||||
|
||||
return $embed;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace WHMCS\Module\Notification\Discord;
|
||||
|
||||
class Field
|
||||
{
|
||||
public $name = "";
|
||||
public $value = "";
|
||||
public $inline = true;
|
||||
|
||||
public function name($name)
|
||||
{
|
||||
$this->name = trim($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function value($value)
|
||||
{
|
||||
$this->value = trim($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function inline($inline)
|
||||
{
|
||||
$this->inline = (bool) $inline;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'value' => $this->value,
|
||||
'inline' => $this->inline
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace WHMCS\Module\Notification\Discord;
|
||||
|
||||
class Message
|
||||
{
|
||||
public $content = "";
|
||||
public $username = "";
|
||||
public $avatarUrl = "";
|
||||
public $embeds = array();
|
||||
|
||||
public function content($content)
|
||||
{
|
||||
$this->content = trim($content);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function username($username)
|
||||
{
|
||||
$this->username = trim($username);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function avatarUrl($avatarUrl)
|
||||
{
|
||||
$this->avatarUrl = trim($avatarUrl);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function embed($embed)
|
||||
{
|
||||
$this->embeds[] = $embed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$message = array();
|
||||
|
||||
if (!empty($this->content)) {
|
||||
$message["content"] = $this->content;
|
||||
}
|
||||
if (!empty($this->avatarUrl)) {
|
||||
$message["avatar_url"] = $this->avatarUrl;
|
||||
}
|
||||
if (!empty($this->username)) {
|
||||
$message["username"] = $this->username;
|
||||
}
|
||||
if (!empty($this->embeds)) {
|
||||
$message["embeds"] = array_map(function($embed) {
|
||||
return $embed instanceof Embed ? $embed->toArray() : $embed;
|
||||
}, $this->embeds);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user