1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 04:11:11 +01:00

add poll object and its filters

This commit is contained in:
AhJ 2024-01-05 18:42:55 +03:30
parent cb38b371cf
commit 41091710e4
15 changed files with 561 additions and 34 deletions

View File

@ -0,0 +1,98 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler;
use JsonSerializable;
use ReflectionClass;
use ReflectionProperty;
use danog\MadelineProto\EventHandler\Poll\QuizPoll;
use danog\MadelineProto\EventHandler\Poll\SinglePoll;
use danog\MadelineProto\EventHandler\Poll\PollAnswer;
use danog\MadelineProto\EventHandler\Poll\MultiplePoll;
/** Poll */
abstract class AbstractPoll implements JsonSerializable
{
/** ID of the poll */
public readonly int $id;
/** Whether the poll is closed and doesnt accept any more answers */
public readonly bool $closed;
/** The question of the poll */
public readonly string $question;
/** @var list<PollAnswer> The possible answers */
public readonly array $answers;
/** Amount of time in seconds the poll will be active after creation, 5-600 */
public readonly ?int $closePeriod;
/** Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future */
public readonly ?int $closeDate;
/** @var list<int> IDs of the last users that recently voted in the poll */
public readonly array $recentVoters;
/** Total number of people that voted in the poll */
public readonly int $totalVoters;
/** @internal */
public function __construct(array $rawPoll)
{
$this->id = $rawPoll['poll']['id'];
$this->closed = $rawPoll['poll']['closed'];
$this->question = $rawPoll['poll']['question'];
$this->closeDate = $rawPoll['poll']['close_date'] ?? null;
$this->closePeriod = $rawPoll['poll']['close_period'] ?? null;
$this->recentVoters = $rawPoll['poll']['public_voters'] ? $rawPoll['results']['recent_voters'] : [];
$this->totalVoters = $rawPoll['results']['total_voters'];
$this->answers = $this->getPollAnswers($rawPoll['poll']['answers'], $rawPoll['results']['results'] ?? []);
}
public static function fromRawPoll(array $rawPoll)
{
if ($rawPoll['poll']['quiz'])
return new QuizPoll($rawPoll);
if ($rawPoll['poll']['multiple_choice'])
return new MultiplePoll($rawPoll);
return new SinglePoll($rawPoll);
}
private function getPollAnswers(array $answers, array $result): array
{
$out = [];
foreach ($answers as $key => $value) {
$merge = array_merge($value, $result[$key] ?? []);
$out[] = new PollAnswer($merge);
}
return $out;
}
/** @internal */
public function jsonSerialize(): mixed
{
$res = ['_' => static::class];
$refl = new ReflectionClass($this);
foreach ($refl->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
$res[$prop->getName()] = $prop->getValue($this);
}
return $res;
}
}

View File

