Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

All api 4.2 and 4.3 changes#1418

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tsnoam merged 6 commits intomasterfromV12
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
6 changes: 3 additions & 3 deletions.pre-commit-config.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
repos:
- repo: git://github.com/python-telegram-bot/mirrors-yapf
rev: master
sha: 5769e088ef6e0a0d1eb63bd6d0c1fe9f3606d6c8
hooks:
- id: yapf
files: ^(telegram|tests)/.*\.py$
args:
- --diff
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
sha: 0b70e285e369bcb24b57b74929490ea7be9c4b19
hooks:
- id: flake8
exclude: ^(setup.py|docs/source/conf.py)$
args:
- --ignore=W605,W503
- repo: git://github.com/pre-commit/mirrors-pylint
rev: v2.3.0
sha: 9d8dcbc2b86c796275680f239c1e90dcd50bd398
hooks:
- id: pylint
files: ^telegram/.*\.py$
Expand Down
1 change: 0 additions & 1 deletionappveyor.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,6 @@ environment:
# isn't covered by this document) at the time of writing.

- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python34"
- PYTHON: "C:\\Python35"
- PYTHON: "C:\\Python36"
- PYTHON: "C:\\Python37"
Expand Down
6 changes: 6 additions & 0 deletionsdocs/source/telegram.poll.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
telegram.Poll
=============

.. autoclass:: telegram.Poll
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletionsdocs/source/telegram.polloption.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
telegram.PollOption
===================

