This commit is contained in:
Adrian Hopek
2022-04-25 13:23:49 +02:00
parent 851a52fe32
commit 25816cc47a
28 changed files with 531 additions and 239 deletions

View File

@@ -4,42 +4,31 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Collection;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\AttachmentField;
use Spatie\SlashCommand\Handlers\Help as BaseHelpHandler;
use Spatie\SlashCommand\Handlers\SignatureHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Slack\SignatureHandler;
use Toby\Domain\Slack\Traits\ListsHandlers;
class Help extends BaseHelpHandler
class Help extends SignatureHandler
{
use ListsHandlers;
protected $signature = "toby pomoc";
protected $description = "Wyświetl wszystkie dostępne komendy tobiego";
protected $description = "Wyświetl wszystkie dostępne komendy";
public function handle(Request $request): Response
{
$handlers = $this->findAvailableHandlers();
return $this->displayListOfAllCommands($handlers);
}
$attachmentFields = $this->mapHandlersToAttachments($handlers);
protected function displayListOfAllCommands(Collection $handlers): Response
{
$attachmentFields = $handlers
->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) {
return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand());
})
->map(function (SignatureHandler $handler) {
return AttachmentField::create("/{$handler->getSignature()}", $handler->getDescription());
})
->all();
return $this->respondToSlack('Dostępne komendy')
return $this->respondToSlack("Dostępne komendy:")
->withAttachment(
Attachment::create()
->setColor('good')
->setFields($attachmentFields)
->setColor("good")
->useMarkdown()
->setFields($attachmentFields),
);
}
}