Remove user and chat arguments, update the example

This commit is contained in:
birdi 2019-07-22 17:49:30 +03:00
parent 80b1168480
commit 8b028693b6
2 changed files with 9 additions and 27 deletions

View file

@ -522,14 +522,10 @@ class IdFilter(Filter):
@classmethod @classmethod
def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Optional[typing.Dict[str, typing.Any]]: def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Optional[typing.Dict[str, typing.Any]]:
result = {} result = {}
if 'user' in full_config: if 'user_id' in full_config:
result['user_id'] = full_config.pop('user')
elif 'user_id' in full_config:
result['user_id'] = full_config.pop('user_id') result['user_id'] = full_config.pop('user_id')
if 'chat' in full_config: if 'chat_id' in full_config:
result['chat_id'] = full_config.pop('chat')
elif 'chat_id' in full_config:
result['chat_id'] = full_config.pop('chat_id') result['chat_id'] = full_config.pop('chat_id')
return result return result

View file

@ -9,43 +9,29 @@ user_id_to_test = None # todo: Set id here
chat_id_to_test = user_id_to_test chat_id_to_test = user_id_to_test
@dp.message_handler(user=user_id_to_test)
async def handler1(msg: types.Message):
await bot.send_message(msg.chat.id,
"Hello, checking with user=")
raise SkipHandler
@dp.message_handler(user_id=user_id_to_test) @dp.message_handler(user_id=user_id_to_test)
async def handler2(msg: types.Message): async def handler1(msg: types.Message):
await bot.send_message(msg.chat.id, await bot.send_message(msg.chat.id,
"Hello, checking with user_id=") "Hello, checking with user_id=")
raise SkipHandler raise SkipHandler
@dp.message_handler(chat=chat_id_to_test)
async def handler3(msg: types.Message):
await bot.send_message(msg.chat.id,
"Hello, checking with chat=")
raise SkipHandler
@dp.message_handler(chat_id=chat_id_to_test) @dp.message_handler(chat_id=chat_id_to_test)
async def handler4(msg: types.Message): async def handler2(msg: types.Message):
await bot.send_message(msg.chat.id, await bot.send_message(msg.chat.id,
"Hello, checking with chat_id=") "Hello, checking with chat_id=")
raise SkipHandler raise SkipHandler
@dp.message_handler(user=user_id_to_test, chat_id=chat_id_to_test) @dp.message_handler(user_id=user_id_to_test, chat_id=chat_id_to_test)
async def handler5(msg: types.Message): async def handler3(msg: types.Message):
await bot.send_message(msg.chat.id, await bot.send_message(msg.chat.id,
"Hello from user= & chat_id=") "Hello from user= & chat_id=")
@dp.message_handler(user=[user_id_to_test, 123]) # todo: add second id here @dp.message_handler(user_id=[user_id_to_test, 123]) # todo: add second id here
async def handler6(msg: types.Message): async def handler4(msg: types.Message):
print("Checked with list!") print("Checked user_id with list!")
if __name__ == '__main__': if __name__ == '__main__':