Rename UpdateEventType to EventType for consistency

This commit is contained in:
netkas 2024-11-03 18:25:42 -05:00
parent a24c617c9f
commit 7623f488ee
28 changed files with 110 additions and 110 deletions

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Abstracts;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Update;
abstract class UpdateEvent
@ -23,11 +23,11 @@
/**
* Retrieves the event type.
* @return UpdateEventType The event type of the current instance.
* @return EventType The event type of the current instance.
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::UPDATE_EVENT;
return EventType::UPDATE_EVENT;
}
public abstract function handle(Bot $bot): void;

View file

@ -14,7 +14,7 @@
use TgBotLib\Abstracts\Method;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Classes\Logger;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Enums\Methods;
use TgBotLib\Enums\Types\ChatActionType;
use TgBotLib\Enums\Types\ParseMode;
@ -271,10 +271,10 @@
/**
* Retrieves all event handlers that match a specified event type.
*
* @param UpdateEventType $type The event type to filter handlers by.
* @param EventType $type The event type to filter handlers by.
* @return array An array of event handlers that handle the specified event type.
*/
public function getEventHandlersByType(UpdateEventType $type): array
public function getEventHandlersByType(EventType $type): array
{
$results = [];
/** @var UpdateEvent $eventHandler */
@ -302,10 +302,10 @@
/**
* Removes all event handlers of a specified type.
*
* @param UpdateEventType $type The event type to filter handlers by.
* @param EventType $type The event type to filter handlers by.
* @return void
*/
public function removeEventHandlersByType(UpdateEventType $type): void
public function removeEventHandlersByType(EventType $type): void
{
$this->eventHandlers = array_filter($this->eventHandlers, function($eventHandler) use ($type)
{

View file

@ -5,7 +5,7 @@
use Exception;
use LogLib\Log;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Currency;
use TgBotLib\Objects\Update;

View file

@ -28,7 +28,7 @@
use TgBotLib\Events\ShippingQueryEvent;
use TgBotLib\Objects\Update;
enum UpdateEventType : string
enum EventType : string
{
case UPDATE_EVENT = UpdateEvent::class;
case REMOVED_CHAT_BOOST_EVENT = RemovedChatBoostEvent::class;
@ -59,125 +59,125 @@
* Determines the type of event based on the provided Update object.
*
* @param Update $update The update object containing event details.
* @return UpdateEventType The type of event detected from the update.
* @return EventType The type of event detected from the update.
*/
public static function determineEventType(Update $update): UpdateEventType
public static function determineEventType(Update $update): EventType
{
if($update->getRemovedChatBoost() !== null)
{
return UpdateEventType::REMOVED_CHAT_BOOST_EVENT;
return EventType::REMOVED_CHAT_BOOST_EVENT;
}
if($update->getChatBoost() !== null)
{
return UpdateEventType::CHAT_BOOST_EVENT;
return EventType::CHAT_BOOST_EVENT;
}
if($update->getChatJoinRequest() !== null)
{
return UpdateEventType::CHAT_JOIN_REQUEST_EVENT;
return EventType::CHAT_JOIN_REQUEST_EVENT;
}
if($update->getChatMember() !== null)
{
return UpdateEventType::CHAT_MEMBER_UPDATED;
return EventType::CHAT_MEMBER_UPDATED;
}
if($update->getMyChatMember() !== null)
{
return UpdateEventType::MY_CHAT_MEMBER_UPDATED;
return EventType::MY_CHAT_MEMBER_UPDATED;
}
if($update->getPollAnswer() !== null)
{
return UpdateEventType::POLL_ANSWER;
return EventType::POLL_ANSWER;
}
if($update->getPoll() !== null)
{
return UpdateEventType::POLL;
return EventType::POLL;
}
if($update->getPurchasedPaidMedia() !== null)
{
return UpdateEventType::PAID_MEDIA_PURCHASED;
return EventType::PAID_MEDIA_PURCHASED;
}
if($update->getPreCheckoutQuery() !== null)
{
return UpdateEventType::PRE_CHECKOUT_QUERY;
return EventType::PRE_CHECKOUT_QUERY;
}
if($update->getShippingQuery() !== null)
{
return UpdateEventType::SHIPPING_QUERY;
return EventType::SHIPPING_QUERY;
}
if($update->getCallbackQuery() !== null)
{
return UpdateEventType::CALLBACK_QUERY;
return EventType::CALLBACK_QUERY;
}
if($update->getChosenInlineResult() !== null)
{
return UpdateEventType::CHOSEN_INLINE_RESULT;
return EventType::CHOSEN_INLINE_RESULT;
}
if($update->getInlineQuery() !== null)
{
return UpdateEventType::INLINE_QUERY;
return EventType::INLINE_QUERY;
}
if($update->getMessageReactionCount() !== null)
{
return UpdateEventType::MESSAGE_REACTION_COUNT;
return EventType::MESSAGE_REACTION_COUNT;
}
if($update->getMessageReaction() !== null)
{
return UpdateEventType::MESSAGE_REACTION;
return EventType::MESSAGE_REACTION;
}
if($update->getDeletedBusinessMessages() !== null)
{
return UpdateEventType::DELETED_BUSINESS_MESSAGES;
return EventType::DELETED_BUSINESS_MESSAGES;
}
if($update->getEditedBusinessMessage() !== null)
{
return UpdateEventType::EDITED_BUSINESS_MESSAGE;
return EventType::EDITED_BUSINESS_MESSAGE;
}
if($update->getBusinessMessage() !== null)
{
return UpdateEventType::BUSINESS_MESSAGE;
return EventType::BUSINESS_MESSAGE;
}
if($update->getBusinessConnection() !== null)
{
return UpdateEventType::BUSINESS_CONNECTION;
return EventType::BUSINESS_CONNECTION;
}
if($update->getEditedChannelPost() !== null)
{
return UpdateEventType::EDITED_CHANNEL_POST;
return EventType::EDITED_CHANNEL_POST;
}
if($update->getChannelPost() !== null)
{
return UpdateEventType::CHANNEL_POST;
return EventType::CHANNEL_POST;
}
if($update->getEditedMessage() !== null)
{
return UpdateEventType::EDITED_MESSAGE;
return EventType::EDITED_MESSAGE;
}
if($update->getMessage() !== null)
{
return UpdateEventType::MESSAGE;
return EventType::MESSAGE;
}
return UpdateEventType::UPDATE_EVENT;
return EventType::UPDATE_EVENT;
}
}

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\BusinessConnection;
abstract class BusinessConnectionEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::BUSINESS_CONNECTION;
return EventType::BUSINESS_CONNECTION;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class BusinessMessageEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::BUSINESS_MESSAGE;
return EventType::BUSINESS_MESSAGE;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\CallbackQuery;
abstract class CallbackQueryEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::CALLBACK_QUERY;
return EventType::CALLBACK_QUERY;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class ChannelPostEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::CHANNEL_POST;
return EventType::CHANNEL_POST;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatBoostUpdated;
abstract class ChatBoostEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::CHAT_BOOST_EVENT;
return EventType::CHAT_BOOST_EVENT;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatJoinRequest;
abstract class ChatJoinRequestEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::CHAT_JOIN_REQUEST_EVENT;
return EventType::CHAT_JOIN_REQUEST_EVENT;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatMemberUpdated;
abstract class ChatMemberUpdatedEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::CHAT_MEMBER_UPDATED;
return EventType::CHAT_MEMBER_UPDATED;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Inline\ChosenInlineResult;
abstract class ChosenInlineResultEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateeventType::CHOSEN_INLINE_RESULT;
return EventType::CHOSEN_INLINE_RESULT;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\BusinessMessagesDeleted;
abstract class DeletedBusinessMessagesEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::DELETED_BUSINESS_MESSAGES;
return EventType::DELETED_BUSINESS_MESSAGES;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedBusinessMessageEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::EDITED_BUSINESS_MESSAGE;
return EventType::EDITED_BUSINESS_MESSAGE;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedChannelPostEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::EDITED_CHANNEL_POST;
return EventType::EDITED_CHANNEL_POST;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedMessageEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::EDITED_MESSAGE;
return EventType::EDITED_MESSAGE;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Inline\InlineQuery;
abstract class InlineQueryEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::INLINE_QUERY;
return EventType::INLINE_QUERY;
}
/**C

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class MessageEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::MESSAGE;
return EventType::MESSAGE;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\MessageReactionCountUpdated;
abstract class MessageReactionCountEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::MESSAGE_REACTION_COUNT;
return EventType::MESSAGE_REACTION_COUNT;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\MessageReactionUpdated;
abstract class MessageReactionEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::MESSAGE_REACTION;
return EventType::MESSAGE_REACTION;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatMemberUpdated;
abstract class MyChatMemberUpdatedEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::MY_CHAT_MEMBER_UPDATED;
return EventType::MY_CHAT_MEMBER_UPDATED;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\PaidMediaPurchased;
abstract class PaidMediaPurchasedEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::PAID_MEDIA_PURCHASED;
return EventType::PAID_MEDIA_PURCHASED;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\PollAnswer;
abstract class PollAnswerEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::POLL_ANSWER;
return EventType::POLL_ANSWER;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Poll;
abstract class PollEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::POLL;
return EventType::POLL;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\PreCheckoutQuery;
abstract class PreCheckoutQueryEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::PRE_CHECKOUT_QUERY;
return EventType::PRE_CHECKOUT_QUERY;
}
/**

View file

@ -3,7 +3,7 @@
namespace TgBotLib\Events;
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatBoostRemoved;
abstract class RemovedChatBoostEvent extends UpdateEvent
@ -11,9 +11,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::REMOVED_CHAT_BOOST_EVENT;
return EventType::REMOVED_CHAT_BOOST_EVENT;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Bot;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\ShippingQuery;
abstract class ShippingQueryEvent extends UpdateEvent
@ -12,9 +12,9 @@
/**
* @inheritDoc
*/
public static function getEventType(): UpdateEventType
public static function getEventType(): EventType
{
return UpdateEventType::SHIPPING_QUERY;
return EventType::SHIPPING_QUERY;
}
/**

View file

@ -4,7 +4,7 @@
use TgBotLib\Abstracts\UpdateEvent;
use TgBotLib\Classes\Utilities;
use TgBotLib\Enums\UpdateEventType;
use TgBotLib\Enums\EventType;
/**
* PollingBot class that extends Bot for handling updates using polling.
@ -136,14 +136,14 @@
$this->offset = $update->getUpdateId() + 1;
}
$updateByType = $this->getEventHandlersByType(UpdateEventType::determineEventType($update));
$updateByType = $this->getEventHandlersByType(EventType::determineEventType($update));
if(count($updateByType) === 0)
{
// If no event handlers are found appropriate for the update type, use the generic update event handler
// So that we don't miss any updates
/** @var UpdateEvent $eventHandler */
foreach($this->getEventHandlersByType(UpdateEventType::UPDATE_EVENT) as $eventHandler)
foreach($this->getEventHandlersByType(EventType::UPDATE_EVENT) as $eventHandler)
{
(new $eventHandler($update))->handle($this);
}
@ -152,7 +152,7 @@
{
// Otherwise, use the appropriate event handler for the update type
/** @var UpdateEvent $eventHandler */
foreach($this->getEventHandlersByType(UpdateEventType::determineEventType($update)) as $eventHandler)
foreach($this->getEventHandlersByType(EventType::determineEventType($update)) as $eventHandler)
{
(new $eventHandler($update))->handle($this);
}