From 624c999f2a63daf54083af44569e60feb35fedb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marky=20=E3=82=B8=E3=83=A3?= Date: Tue, 5 Nov 2024 00:15:53 +0000 Subject: [PATCH 1/2] Support for passing bot name and token --- src/Console/Commands/BootCommand.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/BootCommand.php b/src/Console/Commands/BootCommand.php index 2c01427..efd5d73 100644 --- a/src/Console/Commands/BootCommand.php +++ b/src/Console/Commands/BootCommand.php @@ -3,6 +3,7 @@ namespace Laracord\Console\Commands; use Illuminate\Support\Str; +use Illuminate\Console\Command; class BootCommand extends Command { @@ -12,7 +13,9 @@ class BootCommand extends Command * @var string */ protected $signature = 'bot:boot - {--no-migrate : Boot without running database migrations}'; + {--no-migrate : Boot without running database migrations} + {--bot_name= : The name of the bot} + {--bot_token= : The token of the bot}'; /** * The description of the command. @@ -28,12 +31,31 @@ class BootCommand extends Command */ public function handle() { + // Run migrations unless --no-migrate is specified if (! $this->option('no-migrate')) { $this->callSilent('migrate', ['--force' => true]); } - $this->app->singleton('bot', fn () => $this->getClass()::make($this)); + // Retrieve bot name and token from options or environment + $botName = $this->option('bot_name') ?? config('discord.description'); + $botToken = $this->option('bot_token') ?? config('discord.token'); + // Check if bot token is provided + if (empty($botToken)) { + $this->error('Bot token is required.'); + return; + } + + // Set the bot name and token in the environment dynamically + config(['discord.description' => $botName, 'discord.token' => $botToken]); + + // Create the bot instance using singleton with the bot name and token + $this->app->singleton('bot', function () { + $botClass = $this->getClass(); + return $botClass::make($this, config('discord.description'), config('discord.token')); + }); + + // Boot the bot $this->app->make('bot')->boot(); } @@ -42,7 +64,7 @@ public function handle() */ protected function getClass(): string { - $class = Str::start($this->app->getNamespace(), '\\').'Bot'; + $class = Str::start($this->app->getNamespace(), '\\') . 'Bot'; return class_exists($class) ? $class : 'Laracord'; } From ec4367b2e9885fd59d712f05856ec1ac3b58130f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marky=20=E3=82=B8=E3=83=A3?= Date: Tue, 5 Nov 2024 00:47:40 +0000 Subject: [PATCH 2/2] Laravel Pint --- src/Console/Commands/BootCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/BootCommand.php b/src/Console/Commands/BootCommand.php index efd5d73..045b8b5 100644 --- a/src/Console/Commands/BootCommand.php +++ b/src/Console/Commands/BootCommand.php @@ -2,8 +2,8 @@ namespace Laracord\Console\Commands; -use Illuminate\Support\Str; use Illuminate\Console\Command; +use Illuminate\Support\Str; class BootCommand extends Command { @@ -43,6 +43,7 @@ public function handle() // Check if bot token is provided if (empty($botToken)) { $this->error('Bot token is required.'); + return; } @@ -52,6 +53,7 @@ public function handle() // Create the bot instance using singleton with the bot name and token $this->app->singleton('bot', function () { $botClass = $this->getClass(); + return $botClass::make($this, config('discord.description'), config('discord.token')); }); @@ -64,7 +66,7 @@ public function handle() */ protected function getClass(): string { - $class = Str::start($this->app->getNamespace(), '\\') . 'Bot'; + $class = Str::start($this->app->getNamespace(), '\\').'Bot'; return class_exists($class) ? $class : 'Laracord'; }