-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added conversation timeout in ConversationHandler #895
Added conversation timeout in ConversationHandler #895
Conversation
Codecov Report
@@ Coverage Diff @@
## master #895 +/- ##
==========================================
- Coverage 92.25% 91.82% -0.43%
==========================================
Files 103 103
Lines 4169 4060 -109
Branches 669 641 -28
==========================================
- Hits 3846 3728 -118
- Misses 188 193 +5
- Partials 135 139 +4
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Looks good to me. |
telegram/ext/conversationhandler.py
Outdated
@@ -294,6 +303,14 @@ def handle_update(self, update, dispatcher): | |||
""" | |||
new_state = self.current_handler.handle_update(update, dispatcher) | |||
|
|||
if self.timeout_job is not None: | |||
self.timeout_job.schedule_removal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that there is only a single timeout job which gets removed whenever any conversation is triggered?
Wouldn't you want to use a different job for each conversation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This timeout job is triggered in any conversation state, if you mean this. For different ConversationHandler
instances the job is different too.
UPD. Yes, you're right, I have to use a different job.
telegram/ext/conversationhandler.py
Outdated
@@ -124,7 +130,8 @@ def __init__(self, | |||
timed_out_behavior=None, | |||
per_chat=True, | |||
per_user=True, | |||
per_message=False): | |||
per_message=False, | |||
conversation_timeout=0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer None
as the default value for no timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it, but there is no difference, I think.
tests/test_conversationhandler.py
Outdated
@@ -277,3 +277,27 @@ def test_channel_message_without_chat(self, bot): | |||
message = Message(0, None, None, Chat(0, Chat.CHANNEL, 'Misses Test'), bot=bot) | |||
update = Update(0, message=message) | |||
assert not handler.check_update(update) | |||
|
|||
def test_conversation_timeout(self, dp, bot, user1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the comment above, perhaps adding a test for 2 users would be prudent.
@jh0ker Done UPD. This branch is based on an old revision of |
Hi, because you're latest commit has [ci skip] the latest version is not run on CI's and codecov. Could rebase on current master and commit so it will run a full CI? Thanks |
@Eldinnie I know, I marked it because there are no useful changes (I removed a line with comment that is not needed at all) |
Maybe we remove "pending reply" label? |
@evgfilim1 |
@tsnoam done. |
|
@evgfilim1 Thank you for your contribution |
Closes #648
Short usage: