当前位置: 首页>>代码示例>>Python>>正文


Python Filters.regex方法代码示例

本文整理汇总了Python中telegram.ext.Filters.regex方法的典型用法代码示例。如果您正苦于以下问题:Python Filters.regex方法的具体用法?Python Filters.regex怎么用?Python Filters.regex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telegram.ext.Filters的用法示例。


在下文中一共展示了Filters.regex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import regex [as 别名]
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'], use_context=True)
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    rate_limit_tracker_handler = MessageHandler(~Filters.command, rate_limit_tracker)

    start_handler = CommandHandler('start', start)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = MessageHandler(Filters.regex(r'.*#rules.*'), rules)
    docs_handler = CommandHandler('docs', docs)
    wiki_handler = CommandHandler('wiki', wiki)
    sandwich_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?'),
                                      sandwich)
    off_on_topic_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b'),
                                          off_on_topic)

    # We need several matches so Filters.regex is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors...
    github_handler = MessageHandler(Filters.text, github)
    forward_faq_handler = MessageHandler(Filters.regex(r'(?i).*#faq.*'), forward_faq)

    dispatcher.add_handler(rate_limit_tracker_handler, group=-1)

    # Note: Order matters!
    taghints.register(dispatcher)
    dispatcher.add_handler(forward_faq_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(wiki_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher)
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logger.info('Listening...')

    try:
        github_issues.set_auth(config['KEYS']['github_client_id'], config['KEYS']['github_client_secret'])
    except KeyError:
        logging.info('No github auth set. Rate-limit is 60 requests/hour without auth.')

    github_issues.init_issues(dispatcher.job_queue)

    updater.idle()
开发者ID:bvanrijn,项目名称:rules-bot,代码行数:59,代码来源:rules_bot.py

示例2: test_filters_regex

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import regex [as 别名]
    def test_filters_regex(self, message):
        message.text = '/start deep-linked param'
        assert Filters.regex(r'deep-linked param')(message)
        message.text = '/help'
        assert Filters.regex(r'help')(message)
        message.text = '/help'
        assert Filters.regex('help')(message)

        message.text = 'test'
        assert not Filters.regex(r'fail')(message)
        assert Filters.regex(r'test')(message)
        assert Filters.regex(re.compile(r'test'))(message)

        message.text = 'i love python'
        assert Filters.regex(r'.\b[lo]{2}ve python')(message)
开发者ID:technoekat,项目名称:prodeda1,代码行数:17,代码来源:test_filters.py

示例3: register

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import regex [as 别名]
def register(dispatcher):
    dispatcher.add_handler(MessageHandler(Filters.regex(rf'{"|".join(HINTS.keys())}.*'), hint_handler))
    dispatcher.add_handler(CommandHandler(('hints', 'listhints'), list_available_hints))
开发者ID:bvanrijn,项目名称:rules-bot,代码行数:5,代码来源:taghints.py

示例4: top_scorers

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import regex [as 别名]
        scorers = top_scorers(chat_id[0])
        voters = top_voters(chat_id[0])
        try:
            updater.bot.send_message(
                chat_id[0],
                '<b>DAILY SUMMARY</b>\n{}\n{}'.format(scorers, voters),
                parse_mode='HTML'
            )
        except Exception as e:
            print(e)


updater = Updater('')

updater.dispatcher.add_handler(
    MessageHandler(Filters.regex(':D$') & Filters.reply, add_point)
)
updater.dispatcher.add_handler(
    MessageHandler(Filters.regex('^[:]+[D]+$'), add_point)
)
updater.dispatcher.add_handler(MessageHandler(
    Filters.private & Filters.command & Filters.regex('rank$'),
    cmd_private_rank
))
# updater.dispatcher.add_handler(CommandHandler('top', cmd_top_scorers))
# updater.dispatcher.add_handler(CommandHandler('voters', cmd_top_voters))
# updater.dispatcher.add_handler(CommandHandler('rank', cmd_user_rank))
updater.dispatcher.add_handler(MessageHandler(Filters.all, save_last_message))

updater.start_polling()
# updater.idle()
开发者ID:EinariTuukkanen,项目名称:telegram-bots,代码行数:33,代码来源:bot.py


注:本文中的telegram.ext.Filters.regex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。