本文整理汇总了Python中telegram.ext.Filters类的典型用法代码示例。如果您正苦于以下问题:Python Filters类的具体用法?Python Filters怎么用?Python Filters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filters类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_filters_user_id
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,代码行数:7,代码来源:test_filters.py
示例2: test_filters_chat_id
def test_filters_chat_id(self):
self.assertFalse(Filters.chat(chat_id=-1)(self.message))
self.message.chat.id = -1
self.assertTrue(Filters.chat(chat_id=-1)(self.message))
self.message.chat.id = -2
self.assertTrue(Filters.chat(chat_id=[-1, -2])(self.message))
self.assertFalse(Filters.chat(chat_id=-1)(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例3: test_filters_chat_username
def test_filters_chat_username(self):
self.assertFalse(Filters.chat(username='chat')(self.message))
self.message.chat.username = 'chat'
self.assertTrue(Filters.chat(username='@chat')(self.message))
self.assertTrue(Filters.chat(username='chat')(self.message))
self.assertTrue(Filters.chat(username=['chat1', 'chat', 'chat2'])(self.message))
self.assertFalse(Filters.chat(username=['@chat1', 'chat_2'])(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例4: test_filters_chat_username
def test_filters_chat_username(self, message):
assert not Filters.chat(username='chat')(message)
message.chat.username = 'chat'
assert Filters.chat(username='@chat')(message)
assert Filters.chat(username='chat')(message)
assert Filters.chat(username=['chat1', 'chat', 'chat2'])(message)
assert not Filters.chat(username=['@chat1', 'chat_2'])(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例5: test_inverted_filters
def test_inverted_filters(self, message):
message.text = '/test'
assert Filters.command(message)
assert not (~Filters.command)(message)
message.text = 'test'
assert not Filters.command(message)
assert (~Filters.command)(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例6: test_filters_reply
def test_filters_reply(self, message):
another_message = Message(1, User(1, 'TestOther', False), datetime.datetime.now(),
Chat(0, 'private'))
message.text = 'test'
assert not Filters.reply(message)
message.reply_to_message = another_message
assert Filters.reply(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例7: test_filters_user_id
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,代码行数:7,代码来源:test_filters.py
示例8: test_filters_chat_id
def test_filters_chat_id(self, message):
assert not Filters.chat(chat_id=-1)(message)
message.chat.id = -1
assert Filters.chat(chat_id=-1)(message)
message.chat.id = -2
assert Filters.chat(chat_id=[-1, -2])(message)
assert not Filters.chat(chat_id=[-3, -4])(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:7,代码来源:test_filters.py
示例9: main
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,代码行数:57,代码来源:rules_bot.py
示例10: test_entities_filter
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,代码行数:12,代码来源:test_filters.py
示例11: test_entities_filter
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,代码行数:12,代码来源:test_filters.py
示例12: test_entities_filter
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,代码行数:14,代码来源:test_filters.py
示例13: test_and_or_filters
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,代码行数:16,代码来源:test_filters.py
示例14: test_language_filter_multiple
def test_language_filter_multiple(self, message):
f = Filters.language(['en_US', 'da'])
message.from_user.language_code = 'en_US'
assert f(message)
message.from_user.language_code = 'en_GB'
assert not f(message)
message.from_user.language_code = 'da'
assert f(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:8,代码来源:test_filters.py
示例15: test_language_filter_multiple
def test_language_filter_multiple(self):
f = Filters.language(['en_US', 'da'])
self.message.from_user.language_code = 'en_US'
self.assertTrue(f(self.message))
self.message.from_user.language_code = 'en_GB'
self.assertFalse(f(self.message))
self.message.from_user.language_code = 'da'
self.assertTrue(f(self.message))
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:8,代码来源:test_filters.py
示例16: test_and_or_filters
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,代码行数:18,代码来源:test_filters.py
示例17: test_and_filters
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,代码行数:18,代码来源:test_filters.py
示例18: test_language_filter_single
def test_language_filter_single(self, message):
message.from_user.language_code = 'en_US'
assert (Filters.language('en_US'))(message)
assert (Filters.language('en'))(message)
assert not (Filters.language('en_GB'))(message)
assert not (Filters.language('da'))(message)
message.from_user.language_code = 'da'
assert not (Filters.language('en_US'))(message)
assert not (Filters.language('en'))(message)
assert not (Filters.language('en_GB'))(message)
assert (Filters.language('da'))(message)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:11,代码来源:test_filters.py
示例19: test_and_or_filters
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,代码行数:12,代码来源:test_filters.py
示例20: test_filters_username
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,代码行数:8,代码来源:test_filters.py
注:本文中的telegram.ext.Filters类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论