Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Console/Commands/BootCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laracord\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class BootCommand extends Command
Expand All @@ -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.
Expand All @@ -28,12 +31,33 @@ 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();
}

Expand Down
Loading