Skip to content

Add new Updates and Types #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ public function preCheckoutQuery(Closure $action)
return $this->on(self::getPreCheckoutQueryEvent($action), self::getPreCheckoutQueryChecker());
}

public function poll(Closure $action)
{
return $this->on(self::getPollEvent($action), self::getPollChecker());
}

public function pollAnswer(Closure $action)
{
return $this->on(self::getPollAnswerEvent($action), self::getPollAnswerChecker());
}

public function myChatMember(Closure $action)
{
return $this->on(self::getMyChatMemberEvent($action), self::getMyChatMemberChecker());
}

public function chatMember(Closure $action)
{
return $this->on(self::getChatMemberEvent($action), self::getChatMemberChecker());
}

public function chatJoinRequest(Closure $action)
{
return $this->on(self::getChatJoinRequestEvent($action), self::getChatJoinRequestChecker());
}

/**
* Use this method to add an event.
* If second closure will return true (or if you are passed null instead of closure), first one will be executed.
Expand Down Expand Up @@ -287,6 +312,71 @@ protected static function getPreCheckoutQueryEvent(Closure $action)
};
}

protected static function getPollEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getPoll()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getPoll()]);
return false;
};
}

protected static function getPollAnswerEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getPollAnswer()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getPollAnswer()]);
return false;
};
}

protected static function getMyChatMemberEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getChatMemberUpdated()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getChatMemberUpdated()]);
return false;
};
}

protected static function getChatMemberEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getChatMemberUpdated()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getChatMemberUpdated()]);
return false;
};
}

protected static function getChatJoinRequestEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getChatJoinRequest()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getChatJoinRequest()]);
return false;
};
}

/**
* Returns check function to handling the command.
*
Expand Down Expand Up @@ -404,6 +494,69 @@ protected static function getPreCheckoutQueryChecker()
};
}

/**
* Returns check function to handling the poll.
*
* @return Closure
*/
protected static function getPollChecker()
{
return function (Update $update) {
return !is_null($update->getPoll());
};
}

/**
* Returns check function to handling the poll answers.
*
* @return Closure
*/
protected static function getPollAnswerChecker()
{
return function (Update $update) {
return !is_null($update->getPollAnswer());
};
}

/**
* Returns check function to handling the updated chat member.
* The bot's chat member status was updated in a chat.
* For private chats, this update is received only when the bot is blocked or unblocked by the user.
* @return Closure
*/
protected static function getMyChatMemberChecker()
{
return function (Update $update) {
return !is_null($update->getChatMemberUpdated());
};
}

/**
* Returns check function to handling the updated chat member.
* The bot's chat member status was updated in a chat.
* For private chats, this update is received only when the bot is blocked or unblocked by the user.
* @return Closure
*/
protected static function getChatMemberChecker()
{
return function (Update $update) {
return !is_null($update->getChatMemberUpdated());
};
}

/**
* Returns check function to handling the chat join requests.
* The bot's chat member status was updated in a chat.
* For private chats, this update is received only when the bot is blocked or unblocked by the user.
* @return Closure
*/
protected static function getChatJoinRequestChecker()
{
return function (Update $update) {
return !is_null($update->getChatJoinRequest());
};
}

public function __call($name, array $arguments)
{
if (method_exists($this, $name)) {
Expand Down
Loading