From 4f000c40a5bec363175e01fbe598622efe3bc7ea Mon Sep 17 00:00:00 2001 From: Vijay Tupakula Date: Fri, 12 Jul 2024 11:16:38 +0530 Subject: [PATCH] Adds slash commands, allows to run commands while in chat mode --- app/Commands/DroidCommand.php | 19 +++++++++++++++---- tests/Feature/InspireCommandTest.php | 5 ----- 2 files changed, 15 insertions(+), 9 deletions(-) delete mode 100755 tests/Feature/InspireCommandTest.php diff --git a/app/Commands/DroidCommand.php b/app/Commands/DroidCommand.php index f397ab5..1dcbd00 100644 --- a/app/Commands/DroidCommand.php +++ b/app/Commands/DroidCommand.php @@ -3,6 +3,7 @@ namespace App\Commands; use App\Services\ChatAssistant; +use App\Tools\ExecuteCommand; use App\Utils\OnBoardingSteps; use Exception; use Illuminate\Console\Command; @@ -13,7 +14,14 @@ class DroidCommand extends Command { public $signature = 'droid'; - public $description = 'Allows you to create/update a feature'; + public $description = 'Allows you to create/update a feature and run commands'; + + public function __construct( + private readonly ChatAssistant $chatAssistant, + private readonly ExecuteCommand $executeCommand + ) { + parent::__construct(); + } /** * @throws Exception @@ -25,8 +33,7 @@ public function handle(): int return self::FAILURE; } - $chatAssistant = new ChatAssistant; - $thread = $chatAssistant->createThread(); + $thread = $this->chatAssistant->createThread(); while (true) { $message = ask('🍻:'); @@ -35,7 +42,11 @@ public function handle(): int break; } - $chatAssistant->getAnswer($thread, $message); + if (str_starts_with($message, '/')) { + $this->executeCommand->handle(substr($message, 1)); + } else { + $this->chatAssistant->getAnswer($thread, $message); + } } return self::SUCCESS; diff --git a/tests/Feature/InspireCommandTest.php b/tests/Feature/InspireCommandTest.php deleted file mode 100755 index 57642b2..0000000 --- a/tests/Feature/InspireCommandTest.php +++ /dev/null @@ -1,5 +0,0 @@ -artisan('inspire')->assertExitCode(0); -});