Commit d1a5946a authored by Armando Lüscher's avatar Armando Lüscher

Rewrite help command to reflect changes in the command logic.

parent 884830eb
...@@ -38,44 +38,38 @@ class HelpCommand extends UserCommand ...@@ -38,44 +38,38 @@ class HelpCommand extends UserCommand
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$text = $message->getText(true); $command = trim($message->getText(true));
$commands = $this->telegram->getCommandsList(); //Only get enabled Admin and User commands
$commands = array_filter($this->telegram->getCommandsList(), function ($command) {
return (!$command->isSystemCommand() && $command->isEnabled());
});
if (empty($text)) { //If no command parameter is passed, show the list
$msg = $this->telegram->getBotName() . ' v. ' . $this->telegram->getVersion() . "\n\n"; if ($command === '') {
$msg .= 'Commands List:' . "\n"; $text = $this->telegram->getBotName() . ' v. ' . $this->telegram->getVersion() . "\n\n";
$text .= 'Commands List:' . "\n";
foreach ($commands as $command) { foreach ($commands as $command) {
if (is_object($command)) { $text .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n";
if (!$command->isEnabled()) {
continue;
} }
$msg .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n"; $text .= "\n" . 'For exact command help type: /help <command>';
}
}
$msg .= "\n" . 'For exact command help type: /help <command>';
} else { } else {
$text = str_replace('/', '', $text); $command = str_replace('/', '', $command);
if (isset($commands[$text])) { if (isset($commands[$command])) {
$command = $commands[$text]; $command = $commands[$command];
if (!$command->isEnabled()) { $text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n";
$msg = 'Command ' . $text . ' not found'; $text .= 'Description: ' . $command->getDescription() . "\n";
} else { $text .= 'Usage: ' . $command->getUsage();
$msg = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n";
$msg .= 'Description: ' . $command->getDescription() . "\n";
$msg .= 'Usage: ' . $command->getUsage();
}
} else { } else {
$msg = 'Command ' . $text . ' not found'; $text = 'No help available: Command /' . $command . ' not found';
} }
} }
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'reply_to_message_id' => $message_id, 'reply_to_message_id' => $message_id,
'text' => $msg, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data)->isOk();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment