Skip to content

Commit

Permalink
Merge pull request #2 from MBoretto/master
Browse files Browse the repository at this point in the history
Added Calc Whoami Command. Thanks to @MBoretto
  • Loading branch information
akalongman committed Jul 2, 2015
2 parents 25ec8cf + 1cd8fad commit 60a5311
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Commands/CalcCommand.php
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);

}


}

43 changes: 43 additions & 0 deletions src/Commands/WhoamiCommand.php
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);

}


}

0 comments on commit 60a5311

Please sign in to comment.