diff --git a/src/Message.php b/src/Message.php index f11f0db..bd1cc87 100644 --- a/src/Message.php +++ b/src/Message.php @@ -22,6 +22,7 @@ class Message implements \JsonSerializable private Model $o; private Blocks $blocks; + private ?Carbon $selfdestruct = NULL; /** * Message constructor. @@ -127,6 +128,9 @@ class Message implements \JsonSerializable */ public function post(Carbon $delete=NULL): Generic { + if (! $delete && $this->selfdestruct) + $delete = $this->selfdestruct; + if ($this->_data->has('ephemeral')) abort('500','Cannot post ephemeral messages.'); @@ -212,22 +216,22 @@ class Message implements \JsonSerializable * Make the message self destruct * * @param Carbon $time - * @return Generic - * @throws \Exception + * @return Message */ - public function selfdestruct(Carbon $time): Generic + public function selfdestruct(Carbon $time): self { - $this->blocks->addContextElements( - collect() - ->push(Blocks\Text::item(sprintf('This message will self destruct in %s...',$time->diffForHumans(Carbon::now(),['syntax' => CarbonInterface::DIFF_RELATIVE_TO_NOW]))))); + $this->blocks->addContextElements(collect([ + Blocks\Text::item(sprintf('This message will self destruct in %s...',$time->diffForHumans(Carbon::now(),['syntax' => CarbonInterface::DIFF_RELATIVE_TO_NOW]))) + ])); - return $this->post($time); + $this->selfdestruct = $time; + return $this; } /** * Add an attachment to a message * - * @param Attachment $attachments + * @param Attachments $attachments * @return Message */ public function setAttachments(Attachments $attachments): self