@@ -331,9 +331,9 @@ class user(BaseFilter):
331
331
Only one of chat_id or username must be used here.
332
332
333
333
Args:
334
- user_id(Optional[int]): which user ID to allow through.
335
- username(Optional[str]): which username to allow through. If username starts with '@'
336
- symbol, it will be ignored.
334
+ user_id(Optional[int|list ]): which user ID(s) to allow through.
335
+ username(Optional[str|list ]): which username(s) to allow through. If username starts
336
+ with '@' symbol, it will be ignored.
337
337
338
338
Raises:
339
339
ValueError
@@ -342,19 +342,24 @@ class user(BaseFilter):
342
342
def __init__ (self , user_id = None , username = None ):
343
343
if not (bool (user_id ) ^ bool (username )):
344
344
raise ValueError ('One and only one of user_id or username must be used' )
345
- if username is not None and username . startswith ( '@' ):
346
- self .username = username [ 1 : ]
345
+ if user_id is not None and isinstance ( user_id , int ):
346
+ self .user_ids = [ user_id ]
347
347
else :
348
- self .username = username
349
- self .user_id = user_id
348
+ self .user_ids = user_id
349
+ if username is None :
350
+ self .usernames = username
351
+ elif isinstance (username , str_type ):
352
+ self .usernames = [username .replace ('@' , '' )]
353
+ else :
354
+ self .usernames = [user .replace ('@' , '' ) for user in username ]
350
355
351
356
def filter (self , message ):
352
- if self .user_id is not None :
353
- return bool (message .from_user and message .from_user .id == self .user_id )
357
+ if self .user_ids is not None :
358
+ return bool (message .from_user and message .from_user .id in self .user_ids )
354
359
else :
355
- # self.username is not None
360
+ # self.usernames is not None
356
361
return bool (message .from_user and message .from_user .username and
357
- message .from_user .username == self .username )
362
+ message .from_user .username in self .usernames )
358
363
359
364
class chat (BaseFilter ):
360
365
"""Filters messages to allow only those which are from specified chat ID.
@@ -363,29 +368,34 @@ class chat(BaseFilter):
363
368
Only one of chat_id or username must be used here.
364
369
365
370
Args:
366
- chat_id(Optional[int]): which chat ID to allow through.
367
- username(Optional[str]): which username to allow through. If username starts with '@'
368
- symbol, it will be ignored.
371
+ chat_id(Optional[int|list ]): which chat ID(s) to allow through.
372
+ username(Optional[str|list ]): which username(s) to allow through. If username starts
373
+ with '@' symbol, it will be ignored.
369
374
370
375
Raises:
371
376
ValueError
372
377
"""
373
378
374
379
def __init__ (self , chat_id = None , username = None ):
375
380
if not (bool (chat_id ) ^ bool (username )):
376
- raise ValueError ('One and only one of user_id or username must be used' )
377
- if username is not None and username .startswith ('@' ):
378
- self .username = username [1 :]
381
+ raise ValueError ('One and only one of chat_id or username must be used' )
382
+ if chat_id is not None and isinstance (chat_id , int ):
383
+ self .chat_ids = [chat_id ]
384
+ else :
385
+ self .chat_ids = chat_id
386
+ if username is None :
387
+ self .usernames = username
388
+ elif isinstance (username , str_type ):
389
+ self .usernames = [username .replace ('@' , '' )]
379
390
else :
380
- self .username = username
381
- self .chat_id = chat_id
391
+ self .usernames = [chat .replace ('@' , '' ) for chat in username ]
382
392
383
393
def filter (self , message ):
384
- if self .chat_id is not None :
385
- return message .chat_id == self .chat_id
394
+ if self .chat_ids is not None :
395
+ return bool ( message .chat_id in self .chat_ids )
386
396
else :
387
- # self.username is not None
388
- return bool (message .chat .username and message .chat .username == self .username )
397
+ # self.usernames is not None
398
+ return bool (message .chat .username and message .chat .username in self .usernames )
389
399
390
400
class _Invoice (BaseFilter ):
391
401
0 commit comments