✨ Add Help command
This commit is contained in:
35
bot/Commands/Help.php
Normal file
35
bot/Commands/Help.php
Normal 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)$';
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -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)?';
|
||||
}
|
||||
}
|
||||
|
@@ -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__.'/../../';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user