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


Python Filters.entity方法代码示例

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


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

示例1: test_entities_filter

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_entities_filter(self):
        self.message.entities = [self.e(MessageEntity.MENTION)]
        self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = []
        self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = [self.e(MessageEntity.BOLD)]
        self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = [self.e(MessageEntity.BOLD), self.e(MessageEntity.MENTION)]
        self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:14,代码来源:test_filters.py

示例2: test_entities_filter

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_entities_filter(self, message, message_entity):
        message.entities = [message_entity]
        assert Filters.entity(message_entity.type)(message)

        message.entities = []
        assert not Filters.entity(MessageEntity.MENTION)(message)

        second = message_entity.to_dict()
        second['type'] = 'bold'
        second = MessageEntity.de_json(second, None)
        message.entities = [message_entity, second]
        assert Filters.entity(message_entity.type)(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:14,代码来源:test_filters.py

示例3: test_entities_filter

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_entities_filter(self):
        e = functools.partial(MessageEntity, offset=0, length=0)

        self.message.entities = [e(MessageEntity.MENTION)]
        self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = []
        self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = [e(MessageEntity.BOLD)]
        self.assertFalse(Filters.entity(MessageEntity.MENTION)(self.message))

        self.message.entities = [e(MessageEntity.BOLD), e(MessageEntity.MENTION)]
        self.assertTrue(Filters.entity(MessageEntity.MENTION)(self.message))
开发者ID:matibarriento,项目名称:python-telegram-bot,代码行数:16,代码来源:test_filters.py

示例4: test_and_or_filters

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_and_or_filters(self):
        self.message.text = 'test'
        self.message.forward_date = True
        self.assertTrue((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION))
                        )(self.message))
        self.message.forward_date = False
        self.assertFalse((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION)
                                         ))(self.message))
        self.message.entities = [self.e(MessageEntity.MENTION)]
        self.assertTrue((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION))
                        )(self.message))

        self.assertEqual(
            str((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION)))),
            '<Filters.text and <Filters.forwarded or Filters.entity(mention)>>'
        )
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:18,代码来源:test_filters.py

示例5: test_and_filters

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_and_filters(self):
        self.message.text = 'test'
        self.message.forward_date = True
        self.assertTrue((Filters.text & Filters.forwarded)(self.message))
        self.message.text = '/test'
        self.assertFalse((Filters.text & Filters.forwarded)(self.message))
        self.message.text = 'test'
        self.message.forward_date = None
        self.assertFalse((Filters.text & Filters.forwarded)(self.message))

        self.message.text = 'test'
        self.message.forward_date = True
        self.message.entities = [self.e(MessageEntity.MENTION)]
        self.assertTrue((Filters.text & Filters.forwarded & Filters.entity(MessageEntity.MENTION))(
            self.message))
        self.message.entities = [self.e(MessageEntity.BOLD)]
        self.assertFalse((Filters.text & Filters.forwarded & Filters.entity(MessageEntity.MENTION)
                         )(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:20,代码来源:test_filters.py

示例6: test_and_or_filters

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_and_or_filters(self):
        self.message.text = 'test'
        self.message.forward_date = True
        self.assertTrue((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION))
                        )(self.message))
        self.message.forward_date = False
        self.assertFalse((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION)
                                         ))(self.message))
        self.message.entities = [self.e(MessageEntity.MENTION)]
        self.assertTrue((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION))
                        )(self.message))

        self.assertRegexpMatches(
            str((Filters.text & (Filters.forwarded | Filters.entity(MessageEntity.MENTION)))),
            r"<telegram.ext.filters.MergedFilter consisting of <telegram.ext.filters.(Filters.)?_"
            r"Text object at .*?> and <telegram.ext.filters.MergedFilter consisting of "
            r"<telegram.ext.filters.(Filters.)?_Forwarded object at .*?> or "
            r"<telegram.ext.filters.(Filters.)?entity object at .*?>>>")
开发者ID:python-telegram-bot,项目名称:python-telegram-bot,代码行数:20,代码来源:test_filters.py

示例7: test_and_or_filters

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
    def test_and_or_filters(self, message):
        message.text = 'test'
        message.forward_date = True
        assert (Filters.text & (Filters.forwarded | Filters.status_update))(message)
        message.forward_date = False
        assert not (Filters.text & (Filters.forwarded | Filters.status_update))(message)
        message.pinned_message = True
        assert (Filters.text & (Filters.forwarded | Filters.status_update)(message))

        assert str((Filters.text & (Filters.forwarded | Filters.entity(
            MessageEntity.MENTION)))) == '<Filters.text and <Filters.forwarded or ' \
                                         'Filters.entity(mention)>>'
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:14,代码来源:test_filters.py

