Skip to content

Commit 5f1afb0

Browse files
authored
Merge pull request #1074 from 1int/refactor/default-command-names
Use class constants instead of strings for 'generic' and 'genericmessage'
2 parents 78024d7 + 894c939 commit 5f1afb0

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Notes
88
- [:ledger: View file changes][Unreleased]
99
### Added
10+
- Replaced 'generic' and 'genericmessage' strings with Telegram::GENERIC_COMMAND and Telegram::GENERIC_MESSAGE_COMMAND constants (@1int)
1011
### Changed
1112
### Deprecated
1213
### Removed

src/Commands/SystemCommands/GenericmessageCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Longman\TelegramBot\Entities\ServerResponse;
1616
use Longman\TelegramBot\Exception\TelegramException;
1717
use Longman\TelegramBot\Request;
18+
use Longman\TelegramBot\Telegram;
1819

1920
/**
2021
* Generic message command
@@ -24,7 +25,7 @@ class GenericmessageCommand extends SystemCommand
2425
/**
2526
* @var string
2627
*/
27-
protected $name = 'genericmessage';
28+
protected $name = Telegram::GENERIC_MESSAGE_COMMAND;
2829

2930
/**
3031
* @var string

src/Telegram.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ class Telegram
146146
*/
147147
protected $last_update_id = null;
148148

149+
/**
150+
* The command to be executed when there's a new message update and nothing more suitable is found
151+
*/
152+
const GENERIC_MESSAGE_COMMAND = 'genericmessage';
153+
154+
/**
155+
* The command to be executed by default (when no other relevant commands are applicable)
156+
*/
157+
const GENERIC_COMMAND = 'generic';
158+
149159
/**
150160
* Telegram constructor.
151161
*
@@ -455,7 +465,7 @@ public function processUpdate(Update $update)
455465
$this->getCommandsList();
456466

457467
//If all else fails, it's a generic message.
458-
$command = 'genericmessage';
468+
$command = self::GENERIC_MESSAGE_COMMAND;
459469

460470
$update_type = $this->update->getUpdateType();
461471
if ($update_type === 'message') {
@@ -506,12 +516,12 @@ public function executeCommand($command)
506516

507517
if (!$command_obj || !$command_obj->isEnabled()) {
508518
//Failsafe in case the Generic command can't be found
509-
if ($command === 'generic') {
519+
if ($command === self::GENERIC_COMMAND) {
510520
throw new TelegramException('Generic command missing!');
511521
}
512522

513523
//Handle a generic command or non existing one
514-
$this->last_command_response = $this->executeCommand('generic');
524+
$this->last_command_response = $this->executeCommand(self::GENERIC_COMMAND);
515525
} else {
516526
//execute() method is executed after preExecute()
517527
//This is to prevent executing a DB query without a valid connection

0 commit comments

Comments
 (0)