Skip to content

Commit f50fe6c

Browse files
committed
Merge branch 'master' of https://github.com/python-telegram-bot/python-telegram-bot into extract-urls
2 parents 05a26e5 + 0811f56 commit f50fe6c

File tree

13 files changed

+441
-113
lines changed

13 files changed

+441
-113
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The following wonderful people contributed directly or indirectly to this projec
5454
- `Oleg Sushchenko <https://github.com/feuillemorte>`_
5555
- `overquota <https://github.com/overquota>`_
5656
- `Patrick Hofmann <https://github.com/PH89>`_
57+
- `Paul Larsen <https://github.com/PaulSonOfLars>`_
5758
- `Pieter Schutz <https://github.com/eldinnie>`_
5859
- `Rahiel Kasim <https://github.com/rahiel>`_
5960
- `Sascha <https://github.com/saschalalala>`_

CHANGES.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,72 @@
11
=======
22
Changes
33
=======
4+
**2018-03-02**
5+
*Released 10.0.0*
6+
7+
Non backward compatabile changes and changed defaults
8+
9+
- JobQueue: Remove deprecated prevent_autostart & put() (PR `#1012`_)
10+
- Bot, Updater: Remove deprecated network_delay (PR `#1012`_)
11+
- Remove deprecated Message.new_chat_member (PR `#1012`_)
12+
- Retry bootstrap phase indefinitely (by default) on network errors (PR `#1018`_)
13+
14+
New Features
15+
16+
- Support v3.6 API (PR `#1006`_)
17+
- User.full_name convinience property (PR `#949`_)
18+
- Add `send_phone_number_to_provider` and `send_email_to_provider` arguments to send_invoice (PR `#986`_)
19+
- Bot: Add shortcut methods reply_{markdown,html} (PR `#827`_)
20+
- Bot: Add shortcut method reply_media_group (PR `#994`_)
21+
- Added utils.helpers.effective_message_type (PR `#826`_)
22+
- Bot.get_file now allows passing a file in addition to file_id (PR `#963`_)
23+
- Add .get_file() to Audio, Document, PhotoSize, Sticker, Video, VideoNote and Voice (PR `#963`_)
24+
- Add .send_*() methods to User and Chat (PR `#963`_)
25+
- Get jobs by name (PR `#1011`_)
26+
- Add Message caption html/markdown methods (PR `#1013`_)
27+
- File.download_as_bytearray - new method to get a d/led file as bytearray (PR `#1019`_)
28+
- File.download(): Now returns a meaningful return value (PR `#1019`_)
29+
- Added conversation timeout in ConversationHandler (PR `#895`_)
30+
31+
Changes
32+
33+
- Store bot in PreCheckoutQuery (PR `#953`_)
34+
- Updater: Issue INFO log upon received signal (PR `#951`_)
35+
- JobQueue: Thread safety fixes (PR `#977`_)
36+
- WebhookHandler: Fix exception thrown during error handling (PR `#985`_)
37+
- Explicitly check update.effective_chat in ConversationHandler.check_update (PR `#959`_)
38+
- Updater: Better handling of timeouts during get_updates (PR `#1007`_)
39+
- Remove unnecessary to_dict() (PR `#834`_)
40+
- CommandHandler - ignore strings in entities and "/" followed by whitespace (PR `#1020`_)
41+
- Documentation & style fixes (PR `#942`_, PR `#956`_, PR `#962`_, PR `#980`_, PR `#983`_)
42+
43+
.. _`#826`: https://github.com/python-telegram-bot/python-telegram-bot/pull/826
44+
.. _`#827`: https://github.com/python-telegram-bot/python-telegram-bot/pull/827
45+
.. _`#834`: https://github.com/python-telegram-bot/python-telegram-bot/pull/834
46+
.. _`#895`: https://github.com/python-telegram-bot/python-telegram-bot/pull/895
47+
.. _`#942`: https://github.com/python-telegram-bot/python-telegram-bot/pull/942
48+
.. _`#949`: https://github.com/python-telegram-bot/python-telegram-bot/pull/949
49+
.. _`#951`: https://github.com/python-telegram-bot/python-telegram-bot/pull/951
50+
.. _`#956`: https://github.com/python-telegram-bot/python-telegram-bot/pull/956
51+
.. _`#953`: https://github.com/python-telegram-bot/python-telegram-bot/pull/953
52+
.. _`#962`: https://github.com/python-telegram-bot/python-telegram-bot/pull/962
53+
.. _`#959`: https://github.com/python-telegram-bot/python-telegram-bot/pull/959
54+
.. _`#963`: https://github.com/python-telegram-bot/python-telegram-bot/pull/963
55+
.. _`#977`: https://github.com/python-telegram-bot/python-telegram-bot/pull/977
56+
.. _`#980`: https://github.com/python-telegram-bot/python-telegram-bot/pull/980
57+
.. _`#983`: https://github.com/python-telegram-bot/python-telegram-bot/pull/983
58+
.. _`#985`: https://github.com/python-telegram-bot/python-telegram-bot/pull/985
59+
.. _`#986`: https://github.com/python-telegram-bot/python-telegram-bot/pull/986
60+
.. _`#994`: https://github.com/python-telegram-bot/python-telegram-bot/pull/994
61+
.. _`#1006`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1006
62+
.. _`#1007`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1007
63+
.. _`#1011`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1011
64+
.. _`#1012`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1012
65+
.. _`#1013`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1013
66+
.. _`#1018`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1018
67+
.. _`#1019`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1019
68+
.. _`#1020`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1020
69+
470
**2017-12-08**
571
*Released 9.0.0*
672

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
# built documents.
5959
#
6060
# The short X.Y version.
61-
version = '9.0' # telegram.__version__[:3]
61+
version = '10.0' # telegram.__version__[:3]
6262
# The full version, including alpha/beta/rc tags.
63-
release = '9.0.0' # telegram.__version__
63+
release = '10.0.0' # telegram.__version__
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ objects in the package reflect the types as defined by the `telegram bot api <ht
1515
Changelog
1616
---------
1717

18-
.. include:: ..\\..\\CHANGES.rst
18+
.. include:: ../../CHANGES.rst
1919

2020
Indices and tables
2121
==================

telegram/ext/commandhandler.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,23 @@ def check_update(self, update):
134134
message = update.message or update.edited_message
135135

136136
if message.text and message.text.startswith('/') and len(message.text) > 1:
137-
command = message.text[1:].split(None, 1)[0].split('@')
138-
command.append(
139-
message.bot.username) # in case the command was send without a username
140-
141-
if self.filters is None:
142-
res = True
143-
elif isinstance(self.filters, list):
144-
res = any(func(message) for func in self.filters)
145-
else:
146-
res = self.filters(message)
147-
148-
return res and (command[0].lower() in self.command
149-
and command[1].lower() == message.bot.username.lower())
150-
else:
151-
return False
152-
153-
else:
154-
return False
137+
first_word = message.text_html.split(None, 1)[0]
138+
if len(first_word) > 1 and first_word.startswith('/'):
139+
command = first_word[1:].split('@')
140+
command.append(
141+
message.bot.username) # in case the command was sent without a username
142+
143+
if self.filters is None:
144+
res = True
145+
elif isinstance(self.filters, list):
146+
res = any(func(message) for func in self.filters)
147+
else:
148+
res = self.filters(message)
149+
150+
return res and (command[0].lower() in self.command
151+
and command[1].lower() == message.bot.username.lower())
152+
153+
return False
155154

156155
def handle_update(self, update, dispatcher):
157156
"""Send the update to the :attr:`callback`.

telegram/ext/conversationhandler.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ConversationHandler(Handler):
5555
To change the state of conversation, the callback function of a handler must return the new
5656
state after responding to the user. If it does not return anything (returning ``None`` by
5757
default), the state will not change. To end the conversation, the callback function must
58-
return :attr`END` or ``-1``.
58+
return :attr:`END` or ``-1``.
5959
6060
Attributes:
6161
entry_points (List[:class:`telegram.ext.Handler`]): A list of ``Handler`` objects that can
@@ -76,6 +76,9 @@ class ConversationHandler(Handler):
7676
per_user (:obj:`bool`): Optional. If the conversationkey should contain the User's ID.
7777
per_message (:obj:`bool`): Optional. If the conversationkey should contain the Message's
7878
ID.
79+
conversation_timeout (:obj:`float`|:obj:`datetime.timedelta`): Optional. When this handler
80+
is inactive more than this timeout (in seconds), it will be automatically ended. If
81+
this value is 0 (default), there will be no timeout.
7982
8083
Args:
8184
entry_points (List[:class:`telegram.ext.Handler`]): A list of ``Handler`` objects that can
@@ -107,6 +110,9 @@ class ConversationHandler(Handler):
107110
Default is ``True``.
108111
per_message (:obj:`bool`, optional): If the conversationkey should contain the Message's
109112
ID. Default is ``False``.
113+
conversation_timeout (:obj:`float`|:obj:`datetime.timedelta`, optional): When this handler
114+
is inactive more than this timeout (in seconds), it will be automatically ended. If
115+
this value is 0 or None (default), there will be no timeout.
110116
111117
Raises:
112118
ValueError
@@ -124,7 +130,8 @@ def __init__(self,
124130
timed_out_behavior=None,
125131
per_chat=True,
126132
per_user=True,
127-
per_message=False):
133+
per_message=False,
134+
conversation_timeout=None):
128135

129136
self.entry_points = entry_points
130137
self.states = states
@@ -136,7 +143,9 @@ def __init__(self,
136143
self.per_user = per_user
137144
self.per_chat = per_chat
138145
self.per_message = per_message
146+
self.conversation_timeout = conversation_timeout
139147

148+
self.timeout_jobs = dict()
140149
self.conversations = dict()
141150
self.current_conversation = None
142151
self.current_handler = None
@@ -294,6 +303,16 @@ def handle_update(self, update, dispatcher):
294303
295304
"""
296305
new_state = self.current_handler.handle_update(update, dispatcher)
306+
timeout_job = self.timeout_jobs.get(self.current_conversation)
307+
308+
if timeout_job is not None or new_state == self.END:
309+
timeout_job.schedule_removal()
310+
del self.timeout_jobs[self.current_conversation]
311+
if self.conversation_timeout and new_state != self.END:
312+
self.timeout_jobs[self.current_conversation] = dispatcher.job_queue.run_once(
313+
self._trigger_timeout, self.conversation_timeout,
314+
context=self.current_conversation
315+
)
297316

298317
self.update_state(new_state, self.current_conversation)
299318

@@ -309,3 +328,6 @@ def update_state(self, new_state, key):
309328

310329
elif new_state is not None:
311330
self.conversations[key] = new_state
331+
332+
def _trigger_timeout(self, bot, job):
333+
self.update_state(self.END, job.context)

0 commit comments

Comments
 (0)