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


Python Filters.user方法代码示例

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


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

示例1: test_filters_user_id

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_user_id(self):
     self.assertFalse(Filters.user(user_id=1)(self.message))
     self.message.from_user.id = 1
     self.assertTrue(Filters.user(user_id=1)(self.message))
     self.message.from_user.id = 2
     self.assertTrue(Filters.user(user_id=[1, 2])(self.message))
     self.assertFalse(Filters.user(user_id=1)(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:9,代码来源:test_filters.py

示例2: test_filters_user_id

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_user_id(self, message):
     assert not Filters.user(user_id=1)(message)
     message.from_user.id = 1
     assert Filters.user(user_id=1)(message)
     message.from_user.id = 2
     assert Filters.user(user_id=[1, 2])(message)
     assert not Filters.user(user_id=[3, 4])(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:9,代码来源:test_filters.py

示例3: test_filters_username

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_username(self, message):
     assert not Filters.user(username='user')(message)
     assert not Filters.user(username='Testuser')(message)
     message.from_user.username = 'user'
     assert Filters.user(username='@user')(message)
     assert Filters.user(username='user')(message)
     assert Filters.user(username=['user1', 'user', 'user2'])(message)
     assert not Filters.user(username=['@username', '@user_2'])(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:10,代码来源:test_filters.py

示例4: test_filters_username

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_username(self):
     self.assertFalse(Filters.user(username='user')(self.message))
     self.assertFalse(Filters.user(username='Testuser')(self.message))
     self.message.from_user.username = 'user'
     self.assertTrue(Filters.user(username='@user')(self.message))
     self.assertTrue(Filters.user(username='user')(self.message))
     self.assertTrue(Filters.user(username=['user1', 'user', 'user2'])(self.message))
     self.assertFalse(Filters.user(username=['@username', '@user_2'])(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:10,代码来源:test_filters.py

示例5: __init__

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
    def __init__(self, token, allowed_users=None):
        """
        :param token: str - Telegram's bot token
        :param allowed_users: str - comma-joined list of users allowed to add new torrents.
        """
        if not telegram:
            LOGGER.error('You have not installed python-telegram-bot library.')
            return

        self.token = token
        self.allowed_users = allowed_users or ''
        self.handler_kwargs = {}
        self.updater = Updater(token=self.token)
        self.dispatcher = self.updater.dispatcher
        if self.allowed_users:
            self.handler_kwargs = {'filters': Filters.user(username=self.allowed_users.split(','))}
开发者ID:idlesign,项目名称:torrt,代码行数:18,代码来源:telegram_bot.py

示例6: test_filters_user

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_user(self):
     with pytest.raises(ValueError, match='user_id or username'):
         Filters.user(user_id=1, username='user')
     with pytest.raises(ValueError, match='user_id or username'):
         Filters.user()
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py

示例7: test_filters_user

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
 def test_filters_user(self):
     with self.assertRaisesRegexp(ValueError, 'user_id or username'):
         Filters.user(user_id=1, username='user')
     with self.assertRaisesRegexp(ValueError, 'user_id or username'):
         Filters.user()
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py

示例8: main

# 需要导入模块: from telegram.ext import Filters [as 别名]
# 或者: from telegram.ext.Filters import user [as 别名]
def main():
    updater = Updater(token=config_holder.config["BOT_TOKEN"])
    global dispatcher
    dispatcher = updater.dispatcher
    pass
    dispatcher_handlers = [
        CommandHandler('start', start),

        CommandHandler('book', book),

        CommandHandler('clear', clear_info),

        CommandHandler('unbook', unbook),

        CommandHandler(filters=Filters.user(user_id=config_holder.adm), command='stats', callback=stats),

        MessageHandler(Filters.text & filters.StanceResolveFilter(stance=consts.MONTH_PICKED, check_info=False),
                       callback=day_to_time_pick),

        MessageHandler(Filters.text & filters.StanceResolveFilter(stance=consts.PHONE_PICKED, check_info=True),
                       callback=external_name_to_commit_pick),

        MessageHandler(Filters.text & filters.StanceResolveFilter(stance=consts.END_TIME_PICKED, check_info=True),
                       callback=phone_to_external_name_pick),

        MessageHandler(Filters.text, echo),

        MessageHandler(filters=Filters.contact & Filters.user(user_id=config_holder.adm), callback=change_role),

        FilteredCallbackQueryHandler(filters=filters.StanceResolveFilterCallback(callback_stance=consts.MONTH_PICKED,
                                                                                 user_stance=consts.NOTHING_PICKED),
                                     callback=month_to_day_pick),

        FilteredCallbackQueryHandler(
            filters=filters.StanceResolveFilterCallback(callback_stance=consts.START_TIME_PICKED,
                                                        user_stance=consts.DAY_PICKED),
            callback=start_to_end_time_pick),

        FilteredCallbackQueryHandler(filters=filters.StanceResolveFilterCallback(callback_stance=consts.END_TIME_PICKED,
                                                                                 user_stance=consts.START_TIME_PICKED),
                                     callback=end_time_to_commit_pick),

        FilteredCallbackQueryHandler(filters=filters.filter_committed, callback=commit_pick),

        FilteredCallbackQueryHandler(filters=filters.CallbackOnlyFilter(callback_stance=consts.RANGE_REMOVE),
                                     callback=remove_range),

        FilteredCallbackQueryHandler(filters=(filters.CallbackOnlyFilter(callback_stance=consts.NEXT_DATE) |
                                             filters.CallbackOnlyFilter(callback_stance=consts.PREVIOUS_DATE)) &
                                             Filters.user(user_id=config_holder.adm),
                                     callback=update_stats),

        CallbackQueryHandler(callback=unresolved_pick)
    ]

    for x in dispatcher_handlers:
        dispatcher.add_handler(x)

    def error_callback(bot, update, error):
        try:
            raise error
        except BadRequest as e:
            pass
        except Unauthorized as e:
            logging.error("Can not send message")
        except NetworkError as e:
            time.sleep(2)
            dispatcher.process_update(update)
        except TelegramError as e:
            logging.error("Unknown error occurred", e.__traceback__)

    dispatcher.add_error_handler(error_callback)

    updater.start_polling(read_latency=10, bootstrap_retries=5)
开发者ID:rundoom,项目名称:BookingBot,代码行数:76,代码来源:bookingbot.py


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