update README and examples to new snake_case methods

This commit is contained in:
Rahiel Kasim 2016-04-28 17:29:34 +02:00
parent 74a2baf03d
commit 474d5f0c9f
7 changed files with 35 additions and 35 deletions

View file

@ -356,7 +356,7 @@ We want this function to be called on a Telegram message that contains the ``/st
>>> from telegram.ext import CommandHandler
>>> start_handler = CommandHandler('start', start)
>>> dispatcher.addHandler(start_handler)
>>> dispatcher.add_handler(start_handler)
The last step is to tell the ``Updater`` to start working:
@ -373,7 +373,7 @@ Our bot is now up and running (go ahead and try it)! It's not doing anything yet
...
>>> from telegram.ext import MessageHandler, Filters
>>> echo_handler = MessageHandler([Filters.text], echo)
>>> dispatcher.addHandler(echo_handler)
>>> dispatcher.add_handler(echo_handler)
Our bot should now reply to all text messages that are not a command with a message that has the same content.
@ -386,7 +386,7 @@ Let's add some functionality to our bot. We want to add the ``/caps`` command, t
... bot.sendMessage(chat_id=update.message.chat_id, text=text_caps)
...
>>> caps_handler = CommandHandler('caps', caps, pass_args=True)
>>> dispatcher.addHandler(caps_handler)
>>> dispatcher.add_handler(caps_handler)
To enable our bot to respond to inline queries, we can add the following (you will also have to talk to BotFather):
@ -401,7 +401,7 @@ To enable our bot to respond to inline queries, we can add the following (you wi
...
>>> from telegram.ext import InlineQueryHandler
>>> inline_caps_handler = InlineQueryHandler(inline_caps)
>>> dispatcher.addHandler(inline_caps_handler)
>>> dispatcher.add_handler(inline_caps_handler)
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:
@ -412,7 +412,7 @@ People might try to send commands to the bot that it doesn't understand, so we c
...
>>> from telegram.ext import RegexHandler
>>> unknown_handler = RegexHandler(r'/.*', unknown)
>>> dispatcher.addHandler(unknown_handler)
>>> dispatcher.add_handler(unknown_handler)
If you're done playing around, stop the bot with this:

View file

@ -112,24 +112,24 @@ def main():
dp = updater.dispatcher
# This is how we add handlers for Telegram messages
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
# Message handlers only receive updates that don't contain commands
dp.addHandler(MessageHandler([Filters.text], message))
dp.add_handler(MessageHandler([Filters.text], message))
# Regex handlers will receive all updates on which their regex matches,
# but we have to add it in a separate group, since in one group,
# only one handler will be executed
dp.addHandler(RegexHandler('.*', any_message), group=1)
dp.add_handler(RegexHandler('.*', any_message), group=1)
# String handlers work pretty much the same. Note that we have to tell
# the handler to pass the args or update_queue parameter
dp.addHandler(StringCommandHandler('reply', cli_reply, pass_args=True))
dp.addHandler(StringRegexHandler('[^/].*', cli_noncommand,
dp.add_handler(StringCommandHandler('reply', cli_reply, pass_args=True))
dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand,
pass_update_queue=True))
# All TelegramErrors are caught for you and delivered to the error
# handler(s). Other types of Errors are not caught.
dp.addErrorHandler(error)
dp.add_error_handler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(timeout=10)

View file

@ -54,14 +54,14 @@ def main():
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.addHandler(MessageHandler([Filters.text], echo))
dp.add_handler(MessageHandler([Filters.text], echo))
# log all errors
dp.addErrorHandler(error)
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()

View file

@ -87,14 +87,14 @@ def main():
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.addHandler(InlineQueryHandler(inlinequery))
dp.add_handler(InlineQueryHandler(inlinequery))
# log all errors
dp.addErrorHandler(error)
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()

View file

@ -105,12 +105,12 @@ updater = Updater("TOKEN")
# The command
updater.dispatcher.addHandler(CommandHandler('set', set_value))
# The answer
updater.dispatcher.addHandler(MessageHandler([Filters.text], entered_value))
updater.dispatcher.add_handler(MessageHandler([Filters.text], entered_value))
# The confirmation
updater.dispatcher.addHandler(CallbackQueryHandler(confirm_value))
updater.dispatcher.addHandler(CommandHandler('start', help))
updater.dispatcher.addHandler(CommandHandler('help', help))
updater.dispatcher.addErrorHandler(error)
updater.dispatcher.add_handler(CallbackQueryHandler(confirm_value))
updater.dispatcher.add_handler(CommandHandler('start', help))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.dispatcher.add_error_handler(error)
# Start the Bot
updater.start_polling()

View file

@ -91,12 +91,12 @@ def help(bot, update):
updater = Updater("TOKEN")
# The command
updater.dispatcher.addHandler(CommandHandler('set', set_value))
updater.dispatcher.add_handler(CommandHandler('set', set_value))
# The answer and confirmation
updater.dispatcher.addHandler(MessageHandler([Filters.text], set_value))
updater.dispatcher.addHandler(CommandHandler('cancel', cancel))
updater.dispatcher.addHandler(CommandHandler('start', help))
updater.dispatcher.addHandler(CommandHandler('help', help))
updater.dispatcher.add_handler(MessageHandler([Filters.text], set_value))
updater.dispatcher.add_handler(CommandHandler('cancel', cancel))
updater.dispatcher.add_handler(CommandHandler('start', help))
updater.dispatcher.add_handler(CommandHandler('help', help))
# Start the Bot
updater.start_polling()

View file

@ -73,12 +73,12 @@ def main():
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", start))
dp.addHandler(CommandHandler("set", set))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", start))
dp.add_handler(CommandHandler("set", set))
# log all errors
dp.addErrorHandler(error)
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()