.. autoclass:: telegram.PollOption
:members:
:show-inheritance:
2 changes: 2 additions & 0 deletionsdocs/source/telegram.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,8 @@ telegram package
telegram.messageentity
telegram.parsemode
telegram.photosize
telegram.poll
telegram.polloption
telegram.replykeyboardremove
telegram.replykeyboardmarkup
telegram.replymarkup
Expand Down
9 changes: 6 additions & 3 deletionstelegram/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,8 @@
from .parsemode import ParseMode
from .messageentity import MessageEntity
from .games.game import Game
from .poll import Poll, PollOption
from .loginurl import LoginUrl
from .games.callbackgame import CallbackGame
from .payment.shippingaddress import ShippingAddress
from .payment.orderinfo import OrderInfo
Expand All@@ -57,11 +59,11 @@
from .passport.data import IdDocumentData, PersonalDetails, ResidentialAddress
from .passport.encryptedpassportelement import EncryptedPassportElement
from .passport.passportdata import PassportData
from .inline.inlinekeyboardbutton import InlineKeyboardButton
from .inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from .message import Message
from .callbackquery import CallbackQuery
from .choseninlineresult import ChosenInlineResult
from .inline.inlinekeyboardbutton import InlineKeyboardButton
from .inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from .inline.inputmessagecontent import InputMessageContent
from .inline.inlinequery import InlineQuery
from .inline.inlinequeryresult import InlineQueryResult
Expand DownExpand Up@@ -152,5 +154,6 @@
'PersonalDetails', 'ResidentialAddress', 'InputMediaVideo', 'InputMediaAnimation',
'InputMediaAudio', 'InputMediaDocument', 'TelegramDecryptionError',
'PassportElementErrorSelfie', 'PassportElementErrorTranslationFile',
'PassportElementErrorTranslationFiles', 'PassportElementErrorUnspecified'
'PassportElementErrorTranslationFiles', 'PassportElementErrorUnspecified', 'Poll',
'PollOption', 'LoginUrl'
]
118 changes: 110 additions & 8 deletionstelegram/bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@
from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore, StickerSet,
PhotoSize, Audio, Document, Sticker, Video, Animation, Voice, VideoNote,
Location, Venue, Contact, InputFile)
Location, Venue, Contact, InputFile, Poll)
from telegram.error import InvalidToken, TelegramError
from telegram.utils.helpers import to_timestamp
from telegram.utils.request import Request
Expand DownExpand Up@@ -260,13 +260,16 @@ def send_message(self,
@log
def delete_message(self, chat_id, message_id, timeout=None, **kwargs):
"""
Use this method to delete a message. A message can only be deleted if it was sent less
than 48 hours ago. Any such recently sent outgoing message may be deleted. Additionally,
if the bot is an administrator in a group chat, it can delete any message. If the bot is
an administrator in a supergroup, it can delete messages from any other user and service
messages about people joining or leaving the group (other types of service messages may
only be removed by the group creator). In channels, bots can only remove their own
messages.
Use this method to delete a message, including service messages, with the following
limitations:

- A message can only be deleted if it was sent less than 48 hours ago.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots can delete incoming messages in private chats.
- Bots granted can_post_messages permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has can_delete_messages permission in a supergroup or a channel, it can
delete any message there.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand DownExpand Up@@ -3319,6 +3322,101 @@ def set_passport_data_errors(self, user_id, errors, timeout=None, **kwargs):

return result

@log
def send_poll(self,
chat_id,
question,
options,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None,
timeout=None,
**kwargs):
"""
Use this method to send a native poll. A native poll can't be sent to a private chat.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target private chat.
question (:obj:`str`): Poll question, 1-255 characters.
options (List[:obj:`str`]): List of answer options, 2-10 strings 1-100 characters each.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
original message.
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to remove reply keyboard or to force a reply from the user.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

Returns:
:class:`telegram.Message`: On success, the sent Message is returned.

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/sendPoll'.format(self.base_url)

data = {
'chat_id': chat_id,
'question': question,
'options': options
}

return self._message(url, data, timeout=timeout, disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id, reply_markup=reply_markup,
**kwargs)

@log
def stop_poll(self,
chat_id,
message_id,
reply_markup=None,
timeout=None,
**kwargs):
"""
Use this method to stop a poll which was sent by the bot.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
message_id (:obj:`int`): Identifier of the original message with the poll.
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to remove reply keyboard or to force a reply from the user.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

Returns:
:class:`telegram.Poll`: On success, the stopped Poll with the
final results is returned.

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/stopPoll'.format(self.base_url)

data = {
'chat_id': chat_id,
'message_id': message_id
}

if reply_markup:
if isinstance(reply_markup, ReplyMarkup):
data['reply_markup'] = reply_markup.to_json()
else:
data['reply_markup'] = reply_markup

result = self._request.post(url, data, timeout=timeout)

return Poll.de_json(result, self)

def to_dict(self):
data = {'id': self.id, 'username': self.username, 'first_name': self.username}

Expand DownExpand Up@@ -3456,3 +3554,7 @@ def __reduce__(self):
"""Alias for :attr:`delete_sticker_from_set`"""
setPassportDataErrors = set_passport_data_errors
"""Alias for :attr:`set_passport_data_errors`"""
sendPoll = send_poll
"""Alias for :attr:`send_poll`"""
stopPoll = stop_poll
"""Alias for :attr:`stop_poll`"""
13 changes: 13 additions & 0 deletionstelegram/chat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -337,3 +337,16 @@ def send_voice(self, *args, **kwargs):

"""
return self.bot.send_voice(self.id, *args, **kwargs)

def send_poll(self, *args, **kwargs):
"""Shortcut for::

bot.send_poll(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

"""
return self.bot.send_poll(self.id, *args, **kwargs)
7 changes: 6 additions & 1 deletiontelegram/chatmember.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,8 @@ class ChatMember(TelegramObject):
can_pin_messages (:obj:`bool`): Optional. If the administrator can pin messages.
can_promote_members (:obj:`bool`): Optional. If the administrator can add new
administrators.
is_member (:obj:`bool`): Optional. Restricted only. True, if the user is a member of the
chat at the moment of the request.
can_send_messages (:obj:`bool`): Optional. If the user can send text messages, contacts,
locations and venues.
can_send_media_messages (:obj:`bool`): Optional. If the user can send media messages,
Expand DownExpand Up@@ -81,6 +83,8 @@ class ChatMember(TelegramObject):
administrator can add new administrators with a subset of his own privileges or demote
administrators that he has promoted, directly or indirectly (promoted by administrators
that were appointed by the user).
is_member (:obj:`bool`, optional): Restricted only. True, if the user is a member of the
chat at the moment of the request.
can_send_messages (:obj:`bool`, optional): Restricted only. True, if the user can send text
messages, contacts, locations and venues.
can_send_media_messages (:obj:`bool`, optional): Restricted only. True, if the user can
Expand DownExpand Up@@ -111,7 +115,7 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
can_restrict_members=None, can_pin_messages=None,
can_promote_members=None, can_send_messages=None,
can_send_media_messages=None, can_send_other_messages=None,
can_add_web_page_previews=None, **kwargs):
can_add_web_page_previews=None,is_member=None,**kwargs):
# Required
self.user = user
self.status = status
Expand All@@ -129,6 +133,7 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
self.can_send_media_messages = can_send_media_messages
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.is_member = is_member

