mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Refactor Poll.
Move PollAnswer into poll.py and rename it to PollOption
This commit is contained in:
parent
f8de518f6b
commit
2b568afd2a
@ -32,7 +32,7 @@ from .client.types import (
|
|||||||
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
|
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
|
||||||
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
|
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
|
||||||
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
|
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
|
||||||
Poll, PollAnswer
|
Poll
|
||||||
)
|
)
|
||||||
from .client import (
|
from .client import (
|
||||||
Client, ChatAction, ParseMode, Emoji,
|
Client, ChatAction, ParseMode, Emoji,
|
||||||
|
@ -31,7 +31,7 @@ from .input_media import (
|
|||||||
from .messages_and_media import (
|
from .messages_and_media import (
|
||||||
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,
|
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,
|
||||||
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,
|
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,
|
||||||
Message, Messages, MessageEntity, Poll, PollAnswer
|
Message, Messages, MessageEntity, Poll
|
||||||
)
|
)
|
||||||
from .user_and_chats import (
|
from .user_and_chats import (
|
||||||
Chat, ChatMember, ChatMembers, ChatPhoto,
|
Chat, ChatMember, ChatMembers, ChatPhoto,
|
||||||
|
@ -27,7 +27,6 @@ from .messages import Messages
|
|||||||
from .photo import Photo
|
from .photo import Photo
|
||||||
from .photo_size import PhotoSize
|
from .photo_size import PhotoSize
|
||||||
from .poll import Poll
|
from .poll import Poll
|
||||||
from .poll_answer import PollAnswer
|
|
||||||
from .sticker import Sticker
|
from .sticker import Sticker
|
||||||
from .user_profile_photos import UserProfilePhotos
|
from .user_profile_photos import UserProfilePhotos
|
||||||
from .venue import Venue
|
from .venue import Venue
|
||||||
|
@ -20,10 +20,21 @@ from typing import List
|
|||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .poll_answer import PollAnswer
|
|
||||||
from ..pyrogram_type import PyrogramType
|
from ..pyrogram_type import PyrogramType
|
||||||
|
|
||||||
|
|
||||||
|
class PollOption(PyrogramType):
|
||||||
|
def __init__(self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.client.ext.BaseClient",
|
||||||
|
text: str,
|
||||||
|
voters: int):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.text = text
|
||||||
|
self.voters = voters
|
||||||
|
|
||||||
|
|
||||||
class Poll(PyrogramType):
|
class Poll(PyrogramType):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
*,
|
*,
|
||||||
@ -31,16 +42,16 @@ class Poll(PyrogramType):
|
|||||||
id: int,
|
id: int,
|
||||||
closed: bool,
|
closed: bool,
|
||||||
question: str,
|
question: str,
|
||||||
answers: List[PollAnswer],
|
options: List[PollOption],
|
||||||
answer_chosen: int = None,
|
option_chosen: int = None,
|
||||||
total_voters: int):
|
total_voters: int):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
self.closed = closed
|
self.closed = closed
|
||||||
self.question = question
|
self.question = question
|
||||||
self.answers = answers
|
self.options = options
|
||||||
self.answer_chosen = answer_chosen
|
self.option_chosen = option_chosen
|
||||||
self.total_voters = total_voters
|
self.total_voters = total_voters
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -48,21 +59,21 @@ class Poll(PyrogramType):
|
|||||||
poll = media_poll.poll
|
poll = media_poll.poll
|
||||||
results = media_poll.results.results
|
results = media_poll.results.results
|
||||||
total_voters = media_poll.results.total_voters
|
total_voters = media_poll.results.total_voters
|
||||||
answer_chosen = None
|
option_chosen = None
|
||||||
|
|
||||||
answers = []
|
options = []
|
||||||
|
|
||||||
for i, answer in enumerate(poll.answers):
|
for i, answer in enumerate(poll.answers):
|
||||||
voters = None
|
voters = 0
|
||||||
|
|
||||||
if results:
|
if results:
|
||||||
result = results[i]
|
result = results[i]
|
||||||
voters = result.voters
|
voters = result.voters
|
||||||
|
|
||||||
if result.chosen:
|
if result.chosen:
|
||||||
answer_chosen = i
|
option_chosen = i
|
||||||
|
|
||||||
answers.append(PollAnswer(
|
options.append(PollOption(
|
||||||
text=answer.text,
|
text=answer.text,
|
||||||
voters=voters,
|
voters=voters,
|
||||||
client=client
|
client=client
|
||||||
@ -72,8 +83,8 @@ class Poll(PyrogramType):
|
|||||||
id=poll.id,
|
id=poll.id,
|
||||||
closed=poll.closed,
|
closed=poll.closed,
|
||||||
question=poll.question,
|
question=poll.question,
|
||||||
answers=answers,
|
options=options,
|
||||||
answer_chosen=answer_chosen,
|
option_chosen=option_chosen,
|
||||||
total_voters=total_voters,
|
total_voters=total_voters,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
||||||
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
|
||||||
#
|
|
||||||
# This file is part of Pyrogram.
|
|
||||||
#
|
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
|
||||||
# by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Pyrogram 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 Lesser General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import pyrogram
|
|
||||||
from ..pyrogram_type import PyrogramType
|
|
||||||
|
|
||||||
|
|
||||||
class PollAnswer(PyrogramType):
|
|
||||||
def __init__(self,
|
|
||||||
*,
|
|
||||||
client: "pyrogram.client.ext.BaseClient",
|
|
||||||
text: str,
|
|
||||||
voters: int = None):
|
|
||||||
super().__init__(client)
|
|
||||||
|
|
||||||
self.text = text
|
|
||||||
self.voters = voters
|
|
Loading…
x
Reference in New Issue
Block a user