forked from TeamUltroid/UltroidAddons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
searchmsgs.py
52 lines (43 loc) · 1.21 KB
/
searchmsgs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# " Made by @e3ris for Ultroid. "
# < https://github.com/TeamUltroid/Ultroid >
# idea: https://t.me/TelethonChat/256160
"""
✘ To Search Messages in chat easily :)
✘ **CMD** :
>> {i}search (some_text)
>> {i}search -r (some_text) : 10
»» To search in Reverse order.
✘ **Examples** :
• `{i}search Ultroid`
• `{i}search -r Heroku : 10`
"""
@ultroid_cmd(pattern="search( -r|) ?(.*)")
async def searcher(e):
eris = await e.eor("`Working..`")
args = e.pattern_match.group(2)
limit = 5
if not args or len(args) < 2:
await eod(eris, "Invalid argument!, Try again")
return
if ":" in args:
args, limit = args.split(":", 1)
try:
limit = int(limit)
except BaseException:
limit = 5
limit = 99 if limit > 99 else limit
text, c = "", 0
async for msg in e.client.iter_messages(
e.chat_id,
search=args.strip(),
limit=limit,
reverse=bool(e.pattern_match.group(1)),
):
text += f" [»» {msg.id}](t.me/c/{e.chat.id}/{msg.id})\n"
c += 1
txt = (
f"**Results for :** `{args}` \n\n{text}"
if c > 0
else f"**No Results for :** `{args}`"
)
await eris.edit(txt)