Added missing help command

This commit adds the missing help command for the bot.
This commit is contained in:
Miguel Nogueira 2020-12-25 16:38:27 +00:00
parent 4911163c71
commit 2a2d2a0b7e
4 changed files with 55 additions and 2 deletions

8
Commandfiles/help.txt Normal file
View File

@ -0,0 +1,8 @@
:white_check_mark: Raspberry Bot Command Help :arrow_down:
Active prefix: <prefix>
Available commands:
- numberfact [random/ (int) number] (Example: <prefix> numberfact 20)
- help (This command)

5
bot.php Normal file → Executable file
View File

@ -1,9 +1,11 @@
#!/usr/bin/env php
<?php
use nogueiracodes\RaspberryBot\Bot\Actions\MessageLogger;
use nogueiracodes\RaspberryBot\Bot\Commands\MinecraftInfo;
use nogueiracodes\RaspberryBot\Bot\Commands\NumberFact;
use nogueiracodes\RaspberryBot\Bot\Commands\SimplePlayback;
use nogueiracodes\RaspberryBot\Bot\Commands\Help;
use nogueiracodes\RaspberryBot\Core\RaspberryBot;
require 'src/Bot/init.php';
@ -18,7 +20,8 @@ $raspberryBot
->addCommand([
new SimplePlayback,
new NumberFact,
new MinecraftInfo
new MinecraftInfo,
new Help
])
->addAction(new MessageLogger)
->setCommandPrefix($_ENV['COMMAND_PREFIX'])

41
src/Bot/Commands/Help.php Normal file
View File

@ -0,0 +1,41 @@
<?php
namespace nogueiracodes\RaspberryBot\Bot\Commands;
use Exception;
use nogueiracodes\RaspberryBot\Core\Interfaces\Command;
use nogueiracodes\RaspberryBot\Traits\HasSignature;
use Zttp\Zttp;
class Help implements Command
{
use HasSignature;
public $signature = "help {section: The section to retrieve help for}";
public function run(array $parameters)
{
switch($parameters['section'])
{
case "commands":
if(file_exists(PROJECT_ROOT . "/Commandfiles/help.txt"))
{
return str_replace("<prefix>", $_ENV['COMMAND_PREFIX'], file_get_contents(PROJECT_ROOT . "/Commandfiles/help.txt"));
}
else
{
return ":x: There is currently no available help.";
}
break;
default:
return ":x: There is no help section named " . $parameters['section'] . ".";
break;
}
}
}

View File

@ -8,3 +8,4 @@ $dotenv->load();
$dotenv->required('BOT_AUTH_TOKEN')->notEmpty();
$dotenv->required('COMMAND_PREFIX')->notEmpty();
define('PROJECT_ROOT', realpath(__DIR__ . '/../../'));