Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
e7c9e56f
Commit
e7c9e56f
authored
Jul 03, 2015
by
LONGMAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved calc and whoami commands
parent
449740ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
8 deletions
+21
-8
composer.json
composer.json
+2
-1
CalcCommand.php
src/Commands/CalcCommand.php
+16
-5
WhoamiCommand.php
src/Commands/WhoamiCommand.php
+3
-2
No files found.
composer.json
View file @
e7c9e56f
...
...
@@ -19,7 +19,8 @@
],
"require"
:
{
"php"
:
">=5.3.0"
,
"ext-pdo"
:
"*"
"ext-pdo"
:
"*"
,
"
hoa/math
"
:
"
~0.0
"
},
"autoload"
:
{
"psr-4"
:
{
...
...
src/Commands/CalcCommand.php
View file @
e7c9e56f
...
...
@@ -33,16 +33,27 @@ class CalcCommand extends Command
$data
[
'reply_to_message_id'
]
=
$message_id
;
$data
[
'text'
]
=
$this
->
compute
(
$text
);
$result
=
Request
::
sendMessage
(
$data
);
}
protected
function
compute
(
$text
)
{
$text
=
preg_replace
(
'/[^0-9\+\-\*\/\(\) ]/i'
,
''
,
trim
(
$text
));
$compute
=
create_function
(
''
,
'return ('
.
trim
(
$text
)
.
');'
);
$result
=
0
+
$compute
();
protected
function
compute
(
$expression
)
{
// Load the compiler
$compiler
=
\Hoa\Compiler\Llk
::
load
(
new
\Hoa\File\Read
(
'hoa://Library/Math/Arithmetic.pp'
)
);
// Load the visitor, aka the "evaluator"
$visitor
=
new
\Hoa\Math\Visitor\Arithmetic
();
// Parse the expression
$ast
=
$compiler
->
parse
(
$expression
);
// Evaluate
$result
=
$visitor
->
visit
(
$ast
);
return
$result
;
}
...
...
src/Commands/WhoamiCommand.php
View file @
e7c9e56f
...
...
@@ -32,8 +32,9 @@ class WhoamiCommand extends Command
$data
=
array
();
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'reply_to_message_id'
]
=
$message_id
;
$data
[
'text'
]
=
'Your name is: '
.
$message
->
getFrom
()
->
getFirstName
()
.
' '
.
$message
->
getFrom
()
->
getLastName
();
$data
[
'text'
]
=
"
\n
"
.
'Username: '
.
$message
->
getFrom
()
->
getUsername
();
$data
[
'text'
]
=
'Your Id: '
.
$message
->
getFrom
()
->
getId
();
$data
[
'text'
]
.=
"
\n
"
.
'Name: '
.
$message
->
getFrom
()
->
getFirstName
()
.
' '
.
$message
->
getFrom
()
->
getLastName
();
$data
[
'text'
]
.=
"
\n
"
.
'Username: '
.
$message
->
getFrom
()
->
getUsername
();
$result
=
Request
::
sendMessage
(
$data
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment