Skip to content

Commit

Permalink
Merge pull request #4 from m7rlin/dev
Browse files Browse the repository at this point in the history
Update for PHP7; Add Embed support
  • Loading branch information
m7rlin authored Sep 23, 2019
2 parents ccfff75 + 6d88e58 commit f4542be
Show file tree
Hide file tree
Showing 4 changed files with 684 additions and 61 deletions.
178 changes: 178 additions & 0 deletions lib/DiscordEmbed-v7.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

/**
* Discord Embed is a part of DiscordWebhook library.
*/
final class DiscordEmbed
{
protected $title;
protected $type = "rich";
protected $description;
protected $url;
protected $timestamp;
protected $color;
protected $footer;
protected $image;
protected $thumbnail;
protected $video;
protected $provider;
protected $author;
protected $fields;

/**
* Set the title and the url
*
* @param string $title
* @param string $url
* @return self|null
*/
function setTitle($title, $url = "") {
$this->title = $title;
$this->url = $url;

return $this;
}

/**
* Set description
*
* @param string $description
* @return self
*/
function setDescription($description) {
$this->description = $description;

return $this;
}
/**
* Set timestamp of the embed
*
* @param [type] $timestamp
* @return self
*/
function setTimestamp($timestamp) {
$this->timestamp = $timestamp;

return $this;
}
/**
* Set border color
*
* @param string $color
* @return self
*/
function setColor($color) {
$this->color = is_int($color) ? $color : hexdec($color);

return $this;
}
/**
* Set url
*
* @param string $url
* @return self
*/
function setUrl($url) {
$this->url = $url;

return $this;
}
/**
* Set footer
*
* @param string $text
* @param string $icon_url
* @return self
*/
function setFooter($text, $icon_url = "") {
$this->footer = [
"text" => $text,
"icon_url" => $icon_url,
];

return $this;
}
/**
* Set image
*
* @param string $url
* @return self
*/
function setImage($url) {
$this->image = [
"url" => $url,
];

return $this;
}
/**
* Set thumbnail
*
* @param string $url
* @return self
*/
function setThumbnail($url) {
$this->thumbnail = [
"url" => $url,
];

return $this;
}
/**
* Set author
*
* @param string $name
* @param string $url
* @param string $icon_url
* @return self
*/
function setAuthor($name, $url = "", $icon_url = "") {
$this->author = [
"name" => $name,
"url" => $url,
"icon_url" => $icon_url,
];

return $this;
}
/**
* Set field
*
* @param string $name
* @param string $value
* @param boolean $inline
* @return self
*/
function setField($name, $value = "", $inline = false) {
$this->fields[] = [
'name' => $name,
'value' => $value,
'inline' => boolval($inline),
];

return $this;
}
/**
* Get fields as an array
*
* @return array
*/
function toArray() {
return [
'title' => $this->title,
'type' => $this->type,
'description' => $this->description,
'url' => $this->url,
'color' => $this->color,
'footer' => $this->footer,
'image' => $this->image,
'thumbnail' => $this->thumbnail,
'timestamp' => $this->timestamp,
'author' => $this->author,
'fields' => $this->fields
];
}


}
?>
178 changes: 178 additions & 0 deletions lib/DiscordEmbed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

/**
* Discord Embed is a part of DiscordWebhook library.
*/
final class DiscordEmbed
{
protected $title;
protected $type = "rich";
protected $description;
protected $url;
protected $timestamp;
protected $color;
protected $footer;
protected $image;
protected $thumbnail;
protected $video;
protected $provider;
protected $author;
protected $fields;

/**
* Set the title and the url
*
* @param string $title
* @param string $url
* @return self|null
*/
function setTitle(string $title, string $url = ""): self {
$this->title = $title;
$this->url = $url;

return $this;
}

/**
* Set description
*
* @param string $description
* @return self
*/
function setDescription(string $description): self {
$this->description = $description;

return $this;
}
/**
* Set timestamp of the embed
*
* @param [type] $timestamp
* @return self
*/
function setTimestamp($timestamp): self {
$this->timestamp = $timestamp;

return $this;
}
/**
* Set border color
*
* @param string $color
* @return self
*/
function setColor(string $color): self {
$this->color = is_int($color) ? $color : hexdec($color);

return $this;
}
/**
* Set url
*
* @param string $url
* @return self
*/
function setUrl(string $url): self {
$this->url = $url;

return $this;
}
/**
* Set footer
*
* @param string $text
* @param string $icon_url
* @return self
*/
function setFooter(string $text, string $icon_url = ""): self {
$this->footer = [
"text" => $text,
"icon_url" => $icon_url,
];

return $this;
}
/**
* Set image
*
* @param string $url
* @return self
*/
function setImage(string $url): self {
$this->image = [
"url" => $url,
];

return $this;
}
/**
* Set thumbnail
*
* @param string $url
* @return self
*/
function setThumbnail(string $url): self {
$this->thumbnail = [
"url" => $url,
];

return $this;
}
/**
* Set author
*
* @param string $name
* @param string $url
* @param string $icon_url
* @return self
*/
function setAuthor(string $name, string $url = "", string $icon_url = ""): self {
$this->author = [
"name" => $name,
"url" => $url,
"icon_url" => $icon_url,
];

return $this;
}
/**
* Set field
*
* @param string $name
* @param string $value
* @param boolean $inline
* @return self
*/
function setField(string $name, string $value = "", bool $inline = false): self {
$this->fields[] = [
'name' => $name,
'value' => $value,
'inline' => boolval($inline),
];

return $this;
}
/**
* Get fields as an array
*
* @return array
*/
function toArray(): array {
return [
'title' => $this->title,
'type' => $this->type,
'description' => $this->description,
'url' => $this->url,
'color' => $this->color,
'footer' => $this->footer,
'image' => $this->image,
'thumbnail' => $this->thumbnail,
'timestamp' => $this->timestamp,
'author' => $this->author,
'fields' => $this->fields
];
}


}
?>
Loading

0 comments on commit f4542be

Please sign in to comment.