Skip to content

Commit 474d5f0

Browse files
committed
update README and examples to new snake_case methods
1 parent 74a2baf commit 474d5f0

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ We want this function to be called on a Telegram message that contains the ``/st
356356
357357
>>> from telegram.ext import CommandHandler
358358
>>> start_handler = CommandHandler('start', start)
359-
>>> dispatcher.addHandler(start_handler)
359+
>>> dispatcher.add_handler(start_handler)
360360
361361
The last step is to tell the ``Updater`` to start working:
362362

@@ -373,7 +373,7 @@ Our bot is now up and running (go ahead and try it)! It's not doing anything yet
373373
...
374374
>>> from telegram.ext import MessageHandler, Filters
375375
>>> echo_handler = MessageHandler([Filters.text], echo)
376-
>>> dispatcher.addHandler(echo_handler)
376+
>>> dispatcher.add_handler(echo_handler)
377377
378378
Our bot should now reply to all text messages that are not a command with a message that has the same content.
379379

@@ -386,7 +386,7 @@ Let's add some functionality to our bot. We want to add the ``/caps`` command, t
386386
... bot.sendMessage(chat_id=update.message.chat_id, text=text_caps)
387387
...
388388
>>> caps_handler = CommandHandler('caps', caps, pass_args=True)
389-
>>> dispatcher.addHandler(caps_handler)
389+
>>> dispatcher.add_handler(caps_handler)
390390
391391
To enable our bot to respond to inline queries, we can add the following (you will also have to talk to BotFather):
392392

@@ -401,7 +401,7 @@ To enable our bot to respond to inline queries, we can add the following (you wi
401401
...
402402
>>> from telegram.ext import InlineQueryHandler
403403
>>> inline_caps_handler = InlineQueryHandler(inline_caps)
404-
>>> dispatcher.addHandler(inline_caps_handler)
404+
>>> dispatcher.add_handler(inline_caps_handler)
405405
406406
People might try to send commands to the bot that it doesn't understand, so we can use a ``RegexHandler`` to recognize all commands that were not recognized by the previous handlers. **Note:** This handler has to be added last, else it will be triggered before the ``CommandHandlers`` had a chance to look at the update:
407407

@@ -412,7 +412,7 @@ People might try to send commands to the bot that it doesn't understand, so we c
412412
...
413413
>>> from telegram.ext import RegexHandler
414414
>>> unknown_handler = RegexHandler(r'/.*', unknown)
415-
>>> dispatcher.addHandler(unknown_handler)
415+
>>> dispatcher.add_handler(unknown_handler)
416416
417417
If you're done playing around, stop the bot with this:
418418

examples/clibot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,24 @@ def main():
112112
dp = updater.dispatcher
113113

114114
# This is how we add handlers for Telegram messages
115-
dp.addHandler(CommandHandler("start", start))
116-
dp.addHandler(CommandHandler("help", help))
115+
dp.add_handler(CommandHandler("start", start))
116+
dp.add_handler(CommandHandler("help", help))
117117
# Message handlers only receive updates that don't contain commands
118-
dp.addHandler(MessageHandler([Filters.text], message))
118+
dp.add_handler(MessageHandler([Filters.text], message))
119119
# Regex handlers will receive all updates on which their regex matches,
120120
# but we have to add it in a separate group, since in one group,
121121
# only one handler will be executed
122-
dp.addHandler(RegexHandler('.*', any_message), group=1)
122+
dp.add_handler(RegexHandler('.*', any_message), group=1)
123123

124124
# String handlers work pretty much the same. Note that we have to tell
125125
# the handler to pass the args or update_queue parameter
126-
dp.addHandler(StringCommandHandler('reply', cli_reply, pass_args=True))
127-
dp.addHandler(StringRegexHandler('[^/].*', cli_noncommand,
128-
pass_update_queue=True))
126+
dp.add_handler(StringCommandHandler('reply', cli_reply, pass_args=True))
127+
dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand,
128+
pass_update_queue=True))
129129

130130
# All TelegramErrors are caught for you and delivered to the error
131131
# handler(s). Other types of Errors are not caught.
132-
dp.addErrorHandler(error)
132+
dp.add_error_handler(error)
133133

134134
# Start the Bot and store the update Queue, so we can insert updates
135135
update_queue = updater.start_polling(timeout=10)

examples/echobot2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def main():
5454
dp = updater.dispatcher
5555

5656
# on different commands - answer in Telegram
57-
dp.addHandler(CommandHandler("start", start))
58-
dp.addHandler(CommandHandler("help", help))
57+
dp.add_handler(CommandHandler("start", start))
58+
dp.add_handler(CommandHandler("help", help))
5959

6060
# on noncommand i.e message - echo the message on Telegram
61-
dp.addHandler(MessageHandler([Filters.text], echo))
61+
dp.add_handler(MessageHandler([Filters.text], echo))
6262

6363
# log all errors
64-
dp.addErrorHandler(error)
64+
dp.add_error_handler(error)
6565

6666
# Start the Bot
6767
updater.start_polling()

examples/inlinebot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ def main():
8787
dp = updater.dispatcher
8888

8989
# on different commands - answer in Telegram
90-
dp.addHandler(CommandHandler("start", start))
91-
dp.addHandler(CommandHandler("help", help))
90+
dp.add_handler(CommandHandler("start", start))
91+
dp.add_handler(CommandHandler("help", help))
9292

9393
# on noncommand i.e message - echo the message on Telegram
94-
dp.addHandler(InlineQueryHandler(inlinequery))
94+
dp.add_handler(InlineQueryHandler(inlinequery))
9595

9696
# log all errors
97-
dp.addErrorHandler(error)
97+
dp.add_error_handler(error)
9898

9999
# Start the Bot
100100
updater.start_polling()

examples/inlinekeyboard_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ def error(bot, update, error):
105105
# The command
106106
updater.dispatcher.addHandler(CommandHandler('set', set_value))
107107
# The answer
108-
updater.dispatcher.addHandler(MessageHandler([Filters.text], entered_value))
108+
updater.dispatcher.add_handler(MessageHandler([Filters.text], entered_value))
109109
# The confirmation
110-
updater.dispatcher.addHandler(CallbackQueryHandler(confirm_value))
111-
updater.dispatcher.addHandler(CommandHandler('start', help))
112-
updater.dispatcher.addHandler(CommandHandler('help', help))
113-
updater.dispatcher.addErrorHandler(error)
110+
updater.dispatcher.add_handler(CallbackQueryHandler(confirm_value))
111+
updater.dispatcher.add_handler(CommandHandler('start', help))
112+
updater.dispatcher.add_handler(CommandHandler('help', help))
113+
updater.dispatcher.add_error_handler(error)
114114

115115
# Start the Bot
116116
updater.start_polling()

examples/state_machine_bot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ def help(bot, update):
9191
updater = Updater("TOKEN")
9292

9393
# The command
94-
updater.dispatcher.addHandler(CommandHandler('set', set_value))
94+
updater.dispatcher.add_handler(CommandHandler('set', set_value))
9595
# The answer and confirmation
96-
updater.dispatcher.addHandler(MessageHandler([Filters.text], set_value))
97-
updater.dispatcher.addHandler(CommandHandler('cancel', cancel))
98-
updater.dispatcher.addHandler(CommandHandler('start', help))
99-
updater.dispatcher.addHandler(CommandHandler('help', help))
96+
updater.dispatcher.add_handler(MessageHandler([Filters.text], set_value))
97+
updater.dispatcher.add_handler(CommandHandler('cancel', cancel))
98+
updater.dispatcher.add_handler(CommandHandler('start', help))
99+
updater.dispatcher.add_handler(CommandHandler('help', help))
100100

101101
# Start the Bot
102102
updater.start_polling()

examples/timerbot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def main():
7373
dp = updater.dispatcher
7474

7575
# on different commands - answer in Telegram
76-
dp.addHandler(CommandHandler("start", start))
77-
dp.addHandler(CommandHandler("help", start))
78-
dp.addHandler(CommandHandler("set", set))
76+
dp.add_handler(CommandHandler("start", start))
77+
dp.add_handler(CommandHandler("help", start))
78+
dp.add_handler(CommandHandler("set", set))
7979

8080
# log all errors
81-
dp.addErrorHandler(error)
81+
dp.add_error_handler(error)
8282

8383
# Start the Bot
8484
updater.start_polling()

0 commit comments

Comments
 (0)