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
f9a70a29
Unverified
Commit
f9a70a29
authored
Oct 10, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make use of the new Keyboard entities.
Some typos, code cleanup.
parent
0001e687
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
27 deletions
+20
-27
KeyboardCommand.php
examples/Commands/KeyboardCommand.php
+1
-2
MarkdownCommand.php
examples/Commands/MarkdownCommand.php
+1
-1
CancelCommand.php
src/Commands/UserCommands/CancelCommand.php
+2
-2
Keyboard.php
src/Entities/Keyboard.php
+1
-1
Message.php
src/Entities/Message.php
+15
-21
No files found.
examples/Commands/KeyboardCommand.php
View file @
f9a70a29
...
...
@@ -33,8 +33,6 @@ class KeyboardCommand extends UserCommand
*/
public
function
execute
()
{
$chat_id
=
$this
->
getMessage
()
->
getChat
()
->
getId
();
//Keyboard examples
/** @var Keyboard[] $keyboards */
$keyboards
=
[];
...
...
@@ -77,6 +75,7 @@ class KeyboardCommand extends UserCommand
->
setOneTimeKeyboard
(
true
)
->
setSelective
(
false
);
$chat_id
=
$this
->
getMessage
()
->
getChat
()
->
getId
();
$data
=
[
'chat_id'
=>
$chat_id
,
'text'
=>
'Press a Button:'
,
...
...
examples/Commands/MarkdownCommand.php
View file @
f9a70a29
...
...
@@ -23,7 +23,7 @@ class MarkdownCommand extends UserCommand
* {@inheritdoc}
*/
protected
$name
=
'markdown'
;
protected
$description
=
'Print Markdown te
s
xt'
;
protected
$description
=
'Print Markdown text'
;
protected
$usage
=
'/markdown'
;
protected
$version
=
'1.0.1'
;
/**#@-*/
...
...
src/Commands/UserCommands/CancelCommand.php
View file @
f9a70a29
...
...
@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use
Longman\TelegramBot\Commands\UserCommand
;
use
Longman\TelegramBot\Conversation
;
use
Longman\TelegramBot\Entities\
ReplyKeyboardHide
;
use
Longman\TelegramBot\Entities\
Keyboard
;
use
Longman\TelegramBot\Request
;
/**
...
...
@@ -85,7 +85,7 @@ class CancelCommand extends UserCommand
{
return
Request
::
sendMessage
(
[
'reply_markup'
=>
new
ReplyKeyboardH
ide
([
'selective'
=>
true
]),
'reply_markup'
=>
Keyboard
::
h
ide
([
'selective'
=>
true
]),
'chat_id'
=>
$this
->
getMessage
()
->
getChat
()
->
getId
(),
'text'
=>
$text
,
]
...
...
src/Entities/Keyboard.php
View file @
f9a70a29
...
...
@@ -15,7 +15,7 @@ namespace Longman\TelegramBot\Entities;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
* Class
ReplyKeyboardMarkup
* Class
Keyboard
*
* @link https://core.telegram.org/bots/api#replykeyboardmarkup
*
...
...
src/Entities/Message.php
View file @
f9a70a29
...
...
@@ -149,19 +149,16 @@ class Message extends Entity
*/
public
function
getFullCommand
()
{
if
(
strpos
(
$this
->
text
,
'/'
)
===
0
)
{
$no_EOL
=
strtok
(
$this
->
text
,
PHP_EOL
);
$no_space
=
strtok
(
$this
->
text
,
' '
);
$text
=
$this
->
getProperty
(
'text'
);
if
(
strpos
(
$text
,
'/'
)
===
0
)
{
$no_EOL
=
strtok
(
$text
,
PHP_EOL
);
$no_space
=
strtok
(
$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
null
;
return
strlen
(
$no_space
)
<
strlen
(
$no_EOL
)
?
$no_space
:
$no_EOL
;
}
return
null
;
}
/**
...
...
@@ -171,8 +168,9 @@ class Message extends Entity
*/
public
function
getCommand
()
{
if
(
!
empty
(
$this
->
command
))
{
return
$this
->
command
;
$command
=
$this
->
getProperty
(
'command'
);
if
(
!
empty
(
$command
))
{
return
$command
;
}
$cmd
=
$this
->
getFullCommand
();
...
...
@@ -185,11 +183,11 @@ class Message extends Entity
if
(
isset
(
$split_cmd
[
1
]))
{
//command is followed by name check if is addressed to me
if
(
strtolower
(
$split_cmd
[
1
])
===
strtolower
(
$this
->
bot_name
))
{
return
$
this
->
command
=
$
split_cmd
[
0
];
return
$split_cmd
[
0
];
}
}
else
{
//command is not followed by name
return
$
this
->
command
=
$
cmd
;
return
$cmd
;
}
}
...
...
@@ -205,7 +203,7 @@ class Message extends Entity
*/
public
function
getText
(
$without_cmd
=
false
)
{
$text
=
$this
->
text
;
$text
=
$this
->
getProperty
(
'text'
)
;
if
(
$without_cmd
&&
$command
=
$this
->
getFullCommand
())
{
if
(
strlen
(
$command
)
+
1
<
strlen
(
$text
))
{
...
...
@@ -225,13 +223,9 @@ class Message extends Entity
*/
public
function
botAddedInChat
()
{
if
(
!
empty
(
$this
->
new_chat_member
))
{
if
(
$this
->
new_chat_member
->
getUsername
()
===
$this
->
getBotName
())
{
return
true
;
}
}
$member
=
$this
->
getNewChatMember
();
return
false
;
return
$member
!==
null
&&
$member
->
getUsername
()
===
$this
->
getBotName
()
;
}
/**
...
...
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