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
f2a1dbd8
Commit
f2a1dbd8
authored
Nov 19, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BugFix EOL command text separator
parent
89413a16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
Message.php
src/Entities/Message.php
+11
-2
MessageTest.php
tests/Unit/Entities/MessageTest.php
+21
-0
No files found.
src/Entities/Message.php
View file @
f2a1dbd8
...
...
@@ -199,7 +199,15 @@ class Message extends Entity
public
function
getFullCommand
()
{
if
(
substr
(
$this
->
text
,
0
,
1
)
===
'/'
)
{
return
strtok
(
$this
->
text
,
' '
);
$no_EOL
=
strtok
(
$this
->
text
,
PHP_EOL
);
$no_space
=
strtok
(
$this
->
text
,
' '
);
//try to understand which separator \n or space divide /command from text
if
(
strlen
(
$no_space
)
<
strlen
(
$no_EOL
))
{
return
$no_space
;
}
else
{
return
$no_EOL
;
}
}
else
{
return
;
}
...
...
@@ -273,7 +281,8 @@ class Message extends Entity
if
(
$without_cmd
)
{
$command
=
$this
->
getFullCommand
();
if
(
!
empty
(
$command
))
{
$text
=
substr
(
$text
,
strlen
(
$command
.
' '
),
strlen
(
$text
));
//$text = substr($text, strlen($command.' '), strlen($text));
$text
=
substr
(
$text
,
strlen
(
$command
)
+
1
,
strlen
(
$text
));
}
}
...
...
tests/Unit/Entities/MessageTest.php
View file @
f2a1dbd8
...
...
@@ -82,5 +82,26 @@ class MessageTest extends TestCase
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
'/help@testbot some text'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /commmad\n text
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
"/help
\n
some text"
),
'testbot'
);
$this
->
assertEquals
(
'/help'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help
\n
some text"
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
' some text'
,
$this
->
message
->
getText
(
true
));
// /command@bot\nsome text
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
"/help@testbot
\n
some text"
),
'testbot'
);
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help@testbot
\n
some text"
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /command@bot \nsome text
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
"/help@testbot
\n
some text"
),
'testbot'
);
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help@testbot
\n
some text"
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
"
\n
some text"
,
$this
->
message
->
getText
(
true
));
}
}
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