Add Help command

This commit is contained in:
2024-08-07 17:05:07 +02:00
parent 60f18f2f76
commit 1aa26c836a
6 changed files with 66 additions and 16 deletions

35
bot/Commands/Help.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace Shikiryu\Bot\Commands;
use Shikiryu\Bot\Bot;
class Help implements Icommands
{
public static function getMessage(Bot $bot, array $data): void
{
$message = 'Voici la liste de mes commandes : '."\n";
foreach ($bot->listCommands() as $command) {
$message .= sprintf(
'%s : %s (%s)%s',
$command,
call_user_func([$command, 'getDescription']),
call_user_func([$command, 'getPattern']),
"\n"
);
}
$bot->replyPolitely($message);
}
public static function getDescription(): string
{
return 'Affiche les commandes à lancer';
}
public static function getPattern(): string
{
return '^(help|aide|liste des commandes)$';
}
}

View File

@@ -8,8 +8,7 @@ interface Icommands
{
public static function getMessage(Bot $bot, array $data);
/**
* @return string
*/
public static function getDescription();
public static function getDescription(): string;
public static function getPattern(): string;
}

View File

@@ -14,8 +14,13 @@ class Lorem implements Icommands
/**
* @return string
*/
public static function getDescription()
public static function getDescription(): string
{
return 'Génère du lorem ipsum';
}
public static function getPattern(): string
{
return 'lorem( ipsum)?';
}
}

View File

@@ -49,6 +49,11 @@ class Youtubedl implements Icommands
return 'Youtubedl wrapper';
}
public static function getPattern(): string
{
return '(convertis|télécharges?) (https?:\/\/[^\s]+) en (audio|video|vidéo)';
}
private static function getYoutubeDl(Bot $bot): string
{
$youtubedl_bin = $bot->getConfig()['youtube-dl']['bin'];
@@ -64,5 +69,4 @@ class Youtubedl implements Icommands
{
return $bot->getConfig()['youtube-dl']['download_folder'] ?? __DIR__.'/../../';
}
}