From 1f71ef8258aa9a7b3085cdccf6195b0efeda21df Mon Sep 17 00:00:00 2001 From: giuseppeM99 Date: Fri, 24 Apr 2020 20:14:42 +0200 Subject: [PATCH] Pollfix (#805) * Add support for quiz solutions also throws execeptions * Style fix --- .../MadelineProto/MTProtoTools/Files.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 9e8949d0..7e4e8261 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -509,25 +509,45 @@ trait Files case 'messageMediaPoll': $res['Poll'] = $media['poll']; $res['InputMedia'] = ['_' => 'inputMediaPoll', 'poll' => $res['Poll']]; - if ($res['Poll']['quiz']) { + if (isset($res['Poll']['quiz']) && $res['Poll']['quiz']) { + if (empty($media['results']['results'])) { + //quizzes need a correct answer + throw new \danog\MadelineProto\Exception('No poll results'); + } foreach ($media['results']['results'] as $answer) { if ($answer['correct']) { $res['InputMedia']['correct_answers'][] = $answer['option']; } } } + if (isset($media['results']['solution'])) { + $res['InputMedia']['solution'] = $media['results']['solution']; + } + if (isset($media['results']['solution_entities'])) { + $res['InputMedia']['solution_entities'] = $media['results']['solution_entities']; + } break; case 'updateMessagePoll': $res['Poll'] = $media['poll']; $res['InputMedia'] = ['_' => 'inputMediaPoll', 'poll' => $res['Poll']]; $res['MessageMedia'] = ['_' => 'messageMediaPoll', 'poll' => $res['Poll'], 'results' => $media['results']]; - if ($res['Poll']['quiz']) { + if (isset($res['Poll']['quiz']) && $res['Poll']['quiz']) { + if (empty($media['results']['results'])) { + //quizzes need a correct answer + throw new \danog\MadelineProto\Exception('No poll results'); + } foreach ($media['results']['results'] as $answer) { if ($answer['correct']) { $res['InputMedia']['correct_answers'][] = $answer['option']; } } } + if (isset($media['results']['solution'])) { + $res['InputMedia']['solution'] = $media['results']['solution']; + } + if (isset($media['results']['solution_entities'])) { + $res['InputMedia']['solution_entities'] = $media['results']['solution_entities']; + } break; case 'messageMediaPhoto': if (!isset($media['photo']['access_hash'])) {