本文整理汇总了Python中telegram.ext.RegexHandler方法的典型用法代码示例。如果您正苦于以下问题:Python ext.RegexHandler方法的具体用法?Python ext.RegexHandler怎么用?Python ext.RegexHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext
的用法示例。
在下文中一共展示了ext.RegexHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_handlers
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import RegexHandler [as 别名]
def register_handlers(dispatcher, mode):
assert mode in ('production', 'test')
dispatcher.add_handler(MessageHandler(
Filters.status_update.new_chat_members, handle_new_chat_members
))
dispatcher.add_handler(CommandHandler(
['start', 'help'], handle_start_help
))
dispatcher.add_handler(CommandHandler('stat', handle_stat))
dispatcher.add_handler(CommandHandler(
['daysandbox_set', 'daysandbox_get'], handle_set_get
))
dispatcher.add_handler(RegexHandler(
r'^/setlogformat ', handle_setlogformat, channel_post_updates=True
))
dispatcher.add_handler(CommandHandler('setlog', handle_setlog))
dispatcher.add_handler(CommandHandler('unsetlog', handle_unsetlog))
dispatcher.add_handler(MessageHandler(
Filters.all, partial(handle_any_message, mode), edited_updates=True
))
示例2: _add_link_handler
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import RegexHandler [as 别名]
def _add_link_handler(self):
self.dispatcher.add_handler(RegexHandler(
utl.comp("^/_([a-zA-Z0-9]*)__([\w]*)$"), self._cmd_link_callback))
示例3: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import RegexHandler [as 别名]
def main():
"""
Main function.
This function handles the conversation flow by setting
states on each step of the flow. Each state has its own
handler for the interaction with the user.
"""
global LANG
# Create the EventHandler and pass it your bot's token.
updater = Updater(telegram_token)
# Get the dispatcher to register handlers:
dp = updater.dispatcher
# Add conversation handler with predefined states:
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
SET_LANG: [RegexHandler('^(ES|EN)$', set_lang)],
MENU: [CommandHandler('menu', menu)],
SET_STAT: [RegexHandler(
'^({}|{}|{}|{})$'.format(
send_report['ES'], view_map['ES'],
view_faq['ES'], view_about['ES']),
set_state),
RegexHandler(
'^({}|{}|{}|{})$'.format(
send_report['EN'], view_map['EN'],
view_faq['EN'], view_about['EN']),
set_state)],
LOCATION: [MessageHandler(Filters.location, location),
CommandHandler('menu', menu)]
},
fallbacks=[CommandHandler('cancel', cancel),
CommandHandler('help', help)]
)
dp.add_handler(conv_handler)
# Log all errors:
dp.add_error_handler(error)
# Start DisAtBot:
updater.start_polling()
# Run the bot until the user presses Ctrl-C or the process
# receives SIGINT, SIGTERM or SIGABRT:
updater.idle()