X Tutup
Skip to content

Commit 0d0ad13

Browse files
committed
add documentation and minor stuff
1 parent 95fde0c commit 0d0ad13

11 files changed

+184
-5
lines changed

telegram/ext/callbackqueryhandler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525

2626

2727
class CallbackQueryHandler(Handler):
28+
"""
29+
Handler class to handle Telegram callback queries.
30+
31+
Args:
32+
callback (function): A function that takes ``bot, update`` as
33+
positional arguments. It will be called when the ``checkUpdate``
34+
has determined that an update should be processed by this handler.
35+
pass_update_queue (optional[bool]): If the handler should be passed the
36+
update queue as a keyword argument called ``update_queue``. It can
37+
be used to insert updates. Default is ``False``
38+
"""
2839

2940
def __init__(self, callback, pass_update_queue=False):
3041
super(Handler).__init__(callback, pass_update_queue)

telegram/ext/choseninlineresulthandler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525

2626

2727
class ChosenInlineResultHandler(Handler):
28+
"""
29+
Handler class to handle Telegram updates that contain a chosen inline
30+
result.
31+
32+
Args:
33+
callback (function): A function that takes ``bot, update`` as
34+
positional arguments. It will be called when the ``checkUpdate``
35+
has determined that an update should be processed by this handler.
36+
pass_update_queue (optional[bool]): If the handler should be passed the
37+
update queue as a keyword argument called ``update_queue``. It can
38+
be used to insert updates. Default is ``False``
39+
"""
2840

2941
def __init__(self, callback, pass_update_queue=False):
3042
super(Handler).__init__(callback, pass_update_queue)

telegram/ext/commandhandler.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,31 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919

20-
""" This module contains the base class for handlers as used by the
21-
Dispatcher """
20+
""" This module contains the CommandHandler class """
2221

2322
from .handler import Handler
2423
from telegram import Update
2524

2625

2726
class CommandHandler(Handler):
27+
"""
28+
Handler class to handle Telegram commands. Commands are Telegram messages
29+
that start with ``/``, optionally followed by an @ and the bot's
30+
name and/or some additional text.
31+
32+
Args:
33+
command (str): The name of the command this handler should listen for.
34+
callback (function): A function that takes ``bot, update`` as
35+
positional arguments. It will be called when the ``checkUpdate``
36+
has determined that an update should be processed by this handler.
37+
pass_args (optional[bool]): If the handler should be passed the
38+
arguments passed to the command as a keyword argument called `
39+
`args``. It will contain a list of strings, which is the text
40+
following the command split on spaces. Default is ``False``
41+
pass_update_queue (optional[bool]): If the handler should be passed the
42+
update queue as a keyword argument called ``update_queue``. It can
43+
be used to insert updates. Default is ``False``
44+
"""
2845

2946
def __init__(self, command, callback, pass_args=False,
3047
pass_update_queue=False):

telegram/ext/filters.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
#!/usr/bin/env python
2+
#
3+
# A library that provides a Python interface to the Telegram Bot API
4+
# Copyright (C) 2015-2016
5+
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser Public License
18+
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
20+
""" This module contains the filters used by the MessageHandler class """
21+
122
TEXT, AUDIO, DOCUMENT, PHOTO, STICKER, VIDEO, VOICE, CONTACT, LOCATION, \
223
VENUE, STATUS_UPDATE = range(11)

telegram/ext/handler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222

2323

2424
class Handler(object):
25+
"""
26+
The base class for all update handlers. You can create your own handlers
27+
by inheriting from this class.
28+
29+
Args:
30+
callback (function): A function that takes ``bot, update`` as
31+
positional arguments. It will be called when the ``checkUpdate``
32+
has determined that an update should be processed by this handler.
33+
pass_update_queue (optional[bool]): If the callback should be passed
34+
the update queue as a keyword argument called ``update_queue``. It
35+
can be used to insert updates. Default is ``False``
36+
"""
2537

2638
def __init__(self, callback, pass_update_queue=False):
2739
self.callback = callback

telegram/ext/inlinequeryhandler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525

2626

2727
class InlineQueryHandler(Handler):
28+
"""
29+
Handler class to handle Telegram inline queries.
30+
31+
Args:
32+
callback (function): A function that takes ``bot, update`` as
33+
positional arguments. It will be called when the ``checkUpdate``
34+
has determined that an update should be processed by this handler.
35+
pass_update_queue (optional[bool]): If the handler should be passed the
36+
update queue as a keyword argument called ``update_queue``. It can
37+
be used to insert updates. Default is ``False``
38+
"""
2839

2940
def __init__(self, callback, pass_update_queue=False):
3041
super(Handler).__init__(callback, pass_update_queue)

