diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 3803687..d21ba39 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -70,7 +70,7 @@ public function maybeHandle($message, $args) * * @param \Discord\Parts\Channel\Message $message * @param array $args - * @return void + * @return mixed */ abstract public function handle($message, $args); diff --git a/src/Commands/ContextMenu.php b/src/Commands/ContextMenu.php index 016e3a9..37de1fd 100644 --- a/src/Commands/ContextMenu.php +++ b/src/Commands/ContextMenu.php @@ -2,7 +2,10 @@ namespace Laracord\Commands; +use Discord\Parts\Channel\Message; use Discord\Parts\Interactions\Command\Command as DiscordCommand; +use Discord\Parts\Interactions\Interaction; +use Discord\Parts\User\User; use Laracord\Commands\Contracts\ContextMenu as ContextMenuContract; abstract class ContextMenu extends ApplicationCommand implements ContextMenuContract @@ -32,22 +35,25 @@ public function create(): DiscordCommand /** * Handle the context menu interaction. - * - * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void */ - abstract public function handle($interaction); + abstract public function handle(Interaction $interaction, Message|User|null $target): mixed; /** * Maybe handle the context menu interaction. * * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void + * @return mixed */ public function maybeHandle($interaction) { + $target = match ($this->getType()) { + DiscordCommand::USER => $interaction->data->resolved->users?->first(), + DiscordCommand::MESSAGE => $interaction->data->resolved->messages?->first(), + default => null, + }; + if (! $this->isAdminCommand()) { - $this->handle($interaction); + $this->handle($interaction, $target); return; } @@ -63,7 +69,7 @@ public function maybeHandle($interaction) ); } - $this->handle($interaction); + $this->handle($interaction, $target); } /** diff --git a/src/Commands/Contracts/ContextMenu.php b/src/Commands/Contracts/ContextMenu.php index f00db11..d45c664 100644 --- a/src/Commands/Contracts/ContextMenu.php +++ b/src/Commands/Contracts/ContextMenu.php @@ -2,12 +2,14 @@ namespace Laracord\Commands\Contracts; +use Discord\Parts\Channel\Message; use Discord\Parts\Interactions\Interaction; +use Discord\Parts\User\User; interface ContextMenu { /** * Handle the context menu interaction. */ - public function handle(Interaction $interaction); + public function handle(Interaction $interaction, Message|User|null $target): mixed; } diff --git a/src/Commands/SlashCommand.php b/src/Commands/SlashCommand.php index 131affd..b0c4dc4 100644 --- a/src/Commands/SlashCommand.php +++ b/src/Commands/SlashCommand.php @@ -69,7 +69,7 @@ public function create(): DiscordCommand * Handle the slash command. * * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void + * @return mixed */ abstract public function handle($interaction); @@ -77,7 +77,7 @@ abstract public function handle($interaction); * Maybe handle the slash command. * * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void + * @return mixed */ public function maybeHandle($interaction) { diff --git a/src/Console/Commands/MakeCommand.php b/src/Console/Commands/MakeCommand.php index 0632e59..f535edc 100644 --- a/src/Console/Commands/MakeCommand.php +++ b/src/Console/Commands/MakeCommand.php @@ -43,7 +43,11 @@ protected function replaceClass($stub, $name) $command = $this->option('command') ?: Str::of($name)->classBasename()->kebab()->value(); - return str_replace(['dummy:command', '{{ command }}'], $command, $stub); + $title = Str::of($command)->replace('-', ' ')->apa(); + + $stub = str_replace(['dummy:command', '{{ command }}', '{{ title }}'], [$command, $command, $title], $stub); + + return $stub; } /** diff --git a/src/Console/Commands/MakeMenuCommand.php b/src/Console/Commands/MakeMenuCommand.php index 5562212..4b59065 100644 --- a/src/Console/Commands/MakeMenuCommand.php +++ b/src/Console/Commands/MakeMenuCommand.php @@ -43,7 +43,11 @@ protected function replaceClass($stub, $name) $command = $this->option('command') ?: Str::of($name)->classBasename()->kebab()->value(); - return str_replace(['dummy:command', '{{ command }}'], $command, $stub); + $title = Str::of($command)->replace('-', ' ')->apa(); + + $stub = str_replace(['dummy:command', '{{ command }}', '{{ title }}'], [$command, $command, $title], $stub); + + return $stub; } /** diff --git a/src/Console/Commands/MakeSlashCommand.php b/src/Console/Commands/MakeSlashCommand.php index 3b09017..bd3fe4d 100644 --- a/src/Console/Commands/MakeSlashCommand.php +++ b/src/Console/Commands/MakeSlashCommand.php @@ -43,7 +43,11 @@ protected function replaceClass($stub, $name) $command = $this->option('command') ?: Str::of($name)->classBasename()->kebab()->value(); - return str_replace(['dummy:command', '{{ command }}'], $command, $stub); + $title = Str::of($command)->replace('-', ' ')->apa(); + + $stub = str_replace(['dummy:command', '{{ command }}', '{{ title }}'], [$command, $command, $title], $stub); + + return $stub; } /** diff --git a/src/Console/Commands/stubs/command.stub b/src/Console/Commands/stubs/command.stub index c2123ed..1b9ed01 100644 --- a/src/Console/Commands/stubs/command.stub +++ b/src/Console/Commands/stubs/command.stub @@ -19,7 +19,7 @@ class {{ class }} extends Command * * @var string */ - protected $description = 'The {{ command }} command.'; + protected $description = 'The {{ title }} command.'; /** * Determines whether the command requires admin permissions. @@ -46,7 +46,7 @@ class {{ class }} extends Command { return $this ->message() - ->title('{{ class }}') + ->title('{{ title }}') ->content('Hello world!') ->button('👋', route: 'wave') ->send($message); diff --git a/src/Console/Commands/stubs/context-menu.stub b/src/Console/Commands/stubs/context-menu.stub index 15ee39e..2f5dbc9 100644 --- a/src/Console/Commands/stubs/context-menu.stub +++ b/src/Console/Commands/stubs/context-menu.stub @@ -2,7 +2,9 @@ namespace {{ namespace }}; +use Discord\Parts\Channel\Message; use Discord\Parts\Interactions\Interaction; +use Discord\Parts\User\User; use Laracord\Commands\ContextMenu; class {{ class }} extends ContextMenu @@ -12,7 +14,7 @@ class {{ class }} extends ContextMenu * * @var string */ - protected $name = '{{ command }}'; + protected $name = '{{ title }}'; /** * The context menu type. @@ -35,16 +37,13 @@ class {{ class }} extends ContextMenu /** * Handle the context menu interaction. - * - * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void */ - public function handle($interaction) + public function handle(Interaction $interaction, Message|User|null $target): mixed { $interaction->respondWithMessage( $this ->message() - ->title('{{ class }}') + ->title('{{ title }}') ->content('Hello world!') ->button('👋', route: 'wave') ->build() diff --git a/src/Console/Commands/stubs/event.stub b/src/Console/Commands/stubs/event.stub index 0f03934..7d11bf9 100644 --- a/src/Console/Commands/stubs/event.stub +++ b/src/Console/Commands/stubs/event.stub @@ -17,7 +17,7 @@ class {{ class }} extends Event /** * Handle the event. */ - public function handle({{ attributes }}) + public function handle({{ attributes }}): mixed { $this->console()->log('The {{ eventName }} event has fired!'); } diff --git a/src/Console/Commands/stubs/service.stub b/src/Console/Commands/stubs/service.stub index 0e12ab1..4abe148 100644 --- a/src/Console/Commands/stubs/service.stub +++ b/src/Console/Commands/stubs/service.stub @@ -14,7 +14,7 @@ class {{ class }} extends Service /** * Handle the service. */ - public function handle(): void + public function handle(): mixed { $this->console()->log('Hello world.'); } diff --git a/src/Console/Commands/stubs/slash-command.stub b/src/Console/Commands/stubs/slash-command.stub index f2aeaf6..81e4467 100644 --- a/src/Console/Commands/stubs/slash-command.stub +++ b/src/Console/Commands/stubs/slash-command.stub @@ -19,7 +19,7 @@ class {{ class }} extends SlashCommand * * @var string */ - protected $description = 'The {{ command }} slash command.'; + protected $description = 'The {{ title }} slash command.'; /** * The command options. @@ -53,14 +53,14 @@ class {{ class }} extends SlashCommand * Handle the slash command. * * @param \Discord\Parts\Interactions\Interaction $interaction - * @return void + * @return mixed */ public function handle($interaction) { $interaction->respondWithMessage( $this ->message() - ->title('{{ class }}') + ->title('{{ title }}') ->content('Hello world!') ->button('👋', route: 'wave') ->build() diff --git a/src/Services/Contracts/Service.php b/src/Services/Contracts/Service.php index 6825c9b..1d03229 100644 --- a/src/Services/Contracts/Service.php +++ b/src/Services/Contracts/Service.php @@ -6,6 +6,8 @@ interface Service { /** * Handle the service. + * + * @return mixed */ public function handle(); } diff --git a/src/Services/Service.php b/src/Services/Service.php index 32505ce..153e5c2 100644 --- a/src/Services/Service.php +++ b/src/Services/Service.php @@ -71,7 +71,7 @@ public static function make(Laracord $bot): self /** * Handle the service. * - * @return void + * @return mixed */ abstract public function handle();