Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions docs/source/telegram.replykeyboardhide.rst

This file was deleted.

7 changes: 7 additions & 0 deletions docs/source/telegram.replykeyboardremove.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
telegram.replykeyboardremove module
===================================

.. automodule:: telegram.replykeyboardremove
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Submodules
telegram.messageentity
telegram.parsemode
telegram.photosize
telegram.replykeyboardhide
telegram.replykeyboardremove
telegram.replykeyboardmarkup
telegram.replymarkup
telegram.sticker
Expand Down
6 changes: 3 additions & 3 deletions examples/conversationbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
bot.
"""

from telegram import (ReplyKeyboardMarkup, ReplyKeyboardHide)
from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove)
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
ConversationHandler)

Expand Down Expand Up @@ -49,7 +49,7 @@ def gender(bot, update):
logger.info("Gender of %s: %s" % (user.first_name, update.message.text))
update.message.reply_text('I see! Please send me a photo of yourself, '
'so I know what you look like, or send /skip if you don\'t want to.',
reply_markup=ReplyKeyboardHide())
reply_markup=ReplyKeyboardRemove())

return PHOTO

Expand Down Expand Up @@ -106,7 +106,7 @@ def cancel(bot, update):
user = update.message.from_user
logger.info("User %s canceled the conversation." % user.first_name)
update.message.reply_text('Bye! I hope we can talk again some day.',
reply_markup=ReplyKeyboardHide())
reply_markup=ReplyKeyboardRemove())

return ConversationHandler.END

Expand Down
8 changes: 4 additions & 4 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from .keyboardbutton import KeyboardButton
from .replymarkup import ReplyMarkup
from .replykeyboardmarkup import ReplyKeyboardMarkup
from .replykeyboardhide import ReplyKeyboardHide
from .replykeyboardremove import ReplyKeyboardRemove, ReplyKeyboardHide
from .forcereply import ForceReply
from .error import TelegramError
from .inputfile import InputFile
Expand Down Expand Up @@ -106,9 +106,9 @@
'InlineQueryResultVoice', 'InlineQueryResultGame', 'InputContactMessageContent', 'InputFile',
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
'ParseMode', 'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker',
'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue', 'Video',
'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'ParseMode', 'PhotoSize', 'ReplyKeyboardRemove', 'ReplyKeyboardMarkup', 'ReplyMarkup',
'Sticker', 'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue',
'Video', 'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
'Game', 'GameHighScore'
Expand Down
9 changes: 7 additions & 2 deletions telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ def print_ver_info():
print('future {0}'.format(future.__version__))
print('Python {0}'.format(sys.version.replace('\n', ' ')))

# main
print_ver_info()

def main():
print_ver_info()


if __name__ == '__main__':
main()
68 changes: 53 additions & 15 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import functools
import logging
import warnings

from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore)
Expand Down Expand Up @@ -208,7 +209,7 @@ def sendMessage(self,
ID of the original message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional
interface options. A JSON-serialized object for an inline
keyboard, custom reply keyboard, instructions to hide reply
keyboard, custom reply keyboard, instructions to remove reply
keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as
the definitive timeout (in seconds) for urlopen() operations.
Expand Down Expand Up @@ -299,7 +300,7 @@ def sendPhoto(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -360,7 +361,7 @@ def sendAudio(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -415,7 +416,7 @@ def sendDocument(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -461,7 +462,7 @@ def sendSticker(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -508,7 +509,7 @@ def sendVideo(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.

Expand Down Expand Up @@ -561,7 +562,7 @@ def sendVoice(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -607,7 +608,7 @@ def sendLocation(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -656,7 +657,7 @@ def sendVenue(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -710,7 +711,7 @@ def sendContact(self,
message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -749,7 +750,7 @@ def sendGame(self, chat_id, game_short_name, **kwargs):
ID of the original message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options.
A JSON-serialized object for an inline keyboard, custom reply keyboard,
instructions to hide reply keyboard or to force a reply from the user.
instructions to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as
the definitive timeout (in seconds) for urlopen() operations.

Expand Down Expand Up @@ -987,6 +988,7 @@ def answerCallbackQuery(self,
text=None,
show_alert=False,
url=None,
cache_time=None,
timeout=None,
**kwargs):
"""Use this method to send answers to callback queries sent from inline keyboards. The
Expand All @@ -999,9 +1001,12 @@ def answerCallbackQuery(self,
to the user.
show_alert (Optional[bool]): If `True`, an alert will be shown by the client instead of
a notification at the top of the chat screen. Defaults to `False`.
url (Optional[str]): URL that will be opened by the user's client.
cache_time (Optional[int]): The maximum amount of time in seconds that the result of
the callback query may be cached client-side. Telegram apps will support caching
starting in version 3.14. Defaults to 0.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
url (Optional[str]): URL that will be opened by the user's client.
**kwargs (dict): Arbitrary keyword arguments.

Returns:
Expand All @@ -1021,6 +1026,8 @@ def answerCallbackQuery(self,
data['show_alert'] = show_alert
if url:
data['url'] = url
if cache_time is not None:
data['cache_time'] = cache_time

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

Expand Down Expand Up @@ -1054,7 +1061,7 @@ def editMessageText(self,
reply_markup: A JSON-serialized object for an inline keyboard.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to hide reply keyboard or to force a reply from the user.
to remove reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
**kwargs (dict): Arbitrary keyword arguments.
Expand Down Expand Up @@ -1434,9 +1441,32 @@ def setGameScore(self,
message_id=None,
inline_message_id=None,
edit_message=None,
force=None,
disable_edit_message=None,
**kwargs):
"""Use this method to set the score of the specified user in a game.

Args:
user_id (int): User identifier.
score (int): New score, must be non-negative.
chat_id (Optional[int|str]): Required if `inline_message_id` is not specified. Unique
identifier for the target chat (or username of the target channel in the format
`@channelusername`)
message_id (Optional[int]): Required if inline_message_id is not specified. Identifier
of the sent message.
inline_message_id (Optional[str]): Required if chat_id and message_id are not
specified. Identifier of the inline message.
force (Optional[bool]): Pass True, if the high score is allowed to decrease. This can
be useful when fixing mistakes or banning cheaters.
disable_edit_message (Optional[bool]): Pass True, if the game message should not be
automatically edited to include the current scoreboard.
edit_message (Optional[bool]): Deprecated. Has the opposite logic for
`disable_edit_message`.

Keyword Args:
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.

Returns:
:class:`telegram.Message` or True: The edited message, or if the
message wasn't sent by the bot, True.
Expand All @@ -1452,8 +1482,16 @@ def setGameScore(self,
data['message_id'] = message_id
if inline_message_id:
data['inline_message_id'] = inline_message_id
if edit_message:
data['edit_message'] = edit_message
if force is not None:
data['force'] = force
if disable_edit_message is not None:
data['disable_edit_message'] = disable_edit_message
if edit_message is not None:
warnings.warn('edit_message is deprecated, use disable_edit_message instead')
if disable_edit_message is None:
data['edit_message'] = edit_message
else:
warnings.warn('edit_message is ignored when disable_edit_message is used')

result = self._request.post(url, data, timeout=kwargs.get('timeout'))
if result is True:
Expand Down
31 changes: 26 additions & 5 deletions telegram/ext/messagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class MessageHandler(Handler):

Args:
filters (telegram.ext.BaseFilter): A filter inheriting from
:class:`telegram.filters.BaseFilter`. Standard filters can be found in
:class:`telegram.filters.Filters`. Filters can be combined using bitwise
:class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in
:class:`telegram.ext.filters.Filters`. Filters can be combined using bitwise
operators (& for and, | for or).
callback (function): A function that takes ``bot, update`` as
positional arguments. It will be called when the ``check_update``
Expand All @@ -51,6 +51,11 @@ class MessageHandler(Handler):
``chat_data`` will be passed to the callback function. It will be a ``dict`` you
can use to keep any data related to the chat that the update was sent in.
For each update in the same chat, it will be the same ``dict``. Default is ``False``.
message_updates (Optional[bool]): Should "normal" message updates be handled? Default is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could use a filter for this instead? Now that it is actually possible to use more than one filter. Or is it more clear/explicit and nice using this method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is okay, it's also the same way as we implemented edited messages

``True``.
channel_posts_updates (Optional[bool]): Should channel posts updates be handled? Default is
``True``.

"""

def __init__(self,
Expand All @@ -60,7 +65,12 @@ def __init__(self,
pass_update_queue=False,
pass_job_queue=False,
pass_user_data=False,
pass_chat_data=False):
pass_chat_data=False,
message_updates=True,
channel_posts_updates=True):
if not message_updates and not channel_posts_updates:
raise ValueError('Both message_updates & channel_post_updates are False')

super(MessageHandler, self).__init__(
callback,
pass_update_queue=pass_update_queue,
Expand All @@ -69,6 +79,8 @@ def __init__(self,
pass_chat_data=pass_chat_data)
self.filters = filters
self.allow_edited = allow_edited
self.message_updates = message_updates
self.channel_posts_updates = channel_posts_updates

# We put this up here instead of with the rest of checking code
# in check_update since we don't wanna spam a ton
Expand All @@ -77,15 +89,24 @@ def __init__(self,
'deprecated, please use bitwise operators (& and |) '
'instead. More info: https://git.io/vPTbc.')

def _is_allowed_message(self, update):
return (self.message_updates
and (update.message or (update.edited_message and self.allow_edited)))

def _is_allowed_channel_post(self, update):
return (self.channel_posts_updates
and (update.channel_post or (update.edited_channel_post and self.allow_edited)))

def check_update(self, update):
if (isinstance(update, Update)
and (update.message or update.edited_message and self.allow_edited)):
and (self._is_allowed_message(update) or self._is_allowed_channel_post(update))):

if not self.filters:
res = True

else:
message = update.message or update.edited_message
message = (update.message or update.edited_message or update.channel_post
or update.edited_channel_post)
if isinstance(self.filters, list):
res = any(func(message) for func in self.filters)
else:
Expand Down
Loading