self._id_attrs = (self.user, self.status)

Expand Down
32 changes: 26 additions & 6 deletionstelegram/inline/inlinekeyboardbutton.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,8 @@ class InlineKeyboardButton(TelegramObject):
Attributes:
text (:obj:`str`): Label text on the button.
url (:obj:`str`): Optional. HTTP url to be opened when button is pressed.
login_url (:class:`telegram.LoginUrl`) Optional. An HTTP URL used to automatically
authorize the user.
callback_data (:obj:`str`): Optional. Data to be sent in a callback query to the bot when
button is pressed, UTF-8 1-64 bytes.
switch_inline_query (:obj:`str`): Optional. Will prompt the user to select one of their
Expand All@@ -45,6 +47,8 @@ class InlineKeyboardButton(TelegramObject):
Args:
text (:obj:`str`): Label text on the button.
url (:obj:`str`): HTTP url to be opened when button is pressed.
login_url (:class:`telegram.LoginUrl`, optional) An HTTP URL used to automatically
authorize the user.
callback_data (:obj:`str`, optional): Data to be sent in a callback query to the bot when
button is pressed, 1-64 UTF-8 bytes.
switch_inline_query (:obj:`str`, optional): If set, pressing the button will prompt the
Expand DownExpand Up@@ -76,14 +80,30 @@ def __init__(self,
switch_inline_query_current_chat=None,
callback_game=None,
pay=None,
login_url=None,
**kwargs):
# Required
self.text = text

# Optionals
self.url = url
self.callback_data = callback_data
self.switch_inline_query = switch_inline_query
self.switch_inline_query_current_chat = switch_inline_query_current_chat
self.callback_game = callback_game
self.pay = pay
if url:
self.url = url
if login_url:
self.login_url = login_url
if callback_data:
self.callback_data = callback_data
if switch_inline_query:
self.switch_inline_query = switch_inline_query
if switch_inline_query_current_chat:
self.switch_inline_query_current_chat = switch_inline_query_current_chat
if callback_game:
self.callback_game = callback_game
if pay:
self.pay = pay

@classmethod
def de_json(cls, data, bot):
if not data:
return None

return cls(**data)
15 changes: 14 additions & 1 deletiontelegram/inline/inlinekeyboardmarkup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram InlineKeyboardMarkup."""

from telegram import ReplyMarkup
from telegram import ReplyMarkup, InlineKeyboardButton


class InlineKeyboardMarkup(ReplyMarkup):
Expand DownExpand Up@@ -49,6 +49,19 @@ def to_dict(self):

return data

@classmethod
def de_json(cls, data, bot):
if not data:
return None
keyboard = []
for row in data['inline_keyboard']:
tmp = []
for col in row:
tmp.append(InlineKeyboardButton.de_json(col, bot))
keyboard.append(tmp)

return cls(keyboard)

@classmethod
def from_button(cls, button, **kwargs):
"""Shortcut for::
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp