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
ecb9e774
Commit
ecb9e774
authored
Aug 05, 2017
by
Armando Lüscher
Committed by
GitHub
Aug 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into cleanup_nodb
parents
499c74c9
8a9b0d6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
CHANGELOG.md
CHANGELOG.md
+1
-0
Command.php
src/Commands/Command.php
+58
-0
No files found.
CHANGELOG.md
View file @
ecb9e774
...
...
@@ -13,6 +13,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
-
`Telegram::enableAdmin()`
now handles duplicate additions properly.
-
`Request::getMe()`
failure doesn't break cron execution any more.
### Security
-
New command parameter
`$private_only`
to enforce usage in private chats only.
## [0.46.0] - 2017-07-15
### Added
...
...
src/Commands/Command.php
View file @
ecb9e774
...
...
@@ -97,6 +97,13 @@ abstract class Command
*/
protected
$need_mysql
=
false
;
/*
* Make sure this command only executes on a private chat.
*
* @var bool
*/
protected
$private_only
=
false
;
/**
* Command config
*
...
...
@@ -145,6 +152,24 @@ abstract class Command
return
$this
->
executeNoDb
();
}
if
(
$this
->
isPrivateOnly
()
&&
$this
->
removeNonPrivateMessage
())
{
$message
=
$this
->
getMessage
();
if
(
$user
=
$message
->
getFrom
())
{
return
Request
::
sendMessage
([
'chat_id'
=>
$user
->
getId
(),
'parse_mode'
=>
'Markdown'
,
'text'
=>
sprintf
(
"/%s command is only available in a private chat.
\n
(`%s`)"
,
$this
->
getName
(),
$message
->
getText
()
),
]);
}
return
Request
::
emptyResponse
();
}
return
$this
->
execute
();
}
...
...
@@ -296,6 +321,16 @@ abstract class Command
return
$this
->
enabled
;
}
/**
* If this command is intended for private chats only.
*
* @return bool
*/
public
function
isPrivateOnly
()
{
return
$this
->
private_only
;
}
/**
* If this is a SystemCommand
*
...
...
@@ -325,4 +360,27 @@ abstract class Command
{
return
(
$this
instanceof
UserCommand
);
}
/**
* Delete the current message if it has been called in a non-private chat.
*
* @return bool
*/
protected
function
removeNonPrivateMessage
()
{
$message
=
$this
->
getMessage
();
$chat
=
$message
->
getChat
();
if
(
!
$chat
->
isPrivateChat
())
{
// Delete the falsely called command message.
Request
::
deleteMessage
([
'chat_id'
=>
$chat
->
getId
(),
'message_id'
=>
$message
->
getMessageId
(),
]);
return
true
;
}
return
false
;
}
}
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