You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

1 year ago
  1. <?php
  2. /**
  3. * This file is part of the PHP Telegram Bot example-bot package.
  4. * https://github.com/php-telegram-bot/example-bot/
  5. *
  6. * (c) PHP Telegram Bot Team
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Longman\TelegramBot\Commands\SystemCommands;
  12. use Longman\TelegramBot\Commands\SystemCommand;
  13. use Longman\TelegramBot\Entities\ServerResponse;
  14. use Longman\TelegramBot\Exception\TelegramException;
  15. /**
  16. * Generic command
  17. *
  18. * Gets executed for generic commands, when no other appropriate one is found.
  19. */
  20. class GenericCommand extends SystemCommand
  21. {
  22. /**
  23. * @var string
  24. */
  25. protected $name = 'generic';
  26. /**
  27. * @var string
  28. */
  29. protected $description = 'Handles generic commands or is executed by default when a command is not found';
  30. /**
  31. * @var string
  32. */
  33. protected $version = '1.1.0';
  34. /**
  35. * Main command execution
  36. *
  37. * @return ServerResponse
  38. * @throws TelegramException
  39. */
  40. public function execute(): ServerResponse
  41. {
  42. $message = $this->getMessage();
  43. $user_id = $message->getFrom()->getId();
  44. $command = $message->getCommand();
  45. // To enable proper use of the /whois command.
  46. // If the user is an admin and the command is in the format "/whoisXYZ", call the /whois command
  47. if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
  48. return $this->telegram->executeCommand('whois');
  49. }
  50. return $this->replyToChat("Command /{$command} not found.. :(");
  51. }
  52. }