示例8: add_update_handlers

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import entity [as 别名]
def add_update_handlers(dp):
    browse_handler = ConversationHandler(
        entry_points=[
            CommandHandler('artist', browse.search_artist, pass_args=True, allow_edited=True),
            CommandHandler('song', browse.search_song, pass_args=True, allow_edited=True),
            CommandHandler('album', browse.search_album, pass_args=True, allow_edited=True),
            CommandHandler('search', browse.search_all, pass_args=True, allow_edited=True),
            CommandHandler('new', browse.new),
            CommandHandler('top', browse.top),
            CommandHandler('trending', browse.trending),
            RegexHandler(r'^/(dev)_(\d+)(@.+)?$', browse.derived, pass_groups=True),
            RegexHandler(r'^/(rel)_(\d+)(@.+)?$', browse.related, pass_groups=True),
            RegexHandler(r'^/(albys)_(\d+)(@.+)?$', browse.albums_by_song, pass_groups=True),
            CallbackQueryHandler(browse.artist, pattern=r'^(arlist)\|(.*)\|(.*)$', pass_groups=True)
        ],
        states={
            BrowseState.page: [
                MessageHandler(Filters.text, browse.edited, allow_edited=True, pass_update_queue=True)
            ],
            BrowseState.input: [MessageHandler(Filters.text, browse.search_input, allow_edited=True)],
            BrowseState.input_song: [MessageHandler(Filters.text, browse.search_input_song, allow_edited=True)],
            BrowseState.input_artist: [MessageHandler(Filters.text, browse.search_input_artist, allow_edited=True)],
            BrowseState.input_album: [MessageHandler(Filters.text, browse.search_input_album, allow_edited=True)]
        },
        fallbacks=[CommandHandler('cancel', cancel)],
        allow_reentry=True
    )
    # Was inside BrowseState.page state, but we always want paging buttons to work.. even in semi old messages
    browse_page_handler = CallbackQueryHandler(browse.next_page, pattern=r'^(page)\|(.+)\|(.+)$', pass_groups=True)

    start_handler = CommandHandler('start', text.start, pass_args=True, pass_update_queue=True)
    help_handler = CommandHandler('help', text.send_help)
    inline_handler = CommandHandler('inline', text.inline)
    about_handler = CommandHandler('about', text.about)
    privacy_handler = CommandHandler('privacy', text.privacy)
    kill_handler = CommandHandler('kill', text.kill)
    settings_handler = CommandHandler('settings', settings.start)

    # TODO: Handle edited_message in these too? (would be nice for eg. /artist pinocchio)
    song_handler = RegexHandler(r'^/(?:info|s)_(\d+)(@.+)?$', info.song, pass_groups=True)
    artist_handler = RegexHandler(r'^/(?:ar)_(\d+)(@.+)?$', info.artist, pass_groups=True)
    album_handler = RegexHandler(r'^/(?:al)_(\d+)(@.+)?$', info.album, pass_groups=True)
    song_by_pv_handler = MessageHandler(Filters.entity(MessageEntity.URL), info.song_by_pv)

    lyrics_handler = CallbackQueryHandler(info.lyrics, pattern=r'^(?:ly)\|([^\|]*)\|?([^\|]*)?$', pass_groups=True)
    pv_handler = CallbackQueryHandler(info.pv, pattern=r'^(?:pv)\|([^\|]*)\|?([^\|]*)?$', pass_groups=True)
    album_list_handler = CallbackQueryHandler(info.album_list, pattern=r'^(?:allist)\|(.*)$', pass_groups=True)
    forwarded_handler = MessageHandler(forwarded_filter, info.forwarded, pass_update_queue=True)
    set_handler = CallbackQueryHandler(settings.delegate, pattern='^(?:set)\|([^\|]*)\|?([^\|]*)?$',
                                       pass_groups=True, pass_job_queue=True)

    # Remove the spinning loading icon from buttons
    cancel_callback_query_handler = CallbackQueryHandler(cancel_callback_query)

    song_direct_handler = InlineQueryHandler(inline.song_direct, pattern=r'^!(?:s)#(\d+)$', pass_groups=True)
    song_search_handler = InlineQueryHandler(inline.song_search, pattern=r'^\!(?:s) ?(.*)$', pass_groups=True)
    album_direct_handler = InlineQueryHandler(inline.album_direct, pattern=r'^!(?:al)#(\d+)$', pass_groups=True)
    album_search_handler = InlineQueryHandler(inline.album_search, pattern=r'^\!(?:al) ?(.*)$', pass_groups=True)
    artist_direct_handler = InlineQueryHandler(inline.artist_direct, pattern=r'^!(?:ar?)#(\d+)$', pass_groups=True)
    artist_search_handler = InlineQueryHandler(inline.artist_search, pattern=r'^\!(?:ar?) ?(.*)$', pass_groups=True)
    inline_leftover_handler = InlineQueryHandler(inline.delegate)  # All who didn't match above regex

    cancel_handler = CommandHandler('cancel', text.cancel)
    unknown_command_handler = MessageHandler(Filters.command, text.unknown)

    # Add handlers to dispatcher
    dp.add_handler(forwarded_handler)  # Has to be here otherwise BrowseState.page handler will eat it
    dp.add_handler(song_by_pv_handler)  # Same deal here

    dp.add_handler(browse_handler)
    dp.add_handler(browse_page_handler)

    dp.add_handler(start_handler)
    dp.add_handler(help_handler)
    dp.add_handler(inline_handler)
    dp.add_handler(about_handler)
    dp.add_handler(privacy_handler)
    dp.add_handler(kill_handler)
    dp.add_handler(settings_handler)

    dp.add_handler(song_handler)
    dp.add_handler(artist_handler)
    dp.add_handler(album_handler)

    dp.add_handler(lyrics_handler)
    dp.add_handler(pv_handler)
    dp.add_handler(album_list_handler)
    dp.add_handler(set_handler)

    dp.add_handler(cancel_callback_query_handler)

    dp.add_handler(song_direct_handler)
    dp.add_handler(artist_direct_handler)
    dp.add_handler(album_direct_handler)
    dp.add_handler(song_search_handler)
    dp.add_handler(album_search_handler)  # Has to be before artist since the 'r' in 'ar' is optional there
    dp.add_handler(artist_search_handler)
    dp.add_handler(inline_leftover_handler)

    dp.add_handler(cancel_handler)
#.........这里部分代码省略.........
开发者ID:bomjacob,项目名称:VocaBot,代码行数:103,代码来源:main.py


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