forked from LazyDeveloperr/LazyPrincess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm_filter.py
829 lines (775 loc) Β· 34.9 KB
/
pm_filter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# Kanged From @TroJanZheX
import asyncio
import re
import ast
import math
from pyrogram.errors.exceptions.bad_request_400 import MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty
from Script import script
import pyrogram
from database.connections_mdb import active_connection, all_connections, delete_connection, if_active, make_active, \
make_inactive
from info import ADMINS, AUTH_CHANNEL, AUTH_USERS, CUSTOM_FILE_CAPTION, AUTH_GROUPS, P_TTI_SHOW_OFF, IMDB, \
SINGLE_BUTTON, SPELL_CHECK_REPLY, IMDB_TEMPLATE
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram import Client, filters, enums
from pyrogram.errors import FloodWait, UserIsBlocked, MessageNotModified, PeerIdInvalid
from utils import get_size, is_subscribed, get_poster, search_gagala, temp, get_settings, save_group_settings
from database.users_chats_db import db
from database.ia_filterdb import Media, get_file_details, get_search_results
from database.filters_mdb import (
del_all,
find_filter,
get_filters,
)
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
BUTTONS = {}
SPELL_CHECK = {}
@Client.on_message(filters.group & filters.text & filters.incoming)
async def give_filter(client, message):
k = await manual_filters(client, message)
if k == False:
await auto_filter(client, message)
@Client.on_callback_query(filters.regex(r"^next"))
async def next_page(bot, query):
ident, req, key, offset = query.data.split("_")
if int(req) not in [query.from_user.id, 0]:
return await query.answer("This Message is not for you dear. Don't worry you can send new one !", show_alert=True)
try:
offset = int(offset)
except:
offset = 0
search = BUTTONS.get(key)
if not search:
await query.answer("You are using one of my old messages, please send the request again.", show_alert=True)
return
files, n_offset, total = await get_search_results(search, offset=offset, filter=True)
try:
n_offset = int(n_offset)
except:
n_offset = 0
if not files:
return
settings = await get_settings(query.message.chat.id)
if settings['button']:
btn = [
[
InlineKeyboardButton(
text=f"[{get_size(file.file_size)}] {file.file_name}", callback_data=f'files#{file.file_id}'
),
]
for file in files
]
else:
btn = [
[
InlineKeyboardButton(
text=f"{file.file_name}", callback_data=f'files#{file.file_id}'
),
InlineKeyboardButton(
text=f"{get_size(file.file_size)}",
callback_data=f'files_#{file.file_id}',
),
]
for file in files
]
if 0 < offset <= 10:
off_set = 0
elif offset == 0:
off_set = None
else:
off_set = offset - 10
if n_offset == 0:
btn.append(
[InlineKeyboardButton("βͺ BACK", callback_data=f"next_{req}_{key}_{off_set}"),
InlineKeyboardButton(f"π Pages {math.ceil(int(offset) / 10) + 1} / {math.ceil(total / 10)}",
callback_data="pages")]
)
elif off_set is None:
btn.append(
[InlineKeyboardButton(f"π {math.ceil(int(offset) / 10) + 1} / {math.ceil(total / 10)}", callback_data="pages"),
InlineKeyboardButton("NEXT β©", callback_data=f"next_{req}_{key}_{n_offset}")])
else:
btn.append(
[
InlineKeyboardButton("βͺ BACK", callback_data=f"next_{req}_{key}_{off_set}"),
InlineKeyboardButton(f"π {math.ceil(int(offset) / 10) + 1} / {math.ceil(total / 10)}", callback_data="pages"),
InlineKeyboardButton("NEXT β©", callback_data=f"next_{req}_{key}_{n_offset}")
],
)
try:
await query.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(btn)
)
except MessageNotModified:
pass
await query.answer()
@Client.on_callback_query(filters.regex(r"^spolling"))
async def advantage_spoll_choker(bot, query):
_, user, movie_ = query.data.split('#')
if int(user) != 0 and query.from_user.id != int(user):
return await query.answer("This Message is not for you dear. Don't worry you can send new one !", show_alert=True)
if movie_ == "close_spellcheck":
return await query.message.delete()
movies = SPELL_CHECK.get(query.message.reply_to_message.id)
if not movies:
return await query.answer("You are clicking on an old button which is expired.", show_alert=True)
movie = movies[(int(movie_))]
await query.answer('Checking for Movie in database...')
k = await manual_filters(bot, query.message, text=movie)
if k == False:
files, offset, total_results = await get_search_results(movie, offset=0, filter=True)
if files:
k = (movie, files, offset, total_results)
await auto_filter(bot, query, k)
else:
k = await query.message.edit('π currently unavailable ! we are really sorry for inconvenience !\n Have patience ! our great admins will upload it as soon as possible !')
await asyncio.sleep(10)
await k.delete()
@Client.on_callback_query()
async def cb_handler(client: Client, query: CallbackQuery):
if query.data == "close_data":
await query.message.delete()
elif query.data == "delallconfirm":
userid = query.from_user.id
chat_type = query.message.chat.type
if chat_type == enums.ChatType.PRIVATE:
grpid = await active_connection(str(userid))
if grpid is not None:
grp_id = grpid
try:
chat = await client.get_chat(grpid)
title = chat.title
except:
await query.message.edit_text("Make sure I'm present in your group!!", quote=True)
return await query.answer('β₯οΈ Love @LazyDeveloper β₯οΈ')
else:
await query.message.edit_text(
"I'm not connected to any groups!\nCheck /connections or connect to any groups",
quote=True
)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
grp_id = query.message.chat.id
title = query.message.chat.title
else:
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
st = await client.get_chat_member(grp_id, userid)
if (st.status == enums.ChatMemberStatus.OWNER) or (str(userid) in ADMINS):
await del_all(query.message, grp_id, title)
else:
await query.answer("You need to be Group Owner or an Auth User to do that!", show_alert=True)
elif query.data == "delallcancel":
userid = query.from_user.id
chat_type = query.message.chat.type
if chat_type == enums.ChatType.PRIVATE:
await query.message.reply_to_message.delete()
await query.message.delete()
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
grp_id = query.message.chat.id
st = await client.get_chat_member(grp_id, userid)
if (st.status == enums.ChatMemberStatus.OWNER) or (str(userid) in ADMINS):
await query.message.delete()
try:
await query.message.reply_to_message.delete()
except:
pass
else:
await query.answer("That's not for you sona!", show_alert=True)
elif "groupcb" in query.data:
await query.answer()
group_id = query.data.split(":")[1]
act = query.data.split(":")[2]
hr = await client.get_chat(int(group_id))
title = hr.title
user_id = query.from_user.id
if act == "":
stat = "CONNECT"
cb = "connectcb"
else:
stat = "DISCONNECT"
cb = "disconnect"
keyboard = InlineKeyboardMarkup([
[InlineKeyboardButton(f"{stat}", callback_data=f"{cb}:{group_id}"),
InlineKeyboardButton("DELETE", callback_data=f"deletecb:{group_id}")],
[InlineKeyboardButton("BACK", callback_data="backcb")]
])
await query.message.edit_text(
f"Group Name : **{title}**\nGroup ID : `{group_id}`",
reply_markup=keyboard,
parse_mode=enums.ParseMode.MARKDOWN
)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif "connectcb" in query.data:
await query.answer()
group_id = query.data.split(":")[1]
hr = await client.get_chat(int(group_id))
title = hr.title
user_id = query.from_user.id
mkact = await make_active(str(user_id), str(group_id))
if mkact:
await query.message.edit_text(
f"Connected to **{title}**",
parse_mode=enums.ParseMode.MARKDOWN
)
else:
await query.message.edit_text('Some error occurred!!', parse_mode=enums.ParseMode.MARKDOWN)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif "disconnect" in query.data:
await query.answer()
group_id = query.data.split(":")[1]
hr = await client.get_chat(int(group_id))
title = hr.title
user_id = query.from_user.id
mkinact = await make_inactive(str(user_id))
if mkinact:
await query.message.edit_text(
f"Disconnected from **{title}**",
parse_mode=enums.ParseMode.MARKDOWN
)
else:
await query.message.edit_text(
f"Some error occurred!!",
parse_mode=enums.ParseMode.MARKDOWN
)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif "deletecb" in query.data:
await query.answer()
user_id = query.from_user.id
group_id = query.data.split(":")[1]
delcon = await delete_connection(str(user_id), str(group_id))
if delcon:
await query.message.edit_text(
"Successfully deleted connection"
)
else:
await query.message.edit_text(
f"Some error occurred!!",
parse_mode=enums.ParseMode.MARKDOWN
)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif query.data == "backcb":
await query.answer()
userid = query.from_user.id
groupids = await all_connections(str(userid))
if groupids is None:
await query.message.edit_text(
"There are no active connections!! Connect to some groups first.",
)
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
buttons = []
for groupid in groupids:
try:
ttl = await client.get_chat(int(groupid))
title = ttl.title
active = await if_active(str(userid), str(groupid))
act = " - ACTIVE" if active else ""
buttons.append(
[
InlineKeyboardButton(
text=f"{title}{act}", callback_data=f"groupcb:{groupid}:{act}"
)
]
)
except:
pass
if buttons:
await query.message.edit_text(
"Your connected group details ;\n\n",
reply_markup=InlineKeyboardMarkup(buttons)
)
elif "alertmessage" in query.data:
grp_id = query.message.chat.id
i = query.data.split(":")[1]
keyword = query.data.split(":")[2]
reply_text, btn, alerts, fileid = await find_filter(grp_id, keyword)
if alerts is not None:
alerts = ast.literal_eval(alerts)
alert = alerts[int(i)]
alert = alert.replace("\\n", "\n").replace("\\t", "\t")
await query.answer(alert, show_alert=True)
if query.data.startswith("file"):
ident, file_id = query.data.split("#")
files_ = await get_file_details(file_id)
if not files_:
return await query.answer('No such file exist.')
files = files_[0]
title = files.file_name
size = get_size(files.file_size)
f_caption = files.caption
settings = await get_settings(query.message.chat.id)
if CUSTOM_FILE_CAPTION:
try:
f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
file_size='' if size is None else size,
file_caption='' if f_caption is None else f_caption)
except Exception as e:
logger.exception(e)
f_caption = f_caption
if f_caption is None:
f_caption = f"{files.file_name}"
try:
if AUTH_CHANNEL and not await is_subscribed(client, query):
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
return
elif settings['botpm']:
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
return
else:
await client.send_cached_media(
chat_id=query.from_user.id,
file_id=file_id,
caption=f_caption,
protect_content=True if ident == "filep" else False
)
await query.answer('Check PM, I have sent files in pm', show_alert=True)
except UserIsBlocked:
await query.answer('Unblock the bot mahn !', show_alert=True)
except PeerIdInvalid:
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
except Exception as e:
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
elif query.data.startswith("checksub"):
if AUTH_CHANNEL and not await is_subscribed(client, query):
await query.answer("Mere saamne jyada smart nhi banne ka sona π", show_alert=True)
return
ident, file_id = query.data.split("#")
files_ = await get_file_details(file_id)
if not files_:
return await query.answer('No such file exist.')
files = files_[0]
title = files.file_name
size = get_size(files.file_size)
f_caption = files.caption
if CUSTOM_FILE_CAPTION:
try:
f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
file_size='' if size is None else size,
file_caption='' if f_caption is None else f_caption)
except Exception as e:
logger.exception(e)
f_caption = f_caption
if f_caption is None:
f_caption = f"{title}"
await query.answer()
await client.send_cached_media(
chat_id=query.from_user.id,
file_id=file_id,
caption=f_caption,
protect_content=True if ident == 'checksubp' else False
)
elif query.data == "pages":
await query.answer()
elif query.data == "start":
buttons = [[
InlineKeyboardButton('ββοΈ Add Me To Your Groups βοΈβ', url=f'http://t.me/{temp.U_NAME}?startgroup=true')
], [
InlineKeyboardButton('π§ββοΈ Search π§', switch_inline_query_current_chat=''),
InlineKeyboardButton('π Updates π€', url='https://t.me/LazyDeveloper')
], [
InlineKeyboardButton('ππ» Help π¦Ύ', callback_data='help'),
InlineKeyboardButton('β₯οΈ About β₯οΈ', callback_data='about')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.START_TXT.format(query.from_user.mention, temp.U_NAME, temp.B_NAME),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
elif query.data == "help":
buttons = [[
InlineKeyboardButton('Manual Filter', callback_data='manuelfilter'),
InlineKeyboardButton('Auto Filter', callback_data='autofilter')
], [
InlineKeyboardButton('Connection', callback_data='coct'),
InlineKeyboardButton('Extra Mods', callback_data='extra')
], [
InlineKeyboardButton('π Home', callback_data='start'),
InlineKeyboardButton('π¦ Status', callback_data='stats')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.HELP_TXT.format(query.from_user.mention),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "about":
buttons = [[
InlineKeyboardButton('π Updates π€', url='https://t.me/LazyDeveloper'),
InlineKeyboardButton('β₯οΈ Source', callback_data='source')
], [
InlineKeyboardButton('π Home', callback_data='start'),
InlineKeyboardButton('π Close', callback_data='close_data')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.ABOUT_TXT.format(temp.B_NAME),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "source":
buttons = [[
InlineKeyboardButton('π©βπ¦― Back', callback_data='about')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.SOURCE_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "manuelfilter":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='help'),
InlineKeyboardButton('βΉοΈ Buttons', callback_data='button')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.MANUELFILTER_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "button":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='manuelfilter')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.BUTTON_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "autofilter":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='help')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.AUTOFILTER_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "coct":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='help')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.CONNECTION_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "extra":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='help'),
InlineKeyboardButton('π Admin', callback_data='admin')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.EXTRAMOD_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "admin":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='extra')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_text(
text=script.ADMIN_TXT,
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "stats":
buttons = [[
InlineKeyboardButton('πͺ Back', callback_data='help'),
InlineKeyboardButton('β»οΈ', callback_data='rfrsh')
]]
reply_markup = InlineKeyboardMarkup(buttons)
total = await Media.count_documents()
users = await db.total_users_count()
chats = await db.total_chat_count()
monsize = await db.get_db_size()
free = 536870912 - monsize
monsize = get_size(monsize)
free = get_size(free)
await query.message.edit_text(
text=script.STATUS_TXT.format(total, users, chats, monsize, free),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data == "rfrsh":
await query.answer("Fetching MongoDb DataBase")
buttons = [[
InlineKeyboardButton('π©βπ¦― Back', callback_data='help'),
InlineKeyboardButton('refresh', callback_data='rfrsh')
]]
reply_markup = InlineKeyboardMarkup(buttons)
total = await Media.count_documents()
users = await db.total_users_count()
chats = await db.total_chat_count()
monsize = await db.get_db_size()
free = 536870912 - monsize
monsize = get_size(monsize)
free = get_size(free)
await query.message.edit_text(
text=script.STATUS_TXT.format(total, users, chats, monsize, free),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
elif query.data.startswith("setgs"):
ident, set_type, status, grp_id = query.data.split("#")
grpid = await active_connection(str(query.from_user.id))
if str(grp_id) != str(grpid):
await query.message.edit("Your Active Connection Has Been Changed. Go To /settings.")
return await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
if status == "True":
await save_group_settings(grpid, set_type, False)
else:
await save_group_settings(grpid, set_type, True)
settings = await get_settings(grpid)
if settings is not None:
buttons = [
[
InlineKeyboardButton('Filter Button',
callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}'),
InlineKeyboardButton('Single' if settings["button"] else 'Double',
callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}')
],
[
InlineKeyboardButton('Bot PM', callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}'),
InlineKeyboardButton('β
Yes' if settings["botpm"] else 'β No',
callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}')
],
[
InlineKeyboardButton('File Secure',
callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}'),
InlineKeyboardButton('β
Yes' if settings["file_secure"] else 'β No',
callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}')
],
[
InlineKeyboardButton('IMDB', callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}'),
InlineKeyboardButton('β
Yes' if settings["imdb"] else 'β No',
callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}')
],
[
InlineKeyboardButton('Spell Check',
callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}'),
InlineKeyboardButton('β
Yes' if settings["spell_check"] else 'β No',
callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}')
],
[
InlineKeyboardButton('Welcome', callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}'),
InlineKeyboardButton('β
Yes' if settings["welcome"] else 'β No',
callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}')
]
]
reply_markup = InlineKeyboardMarkup(buttons)
await query.message.edit_reply_markup(reply_markup)
await query.answer('β₯οΈ Thank You LazyDeveloper β₯οΈ')
async def auto_filter(client, msg, spoll=False):
if not spoll:
message = msg
settings = await get_settings(message.chat.id)
if message.text.startswith("/"): return # ignore commands
if re.findall("((^\/|^,|^!|^\.|^[\U0001F600-\U000E007F]).*)", message.text):
return
if 2 < len(message.text) < 100:
search = message.text
files, offset, total_results = await get_search_results(search.lower(), offset=0, filter=True)
if not files:
if settings["spell_check"]:
return await advantage_spell_chok(msg)
else:
return
else:
return
else:
settings = await get_settings(msg.message.chat.id)
message = msg.message.reply_to_message # msg will be callback query
search, files, offset, total_results = spoll
pre = 'filep' if settings['file_secure'] else 'file'
if settings["button"]:
btn = [
[
InlineKeyboardButton(
text=f"[{get_size(file.file_size)}] {file.file_name}", callback_data=f'{pre}#{file.file_id}'
),
]
for file in files
]
else:
btn = [
[
InlineKeyboardButton(
text=f"{file.file_name}",
callback_data=f'{pre}#{file.file_id}',
),
InlineKeyboardButton(
text=f"{get_size(file.file_size)}",
callback_data=f'{pre}#{file.file_id}',
),
]
for file in files
]
if offset != "":
key = f"{message.chat.id}-{message.id}"
BUTTONS[key] = search
req = message.from_user.id if message.from_user else 0
btn.append(
[InlineKeyboardButton(text=f"π 1/{math.ceil(int(total_results) / 10)}", callback_data="pages"),
InlineKeyboardButton(text="NEXT β©", callback_data=f"next_{req}_{key}_{offset}")]
)
else:
btn.append(
[InlineKeyboardButton(text="π 1/1", callback_data="pages")]
)
imdb = await get_poster(search, file=(files[0]).file_name) if settings["imdb"] else None
TEMPLATE = settings['template']
if imdb:
cap = TEMPLATE.format(
query=search,
title=imdb['title'],
votes=imdb['votes'],
aka=imdb["aka"],
seasons=imdb["seasons"],
box_office=imdb['box_office'],
localized_title=imdb['localized_title'],
kind=imdb['kind'],
imdb_id=imdb["imdb_id"],
cast=imdb["cast"],
runtime=imdb["runtime"],
countries=imdb["countries"],
certificates=imdb["certificates"],
languages=imdb["languages"],
director=imdb["director"],
writer=imdb["writer"],
producer=imdb["producer"],
composer=imdb["composer"],
cinematographer=imdb["cinematographer"],
music_team=imdb["music_team"],
distributors=imdb["distributors"],
release_date=imdb['release_date'],
year=imdb['year'],
genres=imdb['genres'],
poster=imdb['poster'],
plot=imdb['plot'],
rating=imdb['rating'],
url=imdb['url'],
**locals()
)
else:
cap = f"Baby, Here is what i found for your query {search}"
if imdb and imdb.get('poster'):
try:
await message.reply_photo(photo=imdb.get('poster'), caption=cap[:1024],
reply_markup=InlineKeyboardMarkup(btn))
except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
pic = imdb.get('poster')
poster = pic.replace('.jpg', "._V1_UX360.jpg")
await message.reply_photo(photo=poster, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btn))
except Exception as e:
logger.exception(e)
await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btn))
else:
await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btn))
if spoll:
await msg.message.delete()
async def advantage_spell_chok(msg):
query = re.sub(
r"\b(pl(i|e)*?(s|z+|ease|se|ese|(e+)s(e)?)|((send|snd|giv(e)?|gib)(\sme)?)|movie(s)?|new|latest|br((o|u)h?)*|^h(e|a)?(l)*(o)*|mal(ayalam)?|t(h)?amil|file|that|find|und(o)*|kit(t(i|y)?)?o(w)?|thar(u)?(o)*w?|kittum(o)*|aya(k)*(um(o)*)?|full\smovie|any(one)|with\ssubtitle(s)?)",
"", msg.text, flags=re.IGNORECASE) # plis contribute some common words
query = query.strip() + " movie"
g_s = await search_gagala(query)
g_s += await search_gagala(msg.text)
gs_parsed = []
if not g_s:
k = await msg.reply("I couldn't find any movie in that name.")
await asyncio.sleep(8)
await k.delete()
return
regex = re.compile(r".*(imdb|wikipedia).*", re.IGNORECASE) # look for imdb / wiki results
gs = list(filter(regex.match, g_s))
gs_parsed = [re.sub(
r'\b(\-([a-zA-Z-\s])\-\simdb|(\-\s)?imdb|(\-\s)?wikipedia|\(|\)|\-|reviews|full|all|episode(s)?|film|movie|series)',
'', i, flags=re.IGNORECASE) for i in gs]
if not gs_parsed:
reg = re.compile(r"watch(\s[a-zA-Z0-9_\s\-\(\)]*)*\|.*",
re.IGNORECASE) # match something like Watch Niram | Amazon Prime
for mv in g_s:
match = reg.match(mv)
if match:
gs_parsed.append(match.group(1))
user = msg.from_user.id if msg.from_user else 0
movielist = []
gs_parsed = list(dict.fromkeys(gs_parsed)) # removing duplicates https://stackoverflow.com/a/7961425
if len(gs_parsed) > 3:
gs_parsed = gs_parsed[:3]
if gs_parsed:
for mov in gs_parsed:
imdb_s = await get_poster(mov.strip(), bulk=True) # searching each keyword in imdb
if imdb_s:
movielist += [movie.get('title') for movie in imdb_s]
movielist += [(re.sub(r'(\-|\(|\)|_)', '', i, flags=re.IGNORECASE)).strip() for i in gs_parsed]
movielist = list(dict.fromkeys(movielist)) # removing duplicates
if not movielist:
k = await msg.reply("Hey Sona! Mujhe is naam se koi movie nhi mili, Mujhe lgta hai ki aapne spelling galat likh dii h π€·ββοΈ!\nPlease check your spelling once again π€¦ββοΈ... or \n Discuss your problem with our admin here π @discussion_groupp ")
await asyncio.sleep(8)
await k.delete()
return
SPELL_CHECK[msg.id] = movielist
btn = [[
InlineKeyboardButton(
text=movie.strip(),
callback_data=f"spolling#{user}#{k}",
)
] for k, movie in enumerate(movielist)]
btn.append([InlineKeyboardButton(text="Close", callback_data=f'spolling#{user}#close_spellcheck')])
await msg.reply("Hey Sona! Mujhe is naam se koi movie nhi mili, Mujhe lgta hai ki aapne spelling galat likh dii h π€·ββοΈ!\nPlease check your spelling once again π€¦ββοΈ... or \n Discuss your problem with our admin here π @discussion_groupp ",
reply_markup=InlineKeyboardMarkup(btn))
async def manual_filters(client, message, text=False):
group_id = message.chat.id
name = text or message.text
reply_id = message.reply_to_message.id if message.reply_to_message else message.id
keywords = await get_filters(group_id)
for keyword in reversed(sorted(keywords, key=len)):
pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
if re.search(pattern, name, flags=re.IGNORECASE):
reply_text, btn, alert, fileid = await find_filter(group_id, keyword)
if reply_text:
reply_text = reply_text.replace("\\n", "\n").replace("\\t", "\t")
if btn is not None:
try:
if fileid == "None":
if btn == "[]":
await client.send_message(group_id, reply_text, disable_web_page_preview=True)
else:
button = eval(btn)
await client.send_message(
group_id,
reply_text,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(button),
reply_to_message_id=reply_id
)
elif btn == "[]":
await client.send_cached_media(
group_id,
fileid,
caption=reply_text or "",
reply_to_message_id=reply_id
)
else:
button = eval(btn)
await message.reply_cached_media(
fileid,
caption=reply_text or "",
reply_markup=InlineKeyboardMarkup(button),
reply_to_message_id=reply_id
)
except Exception as e:
logger.exception(e)
break
else:
return False