From 1cd8fad52a1f5ca723fe81d3ada74a95ee8ddff4 Mon Sep 17 00:00:00 2001 From: MBoretto Date: Wed, 1 Jul 2015 13:56:35 +0200 Subject: [PATCH] Added Calc Whoami Command --- src/Commands/CalcCommand.php | 48 ++++++++++++++++++++++++++++++++++ src/Commands/WhoamiCommand.php | 43 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/Commands/CalcCommand.php create mode 100644 src/Commands/WhoamiCommand.php diff --git a/src/Commands/CalcCommand.php b/src/Commands/CalcCommand.php new file mode 100644 index 000000000..c194f6b66 --- /dev/null +++ b/src/Commands/CalcCommand.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * Written by Marco Boretto + */ +namespace Longman\TelegramBot\Commands; + +use Longman\TelegramBot\Request; +use Longman\TelegramBot\Command; +use Longman\TelegramBot\Entities\Update; + +class CalcCommand extends Command +{ + + public function execute() { + $update = $this->getUpdate(); + $message = $this->getMessage(); + + + + $chat_id = $message->getChat()->getId(); + $text = $message->getText(true); + + #$elm = explode(" ",$text); + #array_shift($elm); + + # $text = trim(implode(" ",$elm)); + $text = preg_replace('/[^0-9\+\-\*\/\(\) ]/i', '',trim($text)); + $compute = create_function('', 'return (' . trim($text) . ');' ); + + + $data = array(); + $data['chat_id'] = $chat_id; + $data['text'] = 0 + $compute(); + + + $result = Request::sendMessage($data); + + } + + +} + diff --git a/src/Commands/WhoamiCommand.php b/src/Commands/WhoamiCommand.php new file mode 100644 index 000000000..940b7103e --- /dev/null +++ b/src/Commands/WhoamiCommand.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * writteno by Marco Boretto + */ + +namespace Longman\TelegramBot\Commands; + +use Longman\TelegramBot\Request; +use Longman\TelegramBot\Command; +use Longman\TelegramBot\Entities\Update; + +class WhoamiCommand extends Command +{ + + public function execute() { + $update = $this->getUpdate(); + $message = $this->getMessage(); + + + + $chat_id = $message->getChat()->getId(); + $text = $message->getText(true); + + $from = $message->getFrom()->getFirstName().' '.$message->getFrom()->getLastName().' '.$message->getFrom()->getUsername(); + + $data = array(); + $data['chat_id'] = $chat_id; + $data['text'] = 'Your name is: ' . $from; + + + $result = Request::sendMessage($data); + + } + + +} +