Skip to content

Commit 8b0113f

Browse files
committed
New 'sender' filter
1 parent 1ede8cd commit 8b0113f

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

tgbox/api/utils.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,8 @@ async def _async_iter_from(_iter_from):
415415
else:
416416
file_path = ''
417417

418-
# We will use it as flags, the first
419-
# is for 'include', the second is for
420-
# 'exclude'. Both should be True to
421-
# match SearchFilter filters.
418+
# We will use it as flags, the first is for 'include', the second is
419+
# for 'exclude'. Both should be True to match SearchFilter filters.
422420
yield_result = [True, True]
423421

424422
for indx, filter in enumerate((sf.in_filters, sf.ex_filters)):
@@ -433,6 +431,42 @@ async def _async_iter_from(_iter_from):
433431
yield_result[indx] = False
434432
break
435433

434+
for sender in filter['sender']:
435+
# If sender is int, then it we check only against
436+
# the 'sender_id', if str, we check against the
437+
# 'sender', and if sender isnumeric(), we convert
438+
# to int and also check against 'sender_id'
439+
440+
# sender and sender_id is presented only in RemoteBox
441+
# files and only in Box channels with Sign Messages
442+
# -> Show Author Profiles enabled. If file doesn't
443+
# have sender, then always skip a file.
444+
445+
file_sender_id, _check = getattr(file, 'sender_id', None), False
446+
447+
if isinstance(sender, int):
448+
if sender == file_sender:
449+
_check = True
450+
451+
if isinstance(sender, str):
452+
file_sender = getattr(file, 'sender') or ''
453+
454+
if in_func(sender, file_sender):
455+
_check = True
456+
else:
457+
if sender.isnumeric() and int(sender) == file_sender_id:
458+
_check = True
459+
460+
if _check:
461+
if indx == 1:
462+
yield_result[indx] = False
463+
break
464+
else:
465+
if filter['sender']:
466+
if indx == 0:
467+
yield_result[indx] = False
468+
break
469+
436470
for minor_version in filter['minor_version']:
437471
if minor_version == file.minor_version:
438472
if indx == 1:

tgbox/tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ class SearchFilter:
177177
* **verbyte** *bytes*: File version byte
178178
* **mime** *str*: File mime type
179179
180+
* **sender** *integer/str*: File sender name or ID:
181+
Only works on RemoteBox files and only on
182+
RemoteBox that enabled Sign Messages (&
183+
Show Author Profiles, optionally for IDs),
184+
otherwise will never return files.
185+
186+
This filter can be Sender name or Sender ID,
187+
e.g sender='black sabbath' or sender=36265675;
188+
if 'sender' is string but .isnumeric(), Generator
189+
will also convert it to int and check against
190+
ID (if available), essentially, sender=36265675
191+
and sender='36265675' both valid, but latter
192+
will also check '36265675' in name.
193+
180194
* **minor_version** *integer*: File minor version
181195
182196
* **min_id** *integer*: File ID should be > min_id
@@ -208,6 +222,7 @@ def __init__(self, **kwargs):
208222
'min_time': _TypeList((int,float)),
209223
'max_time': _TypeList((int,float)),
210224
'mime': _TypeList(str),
225+
'sender': _TypeList((str,int)),
211226
'imported': _TypeList(bool),
212227
're': _TypeList(bool),
213228
'minor_version': _TypeList(int),

0 commit comments

Comments
 (0)