From 1cf82401c32480cda6345c7c2a169478431569a2 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 4 Nov 2024 01:16:21 -0500 Subject: [PATCH] Add CommandEvent class to handle bot commands --- src/TgBotLib/Events/CommandEvent.php | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/TgBotLib/Events/CommandEvent.php diff --git a/src/TgBotLib/Events/CommandEvent.php b/src/TgBotLib/Events/CommandEvent.php new file mode 100644 index 0000000..f5ce420 --- /dev/null +++ b/src/TgBotLib/Events/CommandEvent.php @@ -0,0 +1,64 @@ +update->getMessage(); + } + + /** + * Extracts and returns the arguments of the command from the message text. + * + * @return string The arguments of the command. + */ + protected function getArguments(): string + { + if(strlen($this->getMessage()->getText()) <= strlen(static::getCommand()) + 1) + { + return ''; + } + + return substr($this->getMessage()->getText(), strlen(static::getCommand()) + 1); + } + + /** + * Parses and returns the command arguments as an array. + * + * @return array The parsed command arguments. + */ + protected function getParsedArguments(): array + { + return Parse::parseArgument($this->getArguments()); + } + } \ No newline at end of file