File tree Expand file tree Collapse file tree 4 files changed +25
-19
lines changed Expand file tree Collapse file tree 4 files changed +25
-19
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
88### Changed
99- Use PSR-12 for code style.
1010### Deprecated
11+ - [ :exclamation : ] [ unreleased-bc-startcommand-is-now-a-usercommand ] ` StartCommand ` is now a ` UserCommand ` (not ` SystemCommand ` any more).
1112### Removed
1213- Botan.io integration completely removed.
1314### Fixed
1415- ` forward_date ` is now correctly saved to the DB.
1516### Security
17+ - Don't allow a user to call system commands directly.
1618
1719## [ 0.57.0] - 2019-06-01
1820:exclamation : After updating to this version, you will need to execute the [ SQL migration script] [ 0.57.0-sql-migration ] on your database.
@@ -265,6 +267,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
265267- Move ` hideKeyboard ` to ` removeKeyboard ` .
266268
267269[ unreleased-sql-migration ] : https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql
270+ [ unreleased-bc-startcommand-is-now-a-usercommand ] : https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#startcommand-is-now-a-usercommand
268271[ 0.57.0-sql-migration ] : https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.56.0-0.57.0.sql
269272[ 0.55.0-sql-migration ] : https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.54.1-0.55.0.sql
270273[ 0.55.0-bc-move-animation-out-of-games-namespace ] : https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#move-animation-out-of-games-namespace
Original file line number Diff line number Diff line change 1414
1515abstract class SystemCommand extends Command
1616{
17+ /**
18+ * @{inheritdoc}
19+ *
20+ * Set to empty string to disallow users calling system commands.
21+ */
22+ protected $ usage = '' ;
23+
1724 /**
1825 * A system command just executes
1926 *
Original file line number Diff line number Diff line change 88 * file that was distributed with this source code.
99 */
1010
11- namespace Longman \TelegramBot \Commands \SystemCommands ;
11+ namespace Longman \TelegramBot \Commands \UserCommands ;
1212
13- use Longman \TelegramBot \Commands \SystemCommand ;
14- use Longman \TelegramBot \Request ;
13+ use Longman \TelegramBot \Commands \UserCommand ;
1514
1615/**
1716 * Start command
18- *
19- * @todo Remove due to deprecation!
2017 */
21- class StartCommand extends SystemCommand
18+ class StartCommand extends UserCommand
2219{
2320 /**
2421 * @var string
@@ -38,12 +35,12 @@ class StartCommand extends SystemCommand
3835 /**
3936 * @var string
4037 */
41- protected $ version = '1.0 .0 ' ;
38+ protected $ version = '1.1 .0 ' ;
4239
4340 /**
4441 * Command execute method
4542 *
46- * @return mixed
43+ * @return \Longman\TelegramBot\Entities\ServerResponse
4744 * @throws \Longman\TelegramBot\Exception\TelegramException
4845 */
4946 public function execute ()
@@ -52,8 +49,6 @@ public function execute()
5249 //$chat_id = $message->getChat()->getId();
5350 //$user_id = $message->getFrom()->getId();
5451
55- trigger_error (__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release. ' , E_USER_DEPRECATED );
56-
5752 return parent ::execute ();
5853 }
5954}
Original file line number Diff line number Diff line change @@ -461,15 +461,16 @@ public function processUpdate(Update $update)
461461 if ($ update_type === 'message ' ) {
462462 $ message = $ this ->update ->getMessage ();
463463 $ type = $ message ->getType ();
464- if ($ type === 'command ' ) {
465- $ command = $ message ->getCommand ();
466- } else {
467- // Let's check if the message object has the type field we're looking for
468- // and if a fitting command class is available.
469- $ command_tmp = $ this ->getCommandFromType ($ type );
470- if ($ this ->getCommandObject ($ command_tmp ) !== null ) {
471- $ command = $ command_tmp ;
472- }
464+
465+ // Let's check if the message object has the type field we're looking for...
466+ $ command_tmp = $ type === 'command ' ? $ message ->getCommand () : $ this ->getCommandFromType ($ type );
467+ // ...and if a fitting command class is available.
468+ $ command_obj = $ this ->getCommandObject ($ command_tmp );
469+
470+ // Empty usage string denotes a non-executable command.
471+ // @see https://github.com/php-telegram-bot/core/issues/772#issuecomment-388616072
472+ if ($ command_obj !== null && $ command_obj ->getUsage () !== '' ) {
473+ $ command = $ command_tmp ;
473474 }
474475 } else {
475476 $ command = $ this ->getCommandFromType ($ update_type );
You can’t perform that action at this time.
0 commit comments