-
-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MBoretto/master
Added Calc Whoami Command. Thanks to @MBoretto
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/* | ||
* This file is part of the TelegramBot package. | ||
* | ||
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* Written by Marco Boretto <marco.bore@gmail.com> | ||
*/ | ||
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); | ||
|
||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/* | ||
* This file is part of the TelegramBot package. | ||
* | ||
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* writteno by Marco Boretto <marco.bore@gmail.com> | ||
*/ | ||
|
||
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); | ||
|
||
} | ||
|
||
|
||
} | ||
|