Bot API 4.6

This commit is contained in:
gabbhack 2020-01-23 20:23:08 +05:00
parent 7afe783914
commit ee803303aa
7 changed files with 141 additions and 2 deletions

View file

@ -18,6 +18,7 @@ class MessageEntity(base.TelegramObject):
length: base.Integer = fields.Field()
url: base.String = fields.Field()
user: User = fields.Field(base=User)
langugage: base.String = fields.Field()
def get_text(self, text):
"""

View file

@ -2,15 +2,42 @@ import typing
from . import base
from . import fields
from .user import User
class PollOption(base.TelegramObject):
"""
This object contains information about one answer option in a poll.
https://core.telegram.org/bots/api#polloption
"""
text: base.String = fields.Field()
voter_count: base.Integer = fields.Field()
class PollAnswer(base.TelegramObject):
"""
This object represents an answer of a user in a non-anonymous poll.
https://core.telegram.org/bots/api#pollanswer
"""
poll_id: base.String = fields.Field()
user: User = fields.Field()
option_ids: typing.List[base.Integer] = fields.ListField()
class Poll(base.TelegramObject):
"""
This object contains information about a poll.
https://core.telegram.org/bots/api#poll
"""
id: base.String = fields.Field()
question: base.String = fields.Field()
options: typing.List[PollOption] = fields.ListField(base=PollOption)
total_voter_count: base.Integer = fields.Field()
is_closed: base.Boolean = fields.Field()
is_anonymous: base.Boolean = fields.Field()
poll_type: base.String = fields.Field(alias="type")
allows_multiple_answers: base.Boolean = fields.Field()
correct_option_id: base.Integer = fields.Field()

View file

@ -4,6 +4,18 @@ from . import base
from . import fields
class KeyboardButtonPollType(base.TelegramObject):
"""
This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed.
https://core.telegram.org/bots/api#keyboardbuttonpolltype
"""
poll_type: base.String = fields.Field(alias="type")
def __init__(self, poll_type: base.String):
super(KeyboardButtonPollType, self).__init__(poll_type=poll_type)
class ReplyKeyboardMarkup(base.TelegramObject):
"""
This object represents a custom keyboard with reply options (see Introduction to bots for details and examples).
@ -81,14 +93,16 @@ class ReplyKeyboardMarkup(base.TelegramObject):
class KeyboardButton(base.TelegramObject):
"""
This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive.
This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields request_contact, request_location, and request_poll are mutually exclusive.
Note: request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them.
Note: request_poll option will only work in Telegram versions released after 23 January, 2020. Older clients will receive unsupported message.
https://core.telegram.org/bots/api#keyboardbutton
"""
text: base.String = fields.Field()
request_contact: base.Boolean = fields.Field()
request_location: base.Boolean = fields.Field()
request_poll: KeyboardButtonPollType = fields.Field()
def __init__(self, text: base.String,
request_contact: base.Boolean = None,

View file

@ -6,7 +6,7 @@ from .callback_query import CallbackQuery
from .chosen_inline_result import ChosenInlineResult
from .inline_query import InlineQuery
from .message import Message
from .poll import Poll
from .poll import Poll, PollAnswer
from .pre_checkout_query import PreCheckoutQuery
from .shipping_query import ShippingQuery
from ..utils import helper
@ -30,6 +30,7 @@ class Update(base.TelegramObject):
shipping_query: ShippingQuery = fields.Field(base=ShippingQuery)
pre_checkout_query: PreCheckoutQuery = fields.Field(base=PreCheckoutQuery)
poll: Poll = fields.Field(base=Poll)
poll_answer: PollAnswer = fields.Field(base=PollAnswer)
def __hash__(self):
return self.update_id
@ -58,3 +59,5 @@ class AllowedUpdates(helper.Helper):
CALLBACK_QUERY = helper.ListItem() # callback_query
SHIPPING_QUERY = helper.ListItem() # shipping_query
PRE_CHECKOUT_QUERY = helper.ListItem() # pre_checkout_query
POLL = helper.ListItem() # poll
POLL_ANSWER = helper.ListItem() # poll_answer

View file

@ -22,6 +22,9 @@ class User(base.TelegramObject):
last_name: base.String = fields.Field()
username: base.String = fields.Field()
language_code: base.String = fields.Field()
can_join_groups: base.Boolean = fields.Field()
can_read_all_group_messages: base.Boolean = fields.Field()
supports_inline_queries: base.Boolean = fields.Field()
@property
def full_name(self):