forked from HA-Bots/Auto-Filter-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
751 lines (711 loc) · 36.8 KB
/
commands.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
import os
import logging
import random, string
import asyncio
import time
import datetime
from Script import script
from pyrogram import Client, filters, enums
from pyrogram.errors import ChatAdminRequired, FloodWait, ButtonDataInvalid
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from database.ia_filterdb import Media, get_file_details, unpack_new_file_id, delete_files
from database.users_chats_db import db
from info import INDEX_CHANNELS, ADMINS, IS_VERIFY, VERIFY_TUTORIAL, VERIFY_EXPIRE, TUTORIAL, SHORTLINK_API, SHORTLINK_URL, AUTH_CHANNEL, DELETE_TIME, SUPPORT_LINK, UPDATES_LINK, LOG_CHANNEL, PICS, PROTECT_CONTENT, IS_STREAM, IS_FSUB, PAYMENT_QR, OWNER_USERNAME, REACTIONS, PM_DELETE_TIME as pm_delete_time
from utils import get_settings, get_size, is_subscribed, is_check_admin, get_shortlink, get_verify_status, update_verify_status, save_group_settings, temp, get_readable_time, get_wish, get_seconds
import re
import json
import base64
import sys
from shortzy import Shortzy
from telegraph import upload_file
@Client.on_message(filters.command("start") & filters.incoming)
async def start(client, message):
botid = client.me.id
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
if message.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
if not await db.get_chat(message.chat.id):
total = await client.get_chat_members_count(message.chat.id)
username = f'@{message.chat.username}' if message.chat.username else 'Private'
await client.send_message(LOG_CHANNEL, script.NEW_GROUP_TXT.format(message.chat.title, message.chat.id, username, total))
await db.add_chat(message.chat.id, message.chat.title)
wish = get_wish()
btn = [[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ᴄʜᴀɴɴᴇʟ ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 Support Group 💡', url=SUPPORT_LINK)
]]
await message.reply(text=f"<b>ʜᴇʏ {message.from_user.mention}, <i>{wish}</i>\nʜᴏᴡ ᴄᴀɴ ɪ ʜᴇʟᴘ ʏᴏᴜ??</b>", reply_markup=InlineKeyboardMarkup(btn))
return
if not await db.is_user_exist(message.from_user.id):
await db.add_user(message.from_user.id, message.from_user.first_name)
await client.send_message(LOG_CHANNEL, script.NEW_USER_TXT.format(message.from_user.mention, message.from_user.id))
verify_status = await get_verify_status(message.from_user.id)
if verify_status['is_verified'] and datetime.datetime.now() > verify_status['expiry_time']:
await update_verify_status(message.from_user.id, is_verified=False)
if (len(message.command) != 2) or (len(message.command) == 2 and message.command[1] == 'start'):
buttons = [[
InlineKeyboardButton("+ ᴀᴅᴅ ᴍᴇ ᴛᴏ ʏᴏᴜʀ ɢʀᴏᴜᴘ +", url=f'http://t.me/{temp.U_NAME}?startgroup=start')
],[
InlineKeyboardButton('🔎 sᴇᴀʀᴄʜ ɪɴʟɪɴᴇ 🔍', switch_inline_query_current_chat='')
],[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ᴄʜᴀɴɴᴇʟ ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 Support Group 💡', url=SUPPORT_LINK)
],[
InlineKeyboardButton('👨🚒 ʜᴇʟᴘ', callback_data='help'),
InlineKeyboardButton('📚 ᴀʙᴏᴜᴛ', callback_data='my_about'),
InlineKeyboardButton('👤 ᴏᴡɴᴇʀ', callback_data='my_owner')
],[
InlineKeyboardButton('💰 ᴇᴀʀɴ ᴍᴏɴᴇʏ ʙʏ ʙᴏᴛ 💰', callback_data='earn')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply_photo(
photo=random.choice(PICS),
caption=script.START_TXT.format(message.from_user.mention, get_wish()),
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
return
if len(message.command) == 2 and message.command[1] == "plans":
btn = [
[InlineKeyboardButton("ꜱᴇɴᴅ ᴘᴀʏᴍᴇɴᴛ ʀᴇᴄᴇɪᴘᴛ 🧾", url=OWNER_USERNAME)],
[InlineKeyboardButton("⚠️ ᴄʟᴏsᴇ / ᴅᴇʟᴇᴛᴇ ⚠️", callback_data="close_data")]
]
reply_markup = InlineKeyboardMarkup(btn)
await message.reply_photo(
photo=PAYMENT_QR,
caption="**Pʀᴇᴍɪᴜᴍ Fᴇᴀᴛᴜʀᴇs 🎁\n\n☆ No Need To Verify\n☆ Ad Free Experience\n☆ Unlimited Movie And Series",
reply_markup=reply_markup
)
return
mc = message.command[1]
if mc.startswith('verify'):
_, token = mc.split("_", 1)
verify_status = await get_verify_status(message.from_user.id)
if verify_status['verify_token'] != token:
return await message.reply("Your verify token is invalid.")
expiry_time = datetime.datetime.now() + datetime.timedelta(seconds=VERIFY_EXPIRE)
await update_verify_status(message.from_user.id, is_verified=True, verified_time=time.time(), expire_time=expire_time)
if verify_status["link"] == "":
reply_markup = None
else:
btn = [[
InlineKeyboardButton("📌 Get File 📌", url=f'https://t.me/{temp.U_NAME}?start={verify_status["link"]}')
]]
reply_markup = InlineKeyboardMarkup(btn)
await message.reply(f"✅ You successfully verified until: {get_readable_time(VERIFY_EXPIRE)}", reply_markup=reply_markup, protect_content=True)
return
verify_status = await get_verify_status(message.from_user.id)
if not await db.has_premium_access(message.from_user.id):
if IS_VERIFY and not verify_status['is_verified']:
token = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
await update_verify_status(message.from_user.id, verify_token=token, link="" if mc == 'inline_verify' else mc)
link = await get_shortlink(SHORTLINK_URL, SHORTLINK_API, f'https://t.me/{temp.U_NAME}?start=verify_{token}')
btn = [[
InlineKeyboardButton("🧿 Verify 🧿", url=link)
],[
InlineKeyboardButton('🗳 Tutorial 🗳', url=VERIFY_TUTORIAL)
]]
await message.reply("You not verified today! Kindly verify now. 🔐", reply_markup=InlineKeyboardMarkup(btn), protect_content=True)
return
else:
pass
settings = await get_settings(int(mc.split("_", 2)[1]))
if settings.get('is_fsub', IS_FSUB) and not await db.has_premium_access(message.from_user.id):
if settings['fsub'] is not None:
btn = await is_subscribed(client, message, settings['fsub'])
if btn:
btn.append(
[InlineKeyboardButton("🔁 Try Again 🔁", callback_data=f"checksub#{mc}")]
)
reply_markup = InlineKeyboardMarkup(btn)
await message.reply_photo(
photo=random.choice(PICS),
caption=f"👋 Hello {message.from_user.mention},\n\nPlease join my 'Updates Channel' and try again. 😇",
reply_markup=reply_markup,
parse_mode=enums.ParseMode.HTML
)
return
if mc.startswith('all'):
_, grp_id, key = mc.split("_", 2)
files = temp.FILES.get(key)
if not files:
return await message.reply('No Such All Files Exist!')
settings = await get_settings(int(grp_id))
file_ids = []
fileids = ""
for file in files:
CAPTION = settings['caption']
f_caption = CAPTION.format(
file_name = file.file_name,
file_size = get_size(file.file_size),
file_caption=file.caption
)
if settings.get('is_stream', IS_STREAM):
btn = [[
InlineKeyboardButton("✛ ᴡᴀᴛᴄʜ & ᴅᴏᴡɴʟᴏᴀᴅ ✛", callback_data=f"stream#{file.file_id}")
],[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 ꜱᴜᴘᴘᴏʀᴛ 💡', url=SUPPORT_LINK)
],[
InlineKeyboardButton('⁉️ ᴄʟᴏsᴇ ⁉️', callback_data='close_data')
]]
else:
btn = [[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 ꜱᴜᴘᴘᴏʀᴛ 💡', url=SUPPORT_LINK)
],[
InlineKeyboardButton('⁉️ ᴄʟᴏsᴇ ⁉️', callback_data='close_data')
]]
msg = await client.send_cached_media(
chat_id=message.from_user.id,
file_id=file.file_id,
caption=f_caption,
protect_content=settings['file_secure'],
reply_markup=InlineKeyboardMarkup(btn)
)
file_ids.append(msg.id)
time = get_readable_time(int(pm_delete_time))
vp = await message.reply(f"Nᴏᴛᴇ: Tʜɪs ғɪʟᴇs ᴡɪʟʟ ʙᴇ ᴅᴇʟᴇᴛᴇ ɪɴ {time} ᴛᴏ ᴀᴠᴏɪᴅ ᴄᴏᴘʏʀɪɢʜᴛs. Sᴀᴠᴇ ᴛʜᴇ ғɪʟᴇs ᴛᴏ sᴏᴍᴇᴡʜᴇʀᴇ ᴇʟsᴇ")
await asyncio.sleep(int(pm_delete_time))
btns = [[
InlineKeyboardButton('ɢᴇᴛ ғɪʟᴇs ᴀɢᴀɪɴ', callback_data=f"getmultifile_{key}_{grp_id}")
]]
await client.delete_messages(
chat_id=message.chat.id,
message_ids=file_ids
)
await vp.edit("Tʜᴇ ғɪʟᴇ ʜᴀs ʙᴇᴇɴ ɢᴏɴᴇ ! Cʟɪᴄᴋ ɢɪᴠᴇɴ ʙᴜᴛᴛᴏɴ ᴛᴏ ɢᴇᴛ ɪᴛ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(btns))
return
type_, grp_id, file_id = mc.split("_", 2)
files_ = await get_file_details(file_id)
if not files_:
return await message.reply('No Such File Exist!')
files = files_[0]
settings = await get_settings(int(grp_id))
if type_ != 'shortlink' and settings['shortlink']:
if not await db.has_premium_access(message.from_user.id):
link = await get_shortlink(settings['url'], settings['api'], f"https://t.me/{temp.U_NAME}?start=shortlink_{grp_id}_{file_id}")
btn = [[
InlineKeyboardButton("♻️ Get File ♻️", url=link)
],[
InlineKeyboardButton("📍 ʜᴏᴡ ᴛᴏ ᴏᴘᴇɴ ʟɪɴᴋ 📍", url=settings['tutorial'])
]]
await message.reply(f"[{get_size(files.file_size)}] {files.file_name}\n\nYour file is ready, Please get using this link. 👍", reply_markup=InlineKeyboardMarkup(btn), protect_content=True)
return
else:
pass
if not await db.has_premium_access(message.from_user.id):
protect_content = True
else:
protect_content = False
CAPTION = settings['caption']
f_caption = CAPTION.format(
file_name = files.file_name,
file_size = get_size(files.file_size),
file_caption=files.caption
)
if settings.get('is_stream', IS_STREAM):
btn = [[
InlineKeyboardButton("✛ ᴡᴀᴛᴄʜ & ᴅᴏᴡɴʟᴏᴀᴅ ✛", callback_data=f"stream#{file_id}")
],[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 ꜱᴜᴘᴘᴏʀᴛ 💡', url=SUPPORT_LINK)
],[
InlineKeyboardButton('⁉️ ᴄʟᴏsᴇ ⁉️', callback_data='close_data')
]]
else:
btn = [[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 ꜱᴜᴘᴘᴏʀᴛ 💡', url=SUPPORT_LINK)
],[
InlineKeyboardButton('⁉️ ᴄʟᴏsᴇ ⁉️', callback_data='close_data')
]]
vp = await client.send_cached_media(
chat_id=message.from_user.id,
file_id=file_id,
caption=f_caption,
protect_content=protect_content,
reply_markup=InlineKeyboardMarkup(btn)
)
time = get_readable_time(int(pm_delete_time))
msg = await vp.reply(f"Nᴏᴛᴇ: Tʜɪs ᴍᴇssᴀɢᴇ ᴡɪʟʟ ʙᴇ ᴅᴇʟᴇᴛᴇ ɪɴ {time} ᴛᴏ ᴀᴠᴏɪᴅ ᴄᴏᴘʏʀɪɢʜᴛs. Sᴀᴠᴇ ᴛʜᴇ ғɪʟᴇ ᴛᴏ sᴏᴍᴇᴡʜᴇʀᴇ ᴇʟsᴇ")
await asyncio.sleep(int(pm_delete_time))
btns = [[
InlineKeyboardButton('ɢᴇᴛ ғɪʟᴇ ᴀɢᴀɪɴ', callback_data=f"getfile#{file_id}#{grp_id}")
]]
await msg.delete()
await vp.delete()
await vp.reply("Tʜᴇ ғɪʟᴇ ʜᴀs ʙᴇᴇɴ ɢᴏɴᴇ ! Cʟɪᴄᴋ ɢɪᴠᴇɴ ʙᴜᴛᴛᴏɴ ᴛᴏ ɢᴇᴛ ɪᴛ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(btns))
@Client.on_message(filters.command('index_channels'))
async def channels_info(bot, message):
"""Send basic information of index channels"""
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
ids = INDEX_CHANNELS
if not ids:
return await message.reply("Not set INDEX_CHANNELS")
text = '**Indexed Channels:**\n\n'
for id in ids:
chat = await bot.get_chat(id)
text += f'{chat.title}\n'
text += f'\n**Total:** {len(ids)}'
await message.reply(text)
@Client.on_message(filters.command('stats'))
async def stats(bot, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
msg = await message.reply('Please Wait...')
files = await Media.count_documents()
users = await db.total_users_count()
chats = await db.total_chat_count()
premium = await db.all_premium_users()
u_size = get_size(await db.get_db_size())
u_size_int = await db.get_db_size()
f_size = get_size(536870912 - u_size_int)
uptime = get_readable_time(time.time() - temp.START_TIME)
await msg.edit(script.STATUS_TXT.format(files, users, chats, premium, u_size, f_size, uptime))
@Client.on_message(filters.command('settings'))
async def settings(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
settings = await get_settings(grp_id)
if settings is not None:
buttons = [[
InlineKeyboardButton('Auto Filter', callback_data=f'setgs#auto_filter#{settings["auto_filter"]}#{grp_id}'),
InlineKeyboardButton('✅ Yes' if settings["auto_filter"] else '❌ No', callback_data=f'setgs#auto_filter#{settings["auto_filter"]}#{grp_id}')
],[
InlineKeyboardButton('IMDb Poster', callback_data=f'setgs#imdb#{settings["imdb"]}#{grp_id}'),
InlineKeyboardButton('✅ Yes' if settings["imdb"] else '❌ No', callback_data=f'setgs#imdb#{settings["imdb"]}#{grp_id}')
],[
InlineKeyboardButton('Spelling Check', callback_data=f'setgs#spell_check#{settings["spell_check"]}#{grp_id}'),
InlineKeyboardButton('✅ Yes' if settings["spell_check"] else '❌ No', callback_data=f'setgs#spell_check#{settings["spell_check"]}#{grp_id}')
],[
InlineKeyboardButton('Auto Delete', callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{grp_id}'),
InlineKeyboardButton(f'{get_readable_time(DELETE_TIME)}' if settings["auto_delete"] else '❌ No', callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{grp_id}')
],[
InlineKeyboardButton('Welcome', callback_data=f'setgs#welcome#{settings["welcome"]}#{grp_id}',),
InlineKeyboardButton('✅ Yes' if settings["welcome"] else '❌ No', callback_data=f'setgs#welcome#{settings["welcome"]}#{grp_id}'),
],[
InlineKeyboardButton('Shortlink', callback_data=f'setgs#shortlink#{settings["shortlink"]}#{grp_id}'),
InlineKeyboardButton('✅ Yes' if settings["shortlink"] else '❌ No', callback_data=f'setgs#shortlink#{settings["shortlink"]}#{grp_id}'),
],[
InlineKeyboardButton('Result Page', callback_data=f'setgs#links#{settings["links"]}#{str(grp_id)}'),
InlineKeyboardButton('⛓ Link' if settings["links"] else '🧲 Button', callback_data=f'setgs#links#{settings["links"]}#{str(grp_id)}')
],[
InlineKeyboardButton('Fsub', callback_data=f'setgs#is_fsub#{settings.get("is_fsub", IS_FSUB)}#{str(grp_id)}'),
InlineKeyboardButton('✅ On' if settings.get("is_fsub", IS_FSUB) else '❌ Off', callback_data=f'setgs#is_fsub#{settings.get("is_fsub", IS_FSUB)}#{str(grp_id)}')
],[
InlineKeyboardButton('Stream', callback_data=f'setgs#is_stream#{settings.get("is_stream", IS_STREAM)}#{str(grp_id)}'),
InlineKeyboardButton('✅ On' if settings.get("is_stream", IS_STREAM) else '❌ Off', callback_data=f'setgs#is_stream#{settings.get("is_stream", IS_STREAM)}#{str(grp_id)}')
],[
InlineKeyboardButton('❌ Close ❌', callback_data='close_data')
]]
await message.reply_text(
text=f"Change your settings for <b>'{message.chat.title}'</b> as your wish. ⚙",
reply_markup=InlineKeyboardMarkup(buttons),
parse_mode=enums.ParseMode.HTML
)
else:
await message.reply_text('Something went wrong!')
@Client.on_message(filters.command('set_template'))
async def save_template(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
try:
template = message.text.split(" ", 1)[1]
except:
return await message.reply_text("Command Incomplete!")
await save_group_settings(grp_id, 'template', template)
await message.reply_text(f"Successfully changed template for {title} to\n\n{template}")
@Client.on_message(filters.command('set_caption'))
async def save_caption(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
try:
caption = message.text.split(" ", 1)[1]
except:
return await message.reply_text("Command Incomplete!")
await save_group_settings(grp_id, 'caption', caption)
await message.reply_text(f"Successfully changed caption for {title} to\n\n{caption}")
@Client.on_message(filters.command('set_shortlink'))
async def save_shortlink(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
try:
_, url, api = message.text.split(" ", 2)
except:
return await message.reply_text("<b>Command Incomplete:-\n\ngive me a shortlink & api along with the command...\n\nEx:- <code>/shortlink mdisklink.link 5843c3cc645f5077b2200a2c77e0344879880b3e</code>")
try:
await get_shortlink(url, api, f'https://t.me/{temp.U_NAME}')
except:
return await message.reply_text("Your shortlink API or URL invalid, Please Check again!")
await save_group_settings(grp_id, 'url', url)
await save_group_settings(grp_id, 'api', api)
await message.reply_text(f"Successfully changed shortlink for {title} to\n\nURL - {url}\nAPI - {api}")
@Client.on_message(filters.command('get_custom_settings'))
async def get_custom_settings(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group...')
settings = await get_settings(grp_id)
text = f"""Custom settings for: {title}
Shortlink URL: {settings["url"]}
Shortlink API: {settings["api"]}
IMDb Template: {settings['template']}
File Caption: {settings['caption']}
Welcome Text: {settings['welcome_text']}
Tutorial Link: {settings['tutorial']}
Force Channels: {str(settings['fsub'])[1:-1] if settings['fsub'] else 'Not Set'}"""
btn = [[
InlineKeyboardButton(text="Close", callback_data="close_data")
]]
await message.reply_text(text, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=True)
@Client.on_message(filters.command('set_welcome'))
async def save_welcome(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
try:
welcome = message.text.split(" ", 1)[1]
except:
return await message.reply_text("Command Incomplete!")
await save_group_settings(grp_id, 'welcome_text', welcome)
await message.reply_text(f"Successfully changed welcome for {title} to\n\n{welcome}")
@Client.on_message(filters.command('delete'))
async def delete_file(bot, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
try:
query = message.text.split(" ", 1)[1]
except:
return await message.reply_text("Command Incomplete!\nUsage: /delete query")
msg = await message.reply_text('Searching...')
total, files = await delete_files(query)
if int(total) == 0:
return await msg.edit('Not have files in your query')
btn = [[
InlineKeyboardButton("YES", callback_data=f"delete_{query}")
],[
InlineKeyboardButton("CLOSE", callback_data="close_data")
]]
await msg.edit(f"Total {total} files found in your query {query}.\n\nDo you want to delete?", reply_markup=InlineKeyboardMarkup(btn))
@Client.on_message(filters.command('delete_all'))
async def delete_all_index(bot, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
btn = [[
InlineKeyboardButton(text="YES", callback_data="delete_all")
],[
InlineKeyboardButton(text="CLOSE", callback_data="close_data")
]]
files = await Media.count_documents()
if int(files) == 0:
return await message.reply_text('Not have files to delete')
await message.reply_text(f'Total {files} files have.\nDo you want to delete all?', reply_markup=InlineKeyboardMarkup(btn))
@Client.on_message(filters.command('set_tutorial'))
async def set_tutorial(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
try:
tutorial = message.text.split(" ", 1)[1]
except:
return await message.reply_text("Command Incomplete!")
await save_group_settings(grp_id, 'tutorial', tutorial)
await message.reply_text(f"Successfully changed tutorial for {title} to\n\n{tutorial}")
@Client.on_message(filters.command('set_fsub'))
async def set_fsub(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply("<b>You are Anonymous admin you can't use this command !</b>")
chat_type = message.chat.type
if chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
return await message.reply_text("Use this command in group.")
grp_id = message.chat.id
title = message.chat.title
if not await is_check_admin(client, grp_id, message.from_user.id):
return await message.reply_text('You not admin in this group.')
vp = message.text.split(" ", 1)[1]
if vp.lower() in ["Off", "off", "False", "false", "Turn Off", "turn off"]:
await save_group_settings(grp_id, 'is_fsub', False)
return await message.reply_text("Successfully Turned Off !")
elif vp.lower() in ["On", "on", "True", "true", "Turn On", "turn on"]:
await save_group_settings(grp_id, 'is_fsub', True)
return await message.reply_text("Successfully Turned On !")
try:
ids = message.text.split(" ", 1)[1]
fsub_ids = list(map(int, ids.split()))
except IndexError:
return await message.reply_text("Command Incomplete!\n\nCan multiple channel add separate by spaces. Like: /set_fsub id1 id2 id3")
except ValueError:
return await message.reply_text('Make sure ids is integer.')
channels = "Channels:\n"
for id in fsub_ids:
try:
chat = await client.get_chat(id)
except Exception as e:
return await message.reply_text(f"{id} is invalid!\nMake sure this bot admin in that channel.\n\nError - {e}")
if chat.type != enums.ChatType.CHANNEL:
return await message.reply_text(f"{id} is not channel.")
channels += f'{chat.title}\n'
await save_group_settings(grp_id, 'fsub', fsub_ids)
await message.reply_text(f"Successfully set force channels for {title} to\n\n{channels}")
@Client.on_message(filters.command('telegraph'))
async def telegraph(bot, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
reply_to_message = message.reply_to_message
if not reply_to_message:
return await message.reply('Reply to any photo or video.')
file = reply_to_message.photo or reply_to_message.video or None
if file is None:
return await message.reply('Invalid media.')
if file.file_size >= 5242880:
await message.reply_text(text="Send less than 5MB")
return
text = await message.reply_text(text="ᴘʀᴏᴄᴇssɪɴɢ....")
media = await reply_to_message.download()
try:
response = upload_file(media)
except Exception as e:
await text.edit_text(text=f"Error - {e}")
return
try:
os.remove(media)
except:
pass
await text.edit_text(f"<b>❤️ ʏᴏᴜʀ ᴛᴇʟᴇɢʀᴀᴘʜ ʟɪɴᴋ ᴄᴏᴍᴘʟᴇᴛᴇᴅ 👇</b>\n\n<code>https://telegra.ph/{response[0]}</code></b>")
@Client.on_message(filters.command('ping'))
async def ping(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
start_time = time.monotonic()
msg = await message.reply("👀")
end_time = time.monotonic()
await msg.edit(f'{round((end_time - start_time) * 1000)} ms')
@Client.on_message(filters.command("add_premium"))
async def give_premium_cmd_handler(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
if len(message.command) == 3:
user_id = int(message.command[1]) # Convert the user_id to integer
time = message.command[2]
seconds = await get_seconds(time)
if seconds > 0:
expiry_time = datetime.datetime.now() + datetime.timedelta(seconds=seconds)
user_data = {"id": user_id, "expiry_time": expiry_time}
await db.update_user(user_data) # Use the update_user method to update or insert user data
await message.reply_text("Premium access added to the user.")
await client.send_message(
chat_id=user_id,
text=f"<b>ᴘʀᴇᴍɪᴜᴍ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ᴀᴄᴄᴏᴜɴᴛ ꜰᴏʀ {time} ᴇɴᴊᴏʏ 😀\n</b>",
)
else:
await message.reply_text("Invalid time format. Please use '1day for days', '1hour for hours', or '1min for minutes', or '1month for months' or '1year for year'")
else:
await message.reply_text("<b>Usage: /add_premium user_id time \n\nExample /add_premium 1252789 10day \n\n(e.g. for time units '1day for days', '1hour for hours', or '1min for minutes', or '1month for months' or '1year for year')</b>")
@Client.on_message(filters.command("remove_premium"))
async def remove_premium_cmd_handler(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if user_id not in ADMINS:
await message.delete()
return
if len(message.command) == 2:
user_id = int(message.command[1]) # Convert the user_id to integer
time = "1s"
seconds = await get_seconds(time)
if seconds > 0:
expiry_time = datetime.datetime.now() + datetime.timedelta(seconds=seconds)
user_data = {"id": user_id, "expiry_time": expiry_time} # Using "id" instead of "user_id"
await db.update_user(user_data) # Use the update_user method to update or insert user data
await message.reply_text("Premium access removed to the user.")
await client.send_message(
chat_id=user_id,
text=f"<b>premium removed by admins \n\n Contact Admin if this is mistake \n\n 👮 Admin : {OWNER_USERNAME} \n</b>",
disable_web_page_preview=True
)
else:
await message.reply_text("Invalid time format.'")
else:
await message.reply_text("Usage: /remove_premium user_id")
@Client.on_message(filters.command("plan"))
async def plans_cmd_handler(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
btn = [
[InlineKeyboardButton("ꜱᴇɴᴅ ᴘᴀʏᴍᴇɴᴛ ʀᴇᴄᴇɪᴘᴛ 🧾", url=OWNER_USERNAME)],
[InlineKeyboardButton("⚠️ ᴄʟᴏsᴇ / ᴅᴇʟᴇᴛᴇ ⚠️", callback_data="close_data")]
]
reply_markup = InlineKeyboardMarkup(btn)
await message.reply_photo(
photo=PAYMENT_QR,
caption="**Pʀᴇᴍɪᴜᴍ Fᴇᴀᴛᴜʀᴇs 🎁\n\n☆ No Need To Verify\n☆ Ad Free Experience\n☆ Unlimited Movie And Series",
reply_markup=reply_markup
)
@Client.on_message(filters.command("myplan"))
async def check_plans_cmd(client, message):
try:
await message.react(emoji=random.choice(REACTIONS), big=True)
except:
await message.react(emoji="⚡️", big=True)
user_id = message.from_user.id
if await db.has_premium_access(user_id):
remaining_time = await db.check_remaining_uasge(user_id)
expiry_time = remaining_time + datetime.datetime.now()
await message.reply_text(f"**Your plans details are :\n\nRemaining Time : {remaining_time}\n\nExpirytime : {expiry_time}**")
else:
btn = [
[InlineKeyboardButton("ɢᴇᴛ ғʀᴇᴇ ᴛʀᴀɪʟ ғᴏʀ 𝟻 ᴍɪɴᴜᴛᴇꜱ ☺️", callback_data="get_trail")],
[InlineKeyboardButton("ʙᴜʏ sᴜʙsᴄʀɪᴘᴛɪᴏɴ : ʀᴇᴍᴏᴠᴇ ᴀᴅs", callback_data="buy_premium")],
[InlineKeyboardButton("⚠️ ᴄʟᴏsᴇ / ᴅᴇʟᴇᴛᴇ ⚠️", callback_data="close_data")]
]
reply_markup = InlineKeyboardMarkup(btn)
m=await message.reply_sticker("CAACAgIAAxkBAAIBTGVjQbHuhOiboQsDm35brLGyLQ28AAJ-GgACglXYSXgCrotQHjibHgQ")
await message.reply_text(f"**😢 You Don't Have Any Premium Subscription.\n\n Check Out Our Premium /plan**",reply_markup=reply_markup)
await asyncio.sleep(2)
await m.delete()
@Client.on_message(filters.private & filters.command("set_pm_search"))
async def set_pm_search(client, message):
user_id = message.from_user.id
bot_id = client.me.id
if user_id not in ADMINS:
await message.delete()
return
try:
option = (message.text).split(" ", 1)[1].lower()
except IndexError:
return await message.reply_text("<b>💔 Invalid option. Please send me 'on' or 'off' / 'true' or 'false' after the command.</b>")
if option in ['on', 'true']:
await db.update_pm_search_status(bot_id, enable=True)
await message.reply_text("<b>✅️ ᴘᴍ ꜱᴇᴀʀᴄʜ ᴇɴᴀʙʟᴇᴅ ꜰʀᴏᴍ ɴᴏᴡ ᴜꜱᴇʀꜱ ᴀʙʟᴇ ᴛᴏ ꜱᴇᴀʀᴄʜ ᴍᴏᴠɪᴇ ɪɴ ʙᴏᴛ ᴘᴍ.</b>")
elif option in ['off', 'false']:
await db.update_pm_search_status(bot_id, enable=False)
await message.reply_text("<b>❌️ ᴘᴍ ꜱᴇᴀʀᴄʜ ᴅɪꜱᴀʙʟᴇᴅ, ɴᴏ ᴏɴᴇ ᴜꜱᴇʀꜱ ᴀʙʟᴇ ᴛᴏ ꜱᴇᴀʀᴄʜ ᴍᴏᴠɪᴇ ɪɴ ʙᴏᴛ ᴘᴍ.</b>")
else:
await message.reply_text("<b>💔 Invalid option. Please send me 'on' or 'off' / 'true' or 'false' after the command.</b>")