Skip to content

Commit 1cd8fad

Browse files
committed
Added Calc Whoami Command
1 parent 25ec8cf commit 1cd8fad

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/Commands/CalcCommand.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
* Written by Marco Boretto <[email protected]>
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 CalcCommand extends Command
18+
{
19+
20+
public function execute() {
21+
$update = $this->getUpdate();
22+
$message = $this->getMessage();
23+
24+
25+
26+
$chat_id = $message->getChat()->getId();
27+
$text = $message->getText(true);
28+
29+
#$elm = explode(" ",$text);
30+
#array_shift($elm);
31+
32+
# $text = trim(implode(" ",$elm));
33+
$text = preg_replace('/[^0-9\+\-\*\/\(\) ]/i', '',trim($text));
34+
$compute = create_function('', 'return (' . trim($text) . ');' );
35+
36+
37+
$data = array();
38+
$data['chat_id'] = $chat_id;
39+
$data['text'] = 0 + $compute();
40+
41+
42+
$result = Request::sendMessage($data);
43+
44+
}
45+
46+
47+
}
48+

src/Commands/WhoamiCommand.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
* writteno by Marco Boretto <[email protected]>
10+
*/
11+
12+
namespace Longman\TelegramBot\Commands;
13+
14+
use Longman\TelegramBot\Request;
15+
use Longman\TelegramBot\Command;
16+
use Longman\TelegramBot\Entities\Update;
17+
18+
class WhoamiCommand extends Command
19+
{
20+
21+
public function execute() {
22+
$update = $this->getUpdate();
23+
$message = $this->getMessage();
24+
25+
26+
27+
$chat_id = $message->getChat()->getId();
28+
$text = $message->getText(true);
29+
30+
$from = $message->getFrom()->getFirstName().' '.$message->getFrom()->getLastName().' '.$message->getFrom()->getUsername();
31+
32+
$data = array();
33+
$data['chat_id'] = $chat_id;
34+
$data['text'] = 'Your name is: ' . $from;
35+
36+
37+
$result = Request::sendMessage($data);
38+
39+
}
40+
41+
42+
}
43+

0 commit comments

Comments
 (0)