telegram/ext/messagehandler.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727

2828

2929
class MessageHandler(Handler):
30+
"""
31+
Handler class to handle telegram messages. Messages are Telegram Updates
32+
that do not contain a command. They might contain text, media or status
33+
updates.
34+
35+
Args:
36+
filters (list): A list of filters defined in ``telegram.ext.filters``.
37+
All messages that match at least one of those filters will be
38+
accepted. If ``bool(filters)`` evaluates to ``False``, messages are
39+
not filtered.
40+
callback (function): A function that takes ``bot, update`` as
41+
positional arguments. It will be called when the ``checkUpdate``
42+
has determined that an update should be processed by this handler.
43+
pass_update_queue (optional[bool]): If the handler should be passed the
44+
update queue as a keyword argument called ``update_queue``. It can
45+
be used to insert updates. Default is ``False``
46+
"""
3047

3148
def __init__(self, filters, callback, pass_update_queue=False):
3249
super(Handler).__init__(callback, pass_update_queue)

telegram/ext/regexhandler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727

2828

2929
class RegexHandler(Handler):
30+
"""
31+
Handler class to handle Telegram updates based on a regex. It uses a
32+
regular expression to check text messages. Read the documentation of the
33+
``re`` module for more information. The ``re.match`` function is used to
34+
determine if an update should be handled by this handler.
35+
36+
Args:
37+
pattern (str or Pattern): The regex pattern.
38+
callback (function): A function that takes ``bot, update`` as
39+
positional arguments. It will be called when the ``checkUpdate``
40+
has determined that an update should be processed by this handler.
41+
pass_groups (optional[bool]): If the callback should be passed the
42+
result of ``re.match(pattern, text).groups()`` as a keyword
43+
argument called ``groups``. Default is ``False``
44+
pass_groupdict (optional[bool]): If the callback should be passed the
45+
result of ``re.match(pattern, text).groupdict()`` as a keyword
46+
argument called ``groupdict``. Default is ``False``
47+
pass_update_queue (optional[bool]): If the handler should be passed the
48+
update queue as a keyword argument called ``update_queue``. It can
49+
be used to insert updates. Default is ``False``
50+
"""
3051

3152
def __init__(self, pattern, callback, pass_groups=False,
3253
pass_groupdict=False, pass_update_queue=False):

telegram/ext/stringcommandhandler.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424

2525

2626
class StringCommandHandler(Handler):
27+
"""
28+
Handler class to handle string commands. Commands are string updates
29+
that start with ``/``.
30+
31+
Args:
32+
command (str): The name of the command this handler should listen for.
33+
callback (function): A function that takes ``bot, update`` as
34+
positional arguments. It will be called when the ``checkUpdate``
35+
has determined that an update should be processed by this handler.
36+
pass_args (optional[bool]): If the handler should be passed the
37+
arguments passed to the command as a keyword argument called `
38+
`args``. It will contain a list of strings, which is the text
39+
following the command split on spaces. Default is ``False``
40+
pass_update_queue (optional[bool]): If the handler should be passed the
41+
update queue as a keyword argument called ``update_queue``. It can
42+
be used to insert updates. Default is ``False``
43+
"""
2744

2845
def __init__(self, command, callback, pass_args=False,
2946
pass_update_queue=False):

telegram/ext/stringregexhandler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@
2626

2727

2828
class RegexHandler(Handler):
29+
"""
30+
Handler class to handle string updates based on a regex. It uses a
31+
regular expression to check update content. Read the documentation of the
32+
``re`` module for more information. The ``re.match`` function is used to
33+
determine if an update should be handled by this handler.
34+
35+
Args:
36+
pattern (str or Pattern): The regex pattern.
37+
callback (function): A function that takes ``bot, update`` as
38+
positional arguments. It will be called when the ``checkUpdate``
39+
has determined that an update should be processed by this handler.
40+
pass_groups (optional[bool]): If the callback should be passed the
41+
result of ``re.match(pattern, update).groups()`` as a keyword
42+
argument called ``groups``. Default is ``False``
43+
pass_groupdict (optional[bool]): If the callback should be passed the
44+
result of ``re.match(pattern, update).groupdict()`` as a keyword
45+
argument called ``groupdict``. Default is ``False``
46+
pass_update_queue (optional[bool]): If the handler should be passed the
47+
update queue as a keyword argument called ``update_queue``. It can
48+
be used to insert updates. Default is ``False``
49+
"""
2950

3051
def __init__(self, pattern, callback, pass_groups=False,
3152
pass_groupdict=False, pass_update_queue=False):

0 commit comments

Comments
 (0)
X Tutup