From 12a091ce80ec6c83132627ef3c770dfcebf49985 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 5 Nov 2024 13:11:04 -0500 Subject: [PATCH] Refactor command inclusion logic in getText and getCaption --- src/TgBotLib/Objects/Message.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/TgBotLib/Objects/Message.php b/src/TgBotLib/Objects/Message.php index 4a63a34..7749224 100644 --- a/src/TgBotLib/Objects/Message.php +++ b/src/TgBotLib/Objects/Message.php @@ -341,18 +341,18 @@ * @param bool $includeCommand * @return string|null */ - public function getText(bool $includeCommand=true): ?string + public function getText(bool $includeCommand=false): ?string { - if($includeCommand) - { - return $this->text; - } - if($this->text === null) { return null; } + if($includeCommand) + { + return $this->text; + } + if(preg_match('/^\/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?/', $this->text, $matches)) { return str_replace($matches[0], '', $this->text); @@ -502,16 +502,16 @@ */ public function getCaption(bool $includeCommand=false): ?string { - if($includeCommand) - { - return $this->caption; - } - if($this->caption === null) { return null; } + if($includeCommand) + { + return $this->caption; + } + if(preg_match('/^\/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?/', $this->caption, $matches)) { return str_replace($matches[0], '', $this->caption);