Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Jan 6, 2024
1 parent c960924 commit f4d0744
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Console/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use ReflectionProperty;
use SergiX44\Nutgram\Handlers\Handler;
use SergiX44\Nutgram\Handlers\Type\Command as NutgramCommand;
use SergiX44\Nutgram\Nutgram;
Expand Down Expand Up @@ -39,9 +38,8 @@ public function handle(Nutgram $bot): int

protected function getHandlers(Nutgram $bot): Collection
{
$refHandlers = new ReflectionProperty(Nutgram::class, "handlers");
$refHandlers->setAccessible(true);
return collect(Arr::dot($refHandlers->getValue($bot)));
$handlers = (fn () => $this->handlers)->call($bot);
return collect(Arr::dot($handlers));
}

protected function getHandlerName(string $signature, bool $isCommand = false): string
Expand All @@ -60,6 +58,8 @@ protected function resolveUpdateListener(string $signature): string
'edited_message' => 'onEditedMessage',
'channel_post' => 'onChannelPost',
'edited_channel_post' => 'onEditedChannelPost',
'message_reaction' => 'onMessageReaction',
'message_reaction_count' => 'onMessageReactionCount',
'inline_query' => 'onInlineQuery',
'chosen_inline_result' => 'onChosenInlineResult',
'callback_query' => 'onCallbackQuery',
Expand All @@ -70,8 +70,13 @@ protected function resolveUpdateListener(string $signature): string
'my_chat_member' => 'onMyChatMember',
'chat_member' => 'onChatMember',
'chat_join_request' => 'onChatJoinRequest',
'chat_boost' => 'onChatBoost',
'removed_chat_boost' => 'onRemovedChatBoost',
'api_error' => 'onApiError',
'exception' => 'onException',
'fallback' => 'fallback',
'before_api_request' => 'beforeApiRequest',
'after_api_request' => 'afterApiRequest',
default => 'unknown',
};
}
Expand Down Expand Up @@ -101,6 +106,7 @@ protected function resolveMessageListener(string $signature): string
'poll' => 'onMessagePoll',
'venue' => 'onVenue',
'location' => 'onLocation',
'story' => 'onStory',
'new_chat_members' => 'onNewChatMembers',
'left_chat_member' => 'onLeftChatMember',
'new_chat_title' => 'onNewChatTitle',
Expand All @@ -115,13 +121,19 @@ protected function resolveMessageListener(string $signature): string
'pinned_message' => 'onPinnedMessage',
'invoice' => 'onInvoice',
'successful_payment' => 'onSuccessfulPayment',
'users_shared' => 'onUsersShared',
'chat_shared' => 'onChatShared',
'connected_website' => 'onConnectedWebsite',
'passport_data' => 'onPassportData',
'proximity_alert_triggered' => 'onProximityAlertTriggered',
'forum_topic_created' => 'onForumTopicCreated',
'forum_topic_edited' => 'onForumTopicEdited',
'forum_topic_closed' => 'onForumTopicClosed',
'forum_topic_reopened' => 'onForumTopicReopened',
'giveaway_created' => 'onGiveawayCreated',
'giveaway' => 'onGiveaway',
'giveaway_winners' => 'onGiveawayWinners',
'giveaway_completed' => 'onGiveawayCompleted',
'video_chat_scheduled' => 'onVideoChatScheduled',
'video_chat_started' => 'onVideoChatStarted',
'video_chat_ended' => 'onVideoChatEnded',
Expand All @@ -134,9 +146,7 @@ protected function resolveMessageListener(string $signature): string
protected function getCallableName(Handler $handler): string
{
// get callable value
$refCallable = new ReflectionProperty(Handler::class, "callable");
$refCallable->setAccessible(true);
$callable = $refCallable->getValue($handler);
$callable = (fn () => $this->callable)->call($handler);

// parse callable
if (is_string($callable)) {
Expand Down

0 comments on commit f4d0744

Please sign in to comment.