@ -17,52 +17,60 @@
namespace danog\MadelineProto\EventHandler\Filter;
use AssertionError;
use ReflectionType;
use ReflectionNamedType;
use ReflectionUnionType;
use ReflectionIntersectionType;
use danog\MadelineProto\EventHandler;
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersAnd;
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersOr;
use danog\MadelineProto\EventHandler\Filter\Media\FilterAudio;
use danog\MadelineProto\EventHandler\Filter\Media\FilterDocument;
use danog\MadelineProto\EventHandler\Filter\Media\FilterDocumentPhoto;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\GroupMessage;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\ServiceMessage;
use danog\MadelineProto\EventHandler\Filter\FilterPoll;
use danog\MadelineProto\EventHandler\Filter\Poll\FilterQuizPoll;
use danog\MadelineProto\EventHandler\Filter\Poll\FilterSinglePoll;
use danog\MadelineProto\EventHandler\Filter\Poll\FilterMultiplePoll;
use danog\MadelineProto\EventHandler\Filter\Media\FilterGif;
use danog\MadelineProto\EventHandler\Filter\Media\FilterAudio;
use danog\MadelineProto\EventHandler\Filter\Media\FilterPhoto;
use danog\MadelineProto\EventHandler\Filter\Media\FilterRoundVideo;
use danog\MadelineProto\EventHandler\Filter\Media\FilterSticker;
use danog\MadelineProto\EventHandler\Filter\Media\FilterVideo;
use danog\MadelineProto\EventHandler\Filter\Media\FilterVoice;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
use danog\MadelineProto\EventHandler\Message\GroupMessage;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\EventHandler\Message\ServiceMessage;
use danog\MadelineProto\EventHandler\Filter\Media\FilterSticker;
use danog\MadelineProto\EventHandler\Filter\Media\FilterDocument;
use danog\MadelineProto\EventHandler\Filter\Media\FilterRoundVideo;
use danog\MadelineProto\EventHandler\Filter\Media\FilterDocumentPhoto;
use danog\MadelineProto\EventHandler\SimpleFilter\Ended;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdminOrOutgoing;
use danog\MadelineProto\EventHandler\SimpleFilter\HasAudio;
use danog\MadelineProto\EventHandler\SimpleFilter\HasDocument;
use danog\MadelineProto\EventHandler\SimpleFilter\HasDocumentPhoto;
use danog\MadelineProto\EventHandler\SimpleFilter\Outgoing;
use danog\MadelineProto\EventHandler\SimpleFilter\Running;
use danog\MadelineProto\EventHandler\SimpleFilter\HasGif;
use danog\MadelineProto\EventHandler\SimpleFilter\HasAudio;
use danog\MadelineProto\EventHandler\SimpleFilter\HasPhoto;
use danog\MadelineProto\EventHandler\SimpleFilter\HasMedia;
use danog\MadelineProto\EventHandler\SimpleFilter\HasNoMedia;
use danog\MadelineProto\EventHandler\SimpleFilter\HasPhoto;
use danog\MadelineProto\EventHandler\SimpleFilter\HasDocument;
use danog\MadelineProto\EventHandler\SimpleFilter\HasRoundVideo;
use danog\MadelineProto\EventHandler\SimpleFilter\HasDocumentPhoto;
use danog\MadelineProto\EventHandler\SimpleFilter\HasPoll;
use danog\MadelineProto\EventHandler\SimpleFilter\HasQuizPoll;
use danog\MadelineProto\EventHandler\SimpleFilter\HasSinglePoll;
use danog\MadelineProto\EventHandler\SimpleFilter\HasMultiplePoll;
use danog\MadelineProto\EventHandler\SimpleFilter\HasSticker;
use danog\MadelineProto\EventHandler\SimpleFilter\HasVideo;
use danog\MadelineProto\EventHandler\SimpleFilter\HasVoice;
use danog\MadelineProto\EventHandler\SimpleFilter\HasTopic;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\EventHandler\SimpleFilter\IsEdited;
use danog\MadelineProto\EventHandler\SimpleFilter\IsForwarded;
use danog\MadelineProto\EventHandler\SimpleFilter\IsNotEdited;
use danog\MadelineProto\EventHandler\SimpleFilter\IsForwarded;
use danog\MadelineProto\EventHandler\SimpleFilter\IsReply;
use danog\MadelineProto\EventHandler\SimpleFilter\IsReplyToSelf;
use danog\MadelineProto\EventHandler\SimpleFilter\Outgoing;
use danog\MadelineProto\EventHandler\SimpleFilter\Running;
use danog\MadelineProto\EventHandler\Update;
use ReflectionIntersectionType;
use ReflectionNamedType;
use ReflectionType;
use ReflectionUnionType;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdminOrOutgoing;
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersAnd;
use danog\MadelineProto\EventHandler\Filter\Combinator\FiltersOr;
abstract class Filter
{
@ -116,6 +124,10 @@ abstract class Filter
HasVideo::class => new FilterVideo,
HasVoice::class => new FilterVoice,
HasTopic::class => new FilterTopic,
HasPoll::class => new FilterPoll,
HasQuizPoll::class => new FilterQuizPoll,
HasSinglePoll::class => new FilterSinglePoll,
HasMultiplePoll::class => new FilterMultiplePoll,
Ended::class => new FilterEnded,
Running::class => new FilterRunning,
FromAdminOrOutgoing::class => new FiltersOr(new FilterFromAdmin, new FilterOutgoing),

View File

@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter;
use Attribute;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
/**
* Allow only messages that contain a poll.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterPoll extends Filter
{
public function apply(Update $update): bool
{
return ($update instanceof Message && $update->poll !== null);
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter\Poll;
use Attribute;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Filter\Filter;
use danog\MadelineProto\EventHandler\Poll\MultiplePoll;
/**
* Allow only messages that contain a multiple poll.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterMultiplePoll extends Filter
{
public function apply(Update $update): bool
{
return ($update instanceof Message && $update->poll instanceof MultiplePoll);
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter\Poll;
use Attribute;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Filter\Filter;
use danog\MadelineProto\EventHandler\Poll\QuizPoll;
/**
* Allow only messages that contain a quiz poll.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterQuizPoll extends Filter
{
public function apply(Update $update): bool
{
return ($update instanceof Message && $update->poll instanceof QuizPoll);
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter\Poll;
use Attribute;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Filter\Filter;
use danog\MadelineProto\EventHandler\Poll\SinglePoll;
/**
* Allow only messages that contain a single poll.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FilterSinglePoll extends Filter
{
public function apply(Update $update): bool
{
return ($update instanceof Message && $update->poll instanceof SinglePoll);
}
}

View File

@ -21,9 +21,10 @@ use danog\MadelineProto\StrTools;
use danog\MadelineProto\ParseMode;
use danog\MadelineProto\EventHandler\Media\Gif;
use danog\MadelineProto\EventHandler\Media\Audio;
use danog\MadelineProto\EventHandler\Media\Voice;
use danog\MadelineProto\EventHandler\Media\Video;
use danog\MadelineProto\EventHandler\Media\Photo;
use danog\MadelineProto\EventHandler\Media\Video;
use danog\MadelineProto\EventHandler\Media\Voice;
use danog\MadelineProto\EventHandler\AbstractPoll;
use danog\MadelineProto\EventHandler\Media\Sticker;
use danog\MadelineProto\EventHandler\Media\Document;
use danog\MadelineProto\EventHandler\Media\RoundVideo;
@ -113,6 +114,9 @@ abstract class Message extends AbstractMessage
*/
public readonly ?int $groupedId;
/** The poll */
public readonly ?AbstractPoll $poll;
/** @internal */
public function __construct(
MTProto $API,
@ -138,10 +142,6 @@ abstract class Message extends AbstractMessage
$this->viaBotId = $rawMessage['via_bot_id'] ??
(isset($rawMessage['via_bot_name']) ? $this->getClient()->getId($rawMessage['via_bot_name']) : null);
$this->keyboard = isset($rawMessage['reply_markup'])
? Keyboard::fromRawReplyMarkup($rawMessage['reply_markup'])
: null;
if (isset($rawMessage['fwd_from']))
{
$fwdFrom = $rawMessage['fwd_from'];
@ -170,6 +170,14 @@ abstract class Message extends AbstractMessage
? $API->wrapMedia($rawMessage['media'], $this->protected)
: null;
$this->keyboard = isset($rawMessage['reply_markup'])
? Keyboard::fromRawReplyMarkup($rawMessage['reply_markup'])
: null;
$this->poll = ($rawMessage['media']['_'] ?? '') === 'messageMediaPoll'
? AbstractPoll::fromRawPoll($rawMessage['media'])
: null;
if ($this->commandType = CommandType::tryFrom($this->message[0] ?? '')) {
$space = \strpos($this->message, ' ', 1) ?: \strlen($this->message);
$args = \explode(' ', \substr($this->message, $space+1));

View File

@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Poll;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\EventHandler\AbstractPoll;
/** Represents a poll with multiple options can be chosen as answer */
final class MultiplePoll extends AbstractPoll
{
/** @internal */
public function __construct(array $rawPoll)
{
parent::__construct($rawPoll);
}
}

View File

@ -0,0 +1,63 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Poll;
use JsonSerializable;
use ReflectionClass;
use ReflectionProperty;
use danog\MadelineProto\TL\Types\Bytes;
/** Represents a possible answer of a poll */
final readonly class PollAnswer implements JsonSerializable
{
/** Textual representation of the answer */
public string $text;
/** The param that has to be passed to [messages.sendVote](https://docs.madelineproto.xyz/API_docs/methods/messages.sendVote.html) */
public string $option;
/** Whether we have chosen this answer */
public ?bool $chosen;
/** For quizzes, whether the option we have chosen is correct */
public ?bool $correct;
/** How many users voted for this option */
public ?int $voters;
/** @internal */
public function __construct(array $rawAnswer)
{
$this->text = $rawAnswer['text'];
$this->option = (string) $rawAnswer['option'];
$this->chosen = $rawAnswer['chosen'] ?? null;
$this->correct = $rawAnswer['correct'] ?? null;
$this->voters = $rawAnswer['voters'] ?? null;
}
/** @internal */
public function jsonSerialize(): mixed
{
$res = ['_' => static::class];
$refl = new ReflectionClass($this);
foreach ($refl->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
$res[$prop->getName()] = $prop->getValue($this);
}
$res['option'] = new Bytes($res['option']);
return $res;
}
}

View File

@ -0,0 +1,60 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Poll;
use danog\MadelineProto\StrTools;
use danog\MadelineProto\EventHandler\AbstractPoll;
use danog\MadelineProto\EventHandler\Message\Entities\MessageEntity;
/** Represents a quiz (with wrong and correct answers, results shown in the return type) poll */
final class QuizPoll extends AbstractPoll
{
/** Explanation of quiz solution */
public readonly ?string $solution;
/** @var list<MessageEntity> Message [entities](https://core.telegram.org/api/entities) for styled text in quiz solution */
public readonly array $entities;
/** @internal */
public function __construct(array $rawPoll)
{
parent::__construct($rawPoll);
$this->solution = $rawPoll['results']['solution'] ?? null;
$this->entities = MessageEntity::fromRawEntities($rawPoll['results']['solution_entites'] ?? []);
}
protected readonly string $html;
protected readonly string $htmlTelegram;
/**
* Get an HTML version of the solution.
*
* @psalm-suppress InaccessibleProperty
*
* @param bool $allowTelegramTags Whether to allow telegram-specific tags like tg-spoiler, tg-emoji, mention links and so on...
*/
public function getHTML(bool $allowTelegramTags = false): string
{
if (!$this->entities) {
return StrTools::htmlEscape($this->solution);
}
if ($allowTelegramTags) {
return $this->htmlTelegram ??= StrTools::entitiesToHtml($this->solution, $this->entities, $allowTelegramTags);
}
return $this->html ??= StrTools::entitiesToHtml($this->solution, $this->entities, $allowTelegramTags);
}
}

View File

@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Poll;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\EventHandler\AbstractPoll;
/** Represents a poll with a option can be chosen as answer*/
final class SinglePoll extends AbstractPoll
{
/** @internal */
public function __construct(array $rawPoll)
{
parent::__construct($rawPoll);
}
}

View File

@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\SimpleFilter;
/** Allows only messages that contain a multiple poll */
interface HasMultiplePoll
{
}

View File

@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\SimpleFilter;
/** Allows only messages that contain a poll */
interface HasPoll
{
}

View File

@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\SimpleFilter;
/** Allows only messages that contain a quiz poll */
interface HasQuizPoll
{
}

View File

@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\SimpleFilter;
/** Allows only messages that contain a single poll */
interface HasSinglePoll
{
}