mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Remove user and chat arguments, update the example
This commit is contained in:
parent
80b1168480
commit
8b028693b6
2 changed files with 9 additions and 27 deletions
|
|
@ -522,14 +522,10 @@ class IdFilter(Filter):
|
|||
@classmethod
|
||||
def validate(cls, full_config: typing.Dict[str, typing.Any]) -> typing.Optional[typing.Dict[str, typing.Any]]:
|
||||
result = {}
|
||||
if 'user' in full_config:
|
||||
result['user_id'] = full_config.pop('user')
|
||||
elif 'user_id' in full_config:
|
||||
if 'user_id' in full_config:
|
||||
result['user_id'] = full_config.pop('user_id')
|
||||
|
||||
if 'chat' in full_config:
|
||||
result['chat_id'] = full_config.pop('chat')
|
||||
elif 'chat_id' in full_config:
|
||||
if 'chat_id' in full_config:
|
||||
result['chat_id'] = full_config.pop('chat_id')
|
||||
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -9,43 +9,29 @@ user_id_to_test = None # todo: Set id here
|
|||
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)
|
||||
async def handler2(msg: types.Message):
|
||||
async def handler1(msg: types.Message):
|
||||
await bot.send_message(msg.chat.id,
|
||||
"Hello, checking with user_id=")
|
||||
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)
|
||||
async def handler4(msg: types.Message):
|
||||
async def handler2(msg: types.Message):
|
||||
await bot.send_message(msg.chat.id,
|
||||
"Hello, checking with chat_id=")
|
||||
raise SkipHandler
|
||||
|
||||
|
||||
@dp.message_handler(user=user_id_to_test, chat_id=chat_id_to_test)
|
||||
async def handler5(msg: types.Message):
|
||||
@dp.message_handler(user_id=user_id_to_test, chat_id=chat_id_to_test)
|
||||
async def handler3(msg: types.Message):
|
||||
await bot.send_message(msg.chat.id,
|
||||
"Hello from user= & chat_id=")
|
||||
|
||||
|
||||
@dp.message_handler(user=[user_id_to_test, 123]) # todo: add second id here
|
||||
async def handler6(msg: types.Message):
|
||||
print("Checked with list!")
|
||||
@dp.message_handler(user_id=[user_id_to_test, 123]) # todo: add second id here
|
||||
async def handler4(msg: types.Message):
|
||||
print("Checked user_id with list!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue