Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Calc Whoami Command #2

Merged
merged 1 commit into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

}


}