alfred-nextcloud/bot/Commands/Help.php

38 lines
955 B
PHP
Raw Permalink Normal View History

2024-08-07 17:05:07 +02:00
<?php
namespace Shikiryu\Bot\Commands;
use Shikiryu\Bot\Bot;
class Help implements Icommands
{
public static function getMessage(Bot $bot, array $data): void
{
2024-08-07 17:46:01 +02:00
$bot->replyPolitely('Voici la liste de mes commandes');
$message = '|Nom|Description|Pattern|'."\n";
$message .= '|---|---|---|'."\n";
2024-08-07 17:05:07 +02:00
foreach ($bot->listCommands() as $command) {
$message .= sprintf(
2024-08-07 17:46:01 +02:00
'|%s|%s|`%s`|%s',
end(explode('\\', $command)),
2024-08-07 17:05:07 +02:00
call_user_func([$command, 'getDescription']),
2024-08-07 17:46:01 +02:00
str_replace('|', '\|', call_user_func([$command, 'getPattern'])),
2024-08-07 17:05:07 +02:00
"\n"
);
}
2024-08-07 17:46:01 +02:00
$bot->reply($message);
2024-08-07 17:05:07 +02:00
}
public static function getDescription(): string
{
return 'Affiche les commandes à lancer';
}
public static function getPattern(): string
{
return '^(help|aide|liste des commandes)$';
}
}