GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Overhaul of Filters (#2759) · MSutt/python-telegram-bot@145d042

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/source
    • conf.py
    • telegram.ext.filters.rst
  • examples
    • conversationbot.py
    • conversationbot2.py
    • deeplinking.py
    • echobot.py
    • nestedconversationbot.py
    • passportbot.py
    • paymentbot.py
    • persistentconversationbot.py
    • pollbot.py
  • telegram
    • ext
      • __init__.py
      • _basepersistence.py
      • _callbackcontext.py
      • _commandhandler.py
      • _messagehandler.py
      • filters.py
    • helpers.py
  • tests
    • conftest.py
    • test_commandhandler.py
    • test_conversationhandler.py
    • test_dispatcher.py
    • test_filters.py
    • test_jobqueue.py
    • test_messagehandler.py
    • test_persistence.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/source/conf.py‎

Copy file name to clipboardExpand all lines: docs/source/conf.py
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# If extensions (or modules to document with autodoc) are in another directory,
2020
# add these directories to sys.path here. If the directory is relative to the
2121
# documentation root, use os.path.abspath to make it absolute, like shown here.
22+
import inspect
2223
from docutils.nodes import Element
2324
from sphinx.application import Sphinx
2425
from sphinx.domains.python import PyXRefRole
@@ -358,7 +359,23 @@ def process_link(self, env: BuildEnvironment, refnode: Element,
358359

359360

360361
def autodoc_skip_member(app, what, name, obj, skip, options):
361-
pass
362+
"""We use this to not document certain members like filter() or check_update() for filters.
363+
See https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#skipping-members"""
364+
365+
included = {'MessageFilter', 'UpdateFilter'} # filter() and check_update() only for these.
366+
included_in_obj = any(inc in repr(obj) for inc in included)
367+
368+
if included_in_obj: # it's difficult to see if check_update is from an inherited-member or not
369+
for frame in inspect.stack(): # From https://github.com/sphinx-doc/sphinx/issues/9533
370+
if frame.function == "filter_members":
371+
docobj = frame.frame.f_locals["self"].object
372+
if not any(inc in str(docobj) for inc in included) and name == 'check_update':
373+
return True
374+
break
375+
376+
if name == 'filter' and obj.__module__ == 'telegram.ext.filters':
377+
if not included_in_obj:
378+
return True # return True to exclude from docs.
362379

363380

364381
def setup(app: Sphinx):
Collapse file

‎docs/source/telegram.ext.filters.rst‎

Copy file name to clipboardExpand all lines: docs/source/telegram.ext.filters.rst
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
telegram.ext.filters Module
44
===========================
55

6+
.. :bysource: since e.g filters.CHAT is much above filters.Chat() in the docs when it shouldn't.
7+
The classes in `filters.py` are sorted alphabetically such that :bysource: still is readable
8+
69
.. automodule:: telegram.ext.filters
10+
:inherited-members:
711
:members:
812
:show-inheritance:
13+
:member-order: bysource
Collapse file

‎examples/conversationbot.py‎

Copy file name to clipboardExpand all lines: examples/conversationbot.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from telegram.ext import (
2121
CommandHandler,
2222
MessageHandler,
23-
Filters,
23+
filters,
2424
ConversationHandler,
2525
Updater,
2626
CallbackContext,
@@ -146,13 +146,13 @@ def main() -> None:
146146
conv_handler = ConversationHandler(
147147
entry_points=[CommandHandler('start', start)],
148148
states={
149-
GENDER: [MessageHandler(Filters.regex('^(Boy|Girl|Other)$'), gender)],
150-
PHOTO: [MessageHandler(Filters.photo, photo), CommandHandler('skip', skip_photo)],
149+
GENDER: [MessageHandler(filters.Regex('^(Boy|Girl|Other)$'), gender)],
150+
PHOTO: [MessageHandler(filters.PHOTO, photo), CommandHandler('skip', skip_photo)],
151151
LOCATION: [
152-
MessageHandler(Filters.location, location),
152+
MessageHandler(filters.LOCATION, location),
153153
CommandHandler('skip', skip_location),
154154
],
155-
BIO: [MessageHandler(Filters.text & ~Filters.command, bio)],
155+
BIO: [MessageHandler(filters.TEXT & ~filters.COMMAND, bio)],
156156
},
157157
fallbacks=[CommandHandler('cancel', cancel)],
158158
)
Collapse file

‎examples/conversationbot2.py‎

Copy file name to clipboardExpand all lines: examples/conversationbot2.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from telegram.ext import (
2222
CommandHandler,
2323
MessageHandler,
24-
Filters,
24+
filters,
2525
ConversationHandler,
2626
Updater,
2727
CallbackContext,
@@ -126,23 +126,23 @@ def main() -> None:
126126
states={
127127
CHOOSING: [
128128
MessageHandler(
129-
Filters.regex('^(Age|Favourite colour|Number of siblings)$'), regular_choice
129+
filters.Regex('^(Age|Favourite colour|Number of siblings)$'), regular_choice
130130
),
131-
MessageHandler(Filters.regex('^Something else...$'), custom_choice),
131+
MessageHandler(filters.Regex('^Something else...$'), custom_choice),
132132
],
133133
TYPING_CHOICE: [
134134
MessageHandler(
135-
Filters.text & ~(Filters.command | Filters.regex('^Done$')), regular_choice
135+
filters.TEXT & ~(filters.COMMAND | filters.Regex('^Done$')), regular_choice
136136
)
137137
],
138138
TYPING_REPLY: [
139139
MessageHandler(
140-
Filters.text & ~(Filters.command | Filters.regex('^Done$')),
140+
filters.TEXT & ~(filters.COMMAND | filters.Regex('^Done$')),
141141
received_information,
142142
)
143143
],
144144
},
145-
fallbacks=[MessageHandler(Filters.regex('^Done$'), done)],
145+
fallbacks=[MessageHandler(filters.Regex('^Done$'), done)],
146146
)
147147

148148
dispatcher.add_handler(conv_handler)
Collapse file

‎examples/deeplinking.py‎

Copy file name to clipboardExpand all lines: examples/deeplinking.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from telegram.ext import (
2626
CommandHandler,
2727
CallbackQueryHandler,
28-
Filters,
28+
filters,
2929
Updater,
3030
CallbackContext,
3131
)
@@ -115,20 +115,20 @@ def main() -> None:
115115

116116
# Register a deep-linking handler
117117
dispatcher.add_handler(
118-
CommandHandler("start", deep_linked_level_1, Filters.regex(CHECK_THIS_OUT))
118+
CommandHandler("start", deep_linked_level_1, filters.Regex(CHECK_THIS_OUT))
119119
)
120120

121121
# This one works with a textual link instead of an URL
122-
dispatcher.add_handler(CommandHandler("start", deep_linked_level_2, Filters.regex(SO_COOL)))
122+
dispatcher.add_handler(CommandHandler("start", deep_linked_level_2, filters.Regex(SO_COOL)))
123123

124124
# We can also pass on the deep-linking payload
125125
dispatcher.add_handler(
126-
CommandHandler("start", deep_linked_level_3, Filters.regex(USING_ENTITIES))
126+
CommandHandler("start", deep_linked_level_3, filters.Regex(USING_ENTITIES))
127127
)
128128

129129
# Possible with inline keyboard buttons as well
130130
dispatcher.add_handler(
131-
CommandHandler("start", deep_linked_level_4, Filters.regex(USING_KEYBOARD))
131+
CommandHandler("start", deep_linked_level_4, filters.Regex(USING_KEYBOARD))
132132
)
133133

134134
# register callback handler for inline keyboard button
Collapse file

‎examples/echobot.py‎

Copy file name to clipboardExpand all lines: examples/echobot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from telegram.ext import (
2222
CommandHandler,
2323
MessageHandler,
24-
Filters,
24+
filters,
2525
Updater,
2626
CallbackContext,
2727
)
@@ -68,7 +68,7 @@ def main() -> None:
6868
dispatcher.add_handler(CommandHandler("help", help_command))
6969

7070
# on non command i.e message - echo the message on Telegram
71-
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))
71+
dispatcher.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
7272

7373
# Start the Bot
7474
updater.start_polling()
Collapse file

‎examples/nestedconversationbot.py‎

Copy file name to clipboardExpand all lines: examples/nestedconversationbot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from telegram.ext import (
2222
CommandHandler,
2323
MessageHandler,
24-
Filters,
24+
filters,
2525
ConversationHandler,
2626
CallbackQueryHandler,
2727
Updater,
@@ -319,7 +319,7 @@ def main() -> None:
319319
SELECTING_FEATURE: [
320320
CallbackQueryHandler(ask_for_input, pattern='^(?!' + str(END) + ').*$')
321321
],
322-
TYPING: [MessageHandler(Filters.text & ~Filters.command, save_input)],
322+
TYPING: [MessageHandler(filters.TEXT & ~filters.COMMAND, save_input)],
323323
},
324324
fallbacks=[
325325
CallbackQueryHandler(end_describing, pattern='^' + str(END) + '$'),
Collapse file

‎examples/passportbot.py‎

Copy file name to clipboardExpand all lines: examples/passportbot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515

1616
from telegram import Update
17-
from telegram.ext import MessageHandler, Filters, Updater, CallbackContext
17+
from telegram.ext import MessageHandler, filters, Updater, CallbackContext
1818

1919
# Enable logging
2020

@@ -110,7 +110,7 @@ def main() -> None:
110110
dispatcher = updater.dispatcher
111111

112112
# On messages that include passport data call msg
113-
dispatcher.add_handler(MessageHandler(Filters.passport_data, msg))
113+
dispatcher.add_handler(MessageHandler(filters.PASSPORT_DATA, msg))
114114

115115
# Start the Bot
116116
updater.start_polling()
Collapse file

‎examples/paymentbot.py‎

Copy file name to clipboardExpand all lines: examples/paymentbot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from telegram.ext import (
1111
CommandHandler,
1212
MessageHandler,
13-
Filters,
13+
filters,
1414
PreCheckoutQueryHandler,
1515
ShippingQueryHandler,
1616
Updater,
@@ -149,7 +149,7 @@ def main() -> None:
149149
dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback))
150150

151151
# Success! Notify your user!
152-
dispatcher.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback))
152+
dispatcher.add_handler(MessageHandler(filters.SUCCESSFUL_PAYMENT, successful_payment_callback))
153153

