-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make job queue API similar to the dispatcher, add new functionality #307
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
Changes from all commits
6b90ac9
3aedd78
8278779
b3142d2
7862163
41daccc
20067ff
bb165b6
e7f4a07
2534e0d
406303d
783f9c3
d40f0a8
de2d732
b08d41d
738e321
c4a8ee5
02af1ea
f65b691
35872d7
1e0ebe8
3107310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,20 @@ class ChosenInlineResultHandler(Handler): | |
callback (function): A function that takes ``bot, update`` as | ||
positional arguments. It will be called when the ``check_update`` | ||
has determined that an update should be processed by this handler. | ||
pass_update_queue (optional[bool]): If the handler should be passed the | ||
update queue as a keyword argument called ``update_queue``. It can | ||
be used to insert updates. Default is ``False`` | ||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``update_queue`` will be passed to the callback function. It will be the ``Queue`` | ||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can | ||
be used to insert updates. Default is ``False``. | ||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue`` | ||
instance created by the ``Updater`` which can be used to schedule new jobs. | ||
Default is ``False``. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as for |
||
|
||
def __init__(self, callback, pass_update_queue=False): | ||
super(ChosenInlineResultHandler, self).__init__(callback, pass_update_queue) | ||
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False): | ||
super(ChosenInlineResultHandler, self).__init__(callback, | ||
pass_update_queue=pass_update_queue, | ||
pass_job_queue=pass_job_queue) | ||
|
||
def check_update(self, update): | ||
return isinstance(update, Update) and update.chosen_inline_result | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,18 +40,26 @@ class CommandHandler(Handler): | |
arguments passed to the command as a keyword argument called ` | ||
``args``. It will contain a list of strings, which is the text | ||
following the command split on spaces. Default is ``False`` | ||
pass_update_queue (optional[bool]): If the handler should be passed the | ||
update queue as a keyword argument called ``update_queue``. It can | ||
be used to insert updates. Default is ``False`` | ||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``update_queue`` will be passed to the callback function. It will be the ``Queue`` | ||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can | ||
be used to insert updates. Default is ``False``. | ||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue`` | ||
instance created by the ``Updater`` which can be used to schedule new jobs. | ||
Default is ``False``. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
|
||
def __init__(self, | ||
command, | ||
callback, | ||
allow_edited=False, | ||
pass_args=False, | ||
pass_update_queue=False): | ||
super(CommandHandler, self).__init__(callback, pass_update_queue) | ||
pass_update_queue=False, | ||
pass_job_queue=False): | ||
super(CommandHandler, self).__init__(callback, | ||
pass_update_queue=pass_update_queue, | ||
pass_job_queue=pass_job_queue) | ||
self.command = command | ||
self.allow_edited = allow_edited | ||
self.pass_args = pass_args | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,20 @@ class Handler(object): | |
callback (function): A function that takes ``bot, update`` as | ||
positional arguments. It will be called when the ``check_update`` | ||
has determined that an update should be processed by this handler. | ||
pass_update_queue (optional[bool]): If the callback should be passed | ||
the update queue as a keyword argument called ``update_queue``. It | ||
can be used to insert updates. Default is ``False`` | ||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``update_queue`` will be passed to the callback function. It will be the ``Queue`` | ||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can | ||
be used to insert updates. Default is ``False``. | ||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue`` | ||
instance created by the ``Updater`` which can be used to schedule new jobs. | ||
Default is ``False``. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as for |
||
|
||
def __init__(self, callback, pass_update_queue=False): | ||
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False): | ||
self.callback = callback | ||
self.pass_update_queue = pass_update_queue | ||
self.pass_job_queue = pass_job_queue | ||
|
||
def check_update(self, update): | ||
""" | ||
|
@@ -77,6 +83,8 @@ def collect_optional_args(self, dispatcher): | |
optional_args = dict() | ||
if self.pass_update_queue: | ||
optional_args['update_queue'] = dispatcher.update_queue | ||
if self.pass_job_queue: | ||
optional_args['job_queue'] = dispatcher.job_queue | ||
|
||
return optional_args | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,20 @@ class InlineQueryHandler(Handler): | |
callback (function): A function that takes ``bot, update`` as | ||
positional arguments. It will be called when the ``check_update`` | ||
has determined that an update should be processed by this handler. | ||
pass_update_queue (optional[bool]): If the handler should be passed the | ||
update queue as a keyword argument called ``update_queue``. It can | ||
be used to insert updates. Default is ``False`` | ||
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``update_queue`` will be passed to the callback function. It will be the ``Queue`` | ||
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can | ||
be used to insert updates. Default is ``False``. | ||
pass_job_queue (optional[bool]): If set to ``True``, a keyword argument called | ||
``job_queue`` will be passed to the callback function. It will be a ``JobQueue`` | ||
instance created by the ``Updater`` which can be used to schedule new jobs. | ||
Default is ``False``. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as for |
||
|
||
def __init__(self, callback, pass_update_queue=False): | ||
super(InlineQueryHandler, self).__init__(callback, pass_update_queue) | ||
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False): | ||
super(InlineQueryHandler, self).__init__(callback, | ||
pass_update_queue=pass_update_queue, | ||
pass_job_queue=pass_job_queue) | ||
|
||
def check_update(self, update): | ||
return isinstance(update, Update) and update.inline_query | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
@jh0ker
I find the whole docstring very confusing. Maybe this need rewrite as well?
example:
When set to true, the callback (what callback? the function just called? soemthing else?) will be passed to the job queue as a keyword argument called ``job_queue``. It can be used to schedule new jobs.
I think similar changes for other arguments are in order
Uh oh!
There was an error while loading. Please reload this page.
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.
callback
is the first argument to__init__
, also you added ato
there. It's actually the other way:job_queue
is passed to thecallback
function.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.
@jh0ker
just shows you how much I got confused 😉
another thought:
always pass job_queue and update_queue as keyword args
then no documentation is needed here
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 the wording ;)
Always passing it means that all callback functions have to at least accept
**kwargs
, which they currently don't have to (and I'd like to keep it that way)