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.

67 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. /**
  12. * New chat members command
  13. *
  14. * Gets executed when a new member joins the chat.
  15. *
  16. * NOTE: This command must be called from GenericmessageCommand.php!
  17. * It is only in a separate command file for easier code maintenance.
  18. */
  19. namespace Longman\TelegramBot\Commands\SystemCommands;
  20. use Longman\TelegramBot\Commands\SystemCommand;
  21. use Longman\TelegramBot\Entities\ServerResponse;
  22. use Longman\TelegramBot\Exception\TelegramException;
  23. class NewchatmembersCommand extends SystemCommand
  24. {
  25. /**
  26. * @var string
  27. */
  28. protected $name = 'newchatmembers';
  29. /**
  30. * @var string
  31. */
  32. protected $description = 'New Chat Members';
  33. /**
  34. * @var string
  35. */
  36. protected $version = '1.3.0';
  37. /**
  38. * Main command execution
  39. *
  40. * @return ServerResponse
  41. * @throws TelegramException
  42. */
  43. public function execute(): ServerResponse
  44. {
  45. $message = $this->getMessage();
  46. $members = $message->getNewChatMembers();
  47. if ($message->botAddedInChat()) {
  48. return $this->replyToChat('Hi there, you BOT!');
  49. }
  50. $member_names = [];
  51. foreach ($members as $member) {
  52. $member_names[] = $member->tryMention();
  53. }
  54. return $this->replyToChat('Hi ' . implode(', ', $member_names) . '!');
  55. }
  56. }