154154
# Start the Bot
155155
updater.start_polling()
Collapse file

‎examples/persistentconversationbot.py‎

Copy file name to clipboardExpand all lines: examples/persistentconversationbot.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from telegram.ext import (
2222
CommandHandler,
2323
MessageHandler,
24-
Filters,
24+
filters,
2525
ConversationHandler,
2626
PicklePersistence,
2727
Updater,
@@ -144,23 +144,23 @@ def main() -> None:
144144
states={
145145
CHOOSING: [
146146
MessageHandler(
147-
Filters.regex('^(Age|Favourite colour|Number of siblings)$'), regular_choice
147+
filters.Regex('^(Age|Favourite colour|Number of siblings)$'), regular_choice
148148
),
149-
MessageHandler(Filters.regex('^Something else...$'), custom_choice),
149+
MessageHandler(filters.Regex('^Something else...$'), custom_choice),
150150
],
151151
TYPING_CHOICE: [
152152
MessageHandler(
153-
Filters.text & ~(Filters.command | Filters.regex('^Done$')), regular_choice
153+
filters.TEXT & ~(filters.COMMAND | filters.Regex('^Done$')), regular_choice
154154
)
155155
],
156156
TYPING_REPLY: [
157157
MessageHandler(
158-
Filters.text & ~(Filters.command | Filters.regex('^Done$')),
158+
filters.TEXT & ~(filters.COMMAND | filters.Regex('^Done$')),
159159
received_information,
160160
)
161161
],
162162
},
163-
fallbacks=[MessageHandler(Filters.regex('^Done$'), done)],
163+
fallbacks=[MessageHandler(filters.Regex('^Done$'), done)],
164164
name="my_conversation",
165165
persistent=True,
166166
)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.