|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of the TelegramBot package. |
| 4 | + * |
| 5 | + * (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + * |
| 10 | +*/ |
| 11 | +namespace Longman\TelegramBot\Commands; |
| 12 | + |
| 13 | +use Longman\TelegramBot\Request; |
| 14 | +use Longman\TelegramBot\Command; |
| 15 | +use Longman\TelegramBot\Entities\Update; |
| 16 | + |
| 17 | +class SlapCommand extends Command |
| 18 | +{ |
| 19 | + protected $name = 'slap'; |
| 20 | + protected $description = 'Slap someone with their username'; |
| 21 | + protected $usage = '/slap <@user>'; |
| 22 | + protected $version = '1.0.0'; |
| 23 | + protected $enabled = true; |
| 24 | + public function execute() |
| 25 | + { |
| 26 | + $update = $this->getUpdate(); |
| 27 | + $message = $this->getMessage(); |
| 28 | + $chat_id = $message->getChat()->getId(); |
| 29 | + $message_id = $message->getMessageId(); |
| 30 | + $text = $message->getText(true); |
| 31 | + |
| 32 | + $sender='@'.$message->getFrom()->getUsername(); |
| 33 | + |
| 34 | + //username validation |
| 35 | + $test=preg_match('/@[\w_]{5,}/', $text); |
| 36 | + if ($test===0) { |
| 37 | + return false; |
| 38 | + } |
| 39 | + |
| 40 | + $data = array(); |
| 41 | + $data['chat_id'] = $chat_id; |
| 42 | + $data['text'] = $sender.' slaps '.$text.' around a bit with a large trout'; |
| 43 | + $result = Request::sendMessage($data); |
| 44 | + return $result; |
| 45 | + } |
| 46 | +} |
0 commit comments