diff --git a/src/TgBotLib/Classes/Utilities.php b/src/TgBotLib/Classes/Utilities.php index 4806298..64082af 100644 --- a/src/TgBotLib/Classes/Utilities.php +++ b/src/TgBotLib/Classes/Utilities.php @@ -5,21 +5,24 @@ use Exception; use LogLib\Log; + use TgBotLib\Enums\EventType; use TgBotLib\Objects\Currency; + use TgBotLib\Objects\Update; class Utilities { /** * @var Currency[]|null */ - private static $currencies_cache; + private static ?array $currencies_cache = null; /** - * Returns + * Retrieves the currency object associated with the given currency code. * - * @param string $code - * @return Currency - * @throws Exception + * @param string $code The currency code to look up. + * @return Currency The currency object corresponding to the given code. + * @throws Exception If the currency code is not found or fetching currencies fails. + * @deprecated Not used */ public static function getCurrency(string $code): Currency { @@ -43,8 +46,36 @@ } if(!isset(self::$currencies_cache[strtolower($code)])) + { throw new Exception("Currency $code not found"); + } return self::$currencies_cache[strtolower($code)]; } + + /** + * Determines the type of event based on the provided update object. + * + * @param Update $update The update object containing event information. + * @return EventType The determined type of the event. + */ + public static function determineEventType(Update $update): EventType + { + if($update->getRemovedChatBoost() !== null) + { + return EventType::REMOVED_CHAT_BOOST_EVENT; + } + + if($update->getChatBoost() !== null) + { + return EventType::CHAT_BOOST_EVENT; + } + + if($update->getChatJoinRequest() !== null) + { + return EventType::CHAT_JOIN_REQUEST_EVENT; + } + + return EventType::UPDATE_EVENT; + } } \ No newline at end of file