kalanakt commited on
Commit
0ef9f3c
1 Parent(s): e9dd2b9

Upload 12 files

Browse files
plugins/banned.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyrogram import Client, filters
2
+ from utils import temp
3
+ from pyrogram.types import Message
4
+ from database.users_chats_db import db
5
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
6
+ from info import SUPPORT_CHAT
7
+ async def banned_users(_, client, message: Message):
8
+ return (
9
+ message.from_user is not None or not message.sender_chat
10
+ ) and message.from_user.id in temp.BANNED_USERS
11
+
12
+ banned_user = filters.create(banned_users)
13
+
14
+ async def disabled_chat(_, client, message: Message):
15
+ return message.chat.id in temp.BANNED_CHATS
16
+
17
+ disabled_group=filters.create(disabled_chat)
18
+
19
+
20
+ @Client.on_message(filters.private & banned_user & filters.incoming)
21
+ async def ban_reply(bot, message):
22
+ ban = await db.get_ban_status(message.from_user.id)
23
+ await message.reply(f'Sorry Dude, You are Banned to use Me. \nBan Reason: {ban["ban_reason"]}')
24
+
25
+ @Client.on_message(filters.group & disabled_group & filters.incoming)
26
+ async def grp_bd(bot, message):
27
+ buttons = [[
28
+ InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
29
+ ]]
30
+ reply_markup=InlineKeyboardMarkup(buttons)
31
+ vazha = await db.get_chat(message.chat.id)
32
+ k = await message.reply(
33
+ text=f"CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..\nReason : <code>{vazha['reason']}</code>.",
34
+ reply_markup=reply_markup)
35
+ try:
36
+ await k.pin()
37
+ except:
38
+ pass
39
+ await bot.leave_chat(message.chat.id)
plugins/broadcast.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from pyrogram import Client, filters
3
+ import datetime
4
+ import time
5
+ from database.users_chats_db import db
6
+ from info import ADMINS
7
+ from utils import broadcast_messages
8
+ import asyncio
9
+
10
+ @Client.on_message(filters.command("broadcast") & filters.user(ADMINS) & filters.reply)
11
+ # https://t.me/GetTGLink/4178
12
+ async def verupikkals(bot, message):
13
+ users = await db.get_all_users()
14
+ b_msg = message.reply_to_message
15
+ sts = await message.reply_text(
16
+ text='Broadcasting your messages...'
17
+ )
18
+ start_time = time.time()
19
+ total_users = await db.total_users_count()
20
+ done = 0
21
+ blocked = 0
22
+ deleted = 0
23
+ failed =0
24
+
25
+ success = 0
26
+ async for user in users:
27
+ pti, sh = await broadcast_messages(int(user['id']), b_msg)
28
+ if pti:
29
+ success += 1
30
+ elif pti == False:
31
+ if sh == "Blocked":
32
+ blocked+=1
33
+ elif sh == "Deleted":
34
+ deleted += 1
35
+ elif sh == "Error":
36
+ failed += 1
37
+ done += 1
38
+ await asyncio.sleep(2)
39
+ if not done % 20:
40
+ await sts.edit(f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
41
+ time_taken = datetime.timedelta(seconds=int(time.time()-start_time))
42
+ await sts.edit(f"Broadcast Completed:\nCompleted in {time_taken} seconds.\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
plugins/channel.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyrogram import Client, filters
2
+ from info import CHANNELS
3
+ from database.ia_filterdb import save_file
4
+
5
+ media_filter = filters.document | filters.video | filters.audio
6
+
7
+
8
+ @Client.on_message(filters.chat(CHANNELS) & media_filter)
9
+ async def media(bot, message):
10
+ """Media Handler"""
11
+ for file_type in ("document", "video", "audio"):
12
+ media = getattr(message, file_type, None)
13
+ if media is not None:
14
+ break
15
+ else:
16
+ return
17
+
18
+ media.file_type = file_type
19
+ media.caption = message.caption
20
+ await save_file(media)
plugins/commands.py ADDED
@@ -0,0 +1,1187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+ import random
4
+ import asyncio
5
+ from Script import script
6
+ from pyrogram import Client, filters, enums
7
+ from pyrogram.errors import ChatAdminRequired, FloodWait
8
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup
9
+ from database.admin_group import get_admingroup, remove_admingroup, add_admingroup
10
+ from database.ia_filterdb import Media, get_file_details, unpack_new_file_id
11
+ from database.users_chats_db import db
12
+ from info import CHANNELS, ADMINS, AUTH_CHANNEL, LOG_CHANNEL, PICS, BATCH_FILE_CAPTION, CUSTOM_FILE_CAPTION, PROTECT_CONTENT
13
+ from utils import get_settings, get_size, is_subscribed, save_group_settings, temp, send_more_files, gen_url, broadcast_messages, broadcast_notification, split_list
14
+ from database.connections_mdb import active_connection
15
+ from database.quickdb import remove_inst, get_ids, add_sent_files, get_verification, remove_verification, add_verification, count_sent_files, add_update_msg, remove_update_msg, get_update_msg
16
+ from database.tvseriesfilters import add_tvseries_filter, update_tvseries_filter, getlinks, find_tvseries_filter, remove_tvseries, find_tvseries_by_first
17
+ from database.notification import find_notification, remove_notification, update_notification, add_notification, find_allusers
18
+ import re
19
+ import json
20
+ import base64
21
+ import time
22
+ logger = logging.getLogger(__name__)
23
+
24
+ BATCH_FILES = {}
25
+
26
+
27
+ @Client.on_message((filters.command("start") | filters.regex('Start')) & filters.incoming)
28
+ async def start(client, message):
29
+ if message.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
30
+ buttons = [
31
+ [
32
+ InlineKeyboardButton('🤖 Updates', url='https://t.me/TMWAD')
33
+ ],
34
+ [
35
+ InlineKeyboardButton(
36
+ 'ℹ️ Help', url=f"https://t.me/{temp.U_NAME}?start=help"),
37
+ ]
38
+ ]
39
+ reply_markup = InlineKeyboardMarkup(buttons)
40
+ await message.reply(script.START_TXT.format(message.from_user.mention if message.from_user else message.chat.title, temp.U_NAME, temp.B_NAME), reply_markup=reply_markup)
41
+ # 😢 https://github.com/EvamariaTG/EvaMaria/blob/master/plugins/p_ttishow.py#L17 😬 wait a bit, before checking.
42
+ await asyncio.sleep(2)
43
+ if not await db.get_chat(message.chat.id):
44
+ total = await client.get_chat_members_count(message.chat.id)
45
+ await client.send_message(LOG_CHANNEL, script.LOG_TEXT_G.format(message.chat.title, message.chat.id, total, "Unknown"))
46
+ await db.add_chat(message.chat.id, message.chat.title)
47
+ return
48
+ if not await db.is_user_exist(message.from_user.id):
49
+ await db.add_user(message.from_user.id, message.from_user.first_name)
50
+ await client.send_message(LOG_CHANNEL, script.LOG_TEXT_P.format(message.from_user.id, message.from_user.mention))
51
+ if len(message.command) != 2:
52
+ buttons = [[
53
+ InlineKeyboardButton('➕ Add Me To Your Groups ➕',
54
+ url=f'http://t.me/{temp.U_NAME}?startgroup=true')
55
+ ], [
56
+ InlineKeyboardButton(
57
+ '🔍 Search', switch_inline_query_current_chat=''),
58
+ InlineKeyboardButton('🤖 Updates', url='https://t.me/TMWAD')
59
+ ], [
60
+ InlineKeyboardButton('ℹ️ Help', callback_data='help'),
61
+ InlineKeyboardButton('😊 About', callback_data='about')
62
+ ]]
63
+ reply_markup = InlineKeyboardMarkup(buttons)
64
+ await message.reply_photo(
65
+ photo=random.choice(PICS),
66
+ caption=script.START_TXT.format(
67
+ message.from_user.mention, temp.U_NAME, temp.B_NAME),
68
+ reply_markup=reply_markup,
69
+ )
70
+ return
71
+
72
+ user_stats = await get_verification(message.from_user.id)
73
+
74
+ if AUTH_CHANNEL and not await is_subscribed(client, message):
75
+ btn = [
76
+ [
77
+ InlineKeyboardButton(
78
+ "🤖 Join Updates Channel", url="https://t.me/TMWAD"
79
+ )
80
+ ]
81
+ ]
82
+
83
+ if message.command[1] != "subscribe":
84
+ try:
85
+ kk, file_id = message.command[1].split("_", 1)
86
+ pre = 'checksubp' if kk == 'filep' else 'checksub'
87
+ btn.append([InlineKeyboardButton(
88
+ " 🔄 Try Again", callback_data=f"{pre}#{file_id}")])
89
+ except IndexError:
90
+ btn.append([InlineKeyboardButton(
91
+ " 🔄 Try Again", url=f"https://t.me/{temp.U_NAME}/{message.command[1]}")])
92
+ except:
93
+ return
94
+
95
+ await client.send_message(
96
+ chat_id=message.from_user.id,
97
+ text="**Please Join My Updates Channel to use this Bot!**",
98
+ reply_markup=InlineKeyboardMarkup(btn)
99
+ )
100
+ return
101
+ if len(message.command) == 2 and message.command[1] in ["subscribe", "error", "okay", "help"]:
102
+ buttons = [[
103
+ InlineKeyboardButton('➕ Add Me To Your Groups ➕',
104
+ url=f'http://t.me/{temp.U_NAME}?startgroup=true')
105
+ ], [
106
+ InlineKeyboardButton(
107
+ '🔍 Search', switch_inline_query_current_chat=''),
108
+ InlineKeyboardButton('🤖 Updates', url='https://t.me/TMWAD')
109
+ ], [
110
+ InlineKeyboardButton('ℹ️ Help', callback_data='help'),
111
+ InlineKeyboardButton('😊 About', callback_data='about')
112
+ ]]
113
+ reply_markup = InlineKeyboardMarkup(buttons)
114
+ await message.reply_photo(
115
+ photo=random.choice(PICS),
116
+ caption=script.START_TXT.format(
117
+ message.from_user.mention, temp.U_NAME, temp.B_NAME),
118
+ reply_markup=reply_markup,
119
+
120
+ )
121
+ return
122
+
123
+ data = message.command[1]
124
+ try:
125
+ pre, file_id = data.split('_', 1)
126
+ except:
127
+ file_id = data
128
+ pre = ""
129
+
130
+ t = time.time()
131
+ await remove_verification(message.from_user.id)
132
+ file_id = data.split("-", 1)[1]
133
+ await add_verification(message.from_user.id, 'verified', file_id, t)
134
+
135
+ tt = time.localtime(t+43200)
136
+ current_time = time.strftime("%D %H:%M:%S", tt)
137
+ await message.reply(
138
+ text=f"""
139
+ <p>you'r verified Succusfully. access until {current_time}</p>
140
+ """
141
+ )
142
+ idstring = await get_ids(file_id)
143
+
144
+ if idstring:
145
+ await remove_inst(file_id)
146
+ idstring = idstring['links']
147
+ fileids = idstring.split("L_I_N_K")
148
+ sendmsglist = []
149
+ for file_id in fileids:
150
+ files_ = await get_file_details(file_id)
151
+ if not files_:
152
+ try:
153
+ msg = await client.send_cached_media(
154
+ chat_id=message.from_user.id,
155
+ file_id=file_id
156
+ )
157
+ filetype = msg.media
158
+ file = getattr(msg, filetype)
159
+ title = file.file_name
160
+ size = get_size(file.file_size)
161
+ f_caption = f"<code>{title}</code>"
162
+ if CUSTOM_FILE_CAPTION:
163
+ try:
164
+ f_caption = CUSTOM_FILE_CAPTION.format(
165
+ file_name='' if title is None else title, file_size='' if size is None else size, file_caption='')
166
+ except:
167
+ return
168
+ await msg.edit_caption(f_caption)
169
+ return
170
+ except:
171
+ pass
172
+ files = files_[0]
173
+ title = files.file_name
174
+ size = get_size(files.file_size)
175
+ f_caption = files.caption
176
+ if CUSTOM_FILE_CAPTION:
177
+ try:
178
+ f_caption = CUSTOM_FILE_CAPTION.format(
179
+ 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)
180
+ except Exception as e:
181
+ logger.exception(e)
182
+ f_caption = f_caption
183
+ if f_caption is None:
184
+ f_caption = f"{files.file_name}"
185
+ k = await client.send_cached_media(
186
+ chat_id=message.from_user.id,
187
+ file_id=file_id,
188
+ caption=f_caption,
189
+ )
190
+ sendmsglist.append(k)
191
+ await add_sent_files(message.from_user.id, file_id)
192
+
193
+ await asyncio.sleep(2)
194
+
195
+ await message.reply('𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖')
196
+ kk = await client.send_message(
197
+ chat_id=message.from_user.id,
198
+ text="""
199
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
200
+ """)
201
+
202
+ await asyncio.sleep(600)
203
+
204
+ for k in sendmsglist:
205
+ await k.delete()
206
+
207
+ sendmsglist = []
208
+
209
+ return await kk.delete()
210
+
211
+ files_ = await get_file_details(file_id)
212
+ if not files_:
213
+ try:
214
+ pre, file_id = ((base64.urlsafe_b64decode(
215
+ data + "=" * (-len(data) % 4))).decode("ascii")).split("_", 1)
216
+ msg = await client.send_cached_media(
217
+ chat_id=message.from_user.id,
218
+ file_id=file_id,
219
+ protect_content=True if pre == 'filep' else False,
220
+ )
221
+ filetype = msg.media
222
+ file = getattr(msg, filetype)
223
+ title = file.file_name
224
+ size = get_size(file.file_size)
225
+ f_caption = f"<code>{title}</code>"
226
+ if CUSTOM_FILE_CAPTION:
227
+ try:
228
+ f_caption = CUSTOM_FILE_CAPTION.format(
229
+ file_name='' if title is None else title, file_size='' if size is None else size, file_caption='')
230
+ except:
231
+ return
232
+ await msg.edit_caption(f_caption)
233
+ return
234
+ except:
235
+ pass
236
+ return await message.reply('No such file exist.')
237
+ files = files_[0]
238
+ title = files.file_name
239
+ size = get_size(files.file_size)
240
+ f_caption = files.caption
241
+ if CUSTOM_FILE_CAPTION:
242
+ try:
243
+ f_caption = CUSTOM_FILE_CAPTION.format(
244
+ 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)
245
+ except Exception as e:
246
+ logger.exception(e)
247
+ f_caption = f_caption
248
+ if f_caption is None:
249
+ f_caption = f"{files.file_name}"
250
+
251
+ k = await client.send_cached_media(
252
+ chat_id=message.from_user.id,
253
+ file_id=file_id,
254
+ caption=f_caption,
255
+ protect_content=True if pre == 'filep' else False,
256
+ )
257
+ sendmsglist = [k]
258
+ await add_sent_files(message.from_user.id, file_id)
259
+
260
+ files = await send_more_files(title)
261
+ if files:
262
+ for file in files[1:]:
263
+ k = await client.send_cached_media(
264
+ chat_id=message.from_user.id,
265
+ file_id=file.file_id,
266
+ caption=f"<code>{file.file_name}</code>",
267
+ protect_content=True if pre == 'filep' else False,
268
+ )
269
+ sendmsglist.append(k)
270
+ await add_sent_files(message.from_user.id, file.file_id)
271
+
272
+ await asyncio.sleep(2)
273
+
274
+ await message.reply("𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖 \n\n⭐Rate Me: <a href='https://t.me/tlgrmcbot?start=spaciousuniversebot-review'>Here</a>")
275
+ kk = await client.send_message(
276
+ chat_id=message.from_user.id,
277
+ text="""
278
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
279
+ """)
280
+
281
+ await asyncio.sleep(600)
282
+
283
+ for k in sendmsglist:
284
+ await k.delete()
285
+ sendmsglist = []
286
+
287
+ return await kk.delete()
288
+
289
+ user_stats = await get_verification(message.from_user.id)
290
+ if user_stats is None:
291
+ t = time.time()
292
+ await add_verification(message.from_user.id, 'unverified', file_id, t)
293
+ button = [[
294
+ InlineKeyboardButton(
295
+ '🔹 Verfiy 🔹', url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{data}'))
296
+ ]]
297
+ return await message.reply(
298
+ text="""
299
+ <p>you'r not verified today. verfied your self and get unlimited access</p>
300
+ <br>
301
+ <small><a href="kalanakt.github.io/projects/telegram/baesuzy/">How To Verify !</a></small>
302
+ """,
303
+ reply_markup=InlineKeyboardMarkup(button)
304
+ )
305
+ elif data.split("-", 1)[0] == "REAL":
306
+ file_id = data.split("-", 1)[1]
307
+ if (str(user_stats["stats"]) == 'unverified') and (str(user_stats["file"]) == file_id):
308
+ file_id = data.split("-", 1)[1]
309
+ t = time.time()
310
+ await remove_verification(message.from_user.id)
311
+ await add_verification(message.from_user.id, 'verified', file_id, t)
312
+ t = time.localtime(t+43200)
313
+ current_time = time.strftime("%D %H:%M:%S", t)
314
+ button = [[
315
+ InlineKeyboardButton(
316
+ 'Get Files', url=f'https://telegram.dog/SpaciousUniverseBot?start={file_id}')
317
+ ]]
318
+ return await message.reply(
319
+ text=f"""
320
+ <p>you'r verified Succusfully. access until {current_time}</p>
321
+ """,
322
+ reply_markup=InlineKeyboardMarkup(button)
323
+ )
324
+ elif data.split("-")[1] == "BATCH":
325
+ file_id = data.split("-", 2)[2]
326
+ t = time.time()
327
+ await remove_verification(message.from_user.id)
328
+ await add_verification(message.from_user.id, 'verified', file_id, t)
329
+ t = time.localtime(t+43200)
330
+ current_time = time.strftime("%D %H:%M:%S", t)
331
+ button = [[
332
+ InlineKeyboardButton(
333
+ 'Get Files', url=f'https://telegram.dog/SpaciousUniverseBot?start={file_id}')
334
+ ]]
335
+ return await message.reply(
336
+ text=f"""
337
+ <p>you'r verified Succusfully. access until {current_time}</p>
338
+ """,
339
+ reply_markup=InlineKeyboardMarkup(button)
340
+ )
341
+ else:
342
+ t = time.time()
343
+ await remove_verification(message.from_user.id)
344
+ await add_verification(message.from_user.id, 'unverified', file_id, t)
345
+ t = time.localtime(t+43200)
346
+ current_time = time.strftime("%D %H:%M:%S", t)
347
+ button = [[
348
+ InlineKeyboardButton(
349
+ '🔹 Verfiy 🔹', url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{data}'))
350
+ ]]
351
+ return await message.reply(
352
+ text="""
353
+ <p>you'r using my old messages. please verify first</p>
354
+ """,
355
+ reply_markup=InlineKeyboardMarkup(button)
356
+ )
357
+
358
+ elif (str(user_stats["stats"]) == 'unverified') and (str(user_stats["file"]) != file_id):
359
+ t = time.time()
360
+ await remove_verification(message.from_user.id)
361
+ await add_verification(message.from_user.id, 'unverified', file_id, t)
362
+ button = [[
363
+ InlineKeyboardButton(
364
+ '🔹 Verfiy 🔹', url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{data}'))
365
+ ]]
366
+ return await message.reply(
367
+ text="""
368
+ <p>you'r not verified today. verfied your self and get unlimited access</p>
369
+ <br>
370
+ <small><a href="kalanakt.github.io/projects/telegram/baesuzy/">How To Verify !</a></small>
371
+ """,
372
+ reply_markup=InlineKeyboardMarkup(button)
373
+ )
374
+
375
+ elif (time.time() - int(float(user_stats["updat_time"]))) > 43200:
376
+ t = time.time()
377
+ await remove_verification(message.from_user.id)
378
+ await add_verification(message.from_user.id, 'unverified', file_id, user_stats["updat_time"])
379
+ button = [[
380
+ InlineKeyboardButton(
381
+ '🔹 Verfiy 🔹', url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{data}'))
382
+ ]]
383
+ return await message.reply(
384
+ text="""
385
+ <p>Your Verification Time Is expired. please verify again</p>
386
+ <br>
387
+ <small><a href="kalanakt.github.io/projects/telegram/baesuzy/">How To Verify</a></small>
388
+ """,
389
+ reply_markup=InlineKeyboardMarkup(button)
390
+ )
391
+
392
+ elif str(user_stats["stats"]) == 'verified':
393
+ if data.split("-", 1)[0] == "BATCH":
394
+ sts = await message.reply("Please wait")
395
+ file_id = data.split("-", 1)[1]
396
+ msgs = BATCH_FILES.get(file_id)
397
+ sendmsglist = []
398
+ if not msgs:
399
+ file = await client.download_media(file_id)
400
+ try:
401
+ with open(file) as file_data:
402
+ msgs = json.load(file_data)
403
+ except:
404
+ await sts.edit("FAILED")
405
+ return await client.send_message(LOG_CHANNEL, "UNABLE TO OPEN FILE.")
406
+ os.remove(file)
407
+ BATCH_FILES[file_id] = msgs
408
+ for msg in msgs:
409
+ title = msg.get("title")
410
+ size = get_size(int(msg.get("size", 0)))
411
+ f_caption = msg.get("caption", "")
412
+ if BATCH_FILE_CAPTION:
413
+ try:
414
+ f_caption = BATCH_FILE_CAPTION.format(
415
+ 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)
416
+ except Exception as e:
417
+ logger.exception(e)
418
+ f_caption = f_caption
419
+ if f_caption is None:
420
+ f_caption = f"{title}"
421
+ try:
422
+ k = await client.send_cached_media(
423
+ chat_id=message.from_user.id,
424
+ file_id=msg.get("file_id"),
425
+ caption=f_caption,
426
+ protect_content=msg.get('protect', False),
427
+ )
428
+ sendmsglist.append(k)
429
+ await add_sent_files(message.from_user.id, msg.get("file_id"))
430
+
431
+ except FloodWait as e:
432
+ await asyncio.sleep(e.x)
433
+ logger.warning(f"Floodwait of {e.x} sec.")
434
+ k = await client.send_cached_media(
435
+ chat_id=message.from_user.id,
436
+ file_id=msg.get("file_id"),
437
+ caption=f_caption,
438
+ protect_content=msg.get('protect', False),
439
+ )
440
+ sendmsglist.append(k)
441
+ await add_sent_files(message.from_user.id, msg.get("file_id"))
442
+
443
+ except Exception as e:
444
+ logger.warning(e, exc_info=True)
445
+ continue
446
+ await asyncio.sleep(2)
447
+ await sts.delete()
448
+ await message.reply("𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖 \n\n⭐Rate Me: <a href='https://t.me/tlgrmcbot?start=spaciousuniversebot-review'>Here</a>")
449
+ kk = await client.send_message(
450
+ chat_id=message.from_user.id,
451
+ text="""
452
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
453
+ """)
454
+
455
+ await asyncio.sleep(600)
456
+
457
+ for k in sendmsglist:
458
+ await k.delete()
459
+ sendmsglist = []
460
+
461
+ return await kk.delete()
462
+
463
+ idstring = await get_ids(file_id)
464
+
465
+ if idstring:
466
+ await remove_inst(file_id)
467
+ idstring = idstring['links']
468
+ fileids = idstring.split("L_I_N_K")
469
+ sendmsglist = []
470
+ for file_id in fileids:
471
+ files_ = await get_file_details(file_id)
472
+ if not files_:
473
+ try:
474
+ msg = await client.send_cached_media(
475
+ chat_id=message.from_user.id,
476
+ file_id=file_id
477
+ )
478
+ filetype = msg.media
479
+ file = getattr(msg, filetype)
480
+ title = file.file_name
481
+ size = get_size(file.file_size)
482
+ f_caption = f"<code>{title}</code>"
483
+ if CUSTOM_FILE_CAPTION:
484
+ try:
485
+ f_caption = CUSTOM_FILE_CAPTION.format(
486
+ file_name='' if title is None else title, file_size='' if size is None else size, file_caption='')
487
+ except:
488
+ return
489
+ await msg.edit_caption(f_caption)
490
+ return
491
+ except:
492
+ pass
493
+ files = files_[0]
494
+ title = files.file_name
495
+ size = get_size(files.file_size)
496
+ f_caption = files.caption
497
+ if CUSTOM_FILE_CAPTION:
498
+ try:
499
+ f_caption = CUSTOM_FILE_CAPTION.format(
500
+ 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)
501
+ except Exception as e:
502
+ logger.exception(e)
503
+ f_caption = f_caption
504
+ if f_caption is None:
505
+ f_caption = f"{files.file_name}"
506
+ try:
507
+ k = await client.send_cached_media(
508
+ chat_id=message.from_user.id,
509
+ file_id=file_id,
510
+ caption=f_caption,
511
+ )
512
+ except FloodWait as e:
513
+ await asyncio.sleep(e.x)
514
+ logger.warning(f"Floodwait of {e.x} sec.")
515
+ k = await client.send_cached_media(
516
+ chat_id=message.from_user.id,
517
+ file_id=file_id,
518
+ caption=f_caption,
519
+ )
520
+ sendmsglist.append(k)
521
+ await add_sent_files(message.from_user.id, file_id)
522
+
523
+ await asyncio.sleep(2)
524
+
525
+ await message.reply('𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖')
526
+ kk = await client.send_message(
527
+ chat_id=message.from_user.id,
528
+ text="""
529
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
530
+ """)
531
+
532
+ await asyncio.sleep(600)
533
+
534
+ for k in sendmsglist:
535
+ await k.delete()
536
+
537
+ sendmsglist = []
538
+
539
+ return await kk.delete()
540
+
541
+ files_ = await get_file_details(file_id)
542
+ if not files_:
543
+ try:
544
+ pre, file_id = ((base64.urlsafe_b64decode(
545
+ data + "=" * (-len(data) % 4))).decode("ascii")).split("_", 1)
546
+ msg = await client.send_cached_media(
547
+ chat_id=message.from_user.id,
548
+ file_id=file_id,
549
+ protect_content=True if pre == 'filep' else False,
550
+ )
551
+ filetype = msg.media
552
+ file = getattr(msg, filetype)
553
+ title = file.file_name
554
+ size = get_size(file.file_size)
555
+ f_caption = f"<code>{title}</code>"
556
+ if CUSTOM_FILE_CAPTION:
557
+ try:
558
+ f_caption = CUSTOM_FILE_CAPTION.format(
559
+ file_name='' if title is None else title, file_size='' if size is None else size, file_caption='')
560
+ except:
561
+ return
562
+ await msg.edit_caption(f_caption)
563
+ return
564
+ except:
565
+ pass
566
+ return await message.reply('No such file exist.')
567
+ files = files_[0]
568
+ title = files.file_name
569
+ size = get_size(files.file_size)
570
+ f_caption = files.caption
571
+ if CUSTOM_FILE_CAPTION:
572
+ try:
573
+ f_caption = CUSTOM_FILE_CAPTION.format(
574
+ 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)
575
+ except Exception as e:
576
+ logger.exception(e)
577
+ f_caption = f_caption
578
+ if f_caption is None:
579
+ f_caption = f"{files.file_name}"
580
+
581
+ k = await client.send_cached_media(
582
+ chat_id=message.from_user.id,
583
+ file_id=file_id,
584
+ caption=f_caption,
585
+ protect_content=True if pre == 'filep' else False,
586
+ )
587
+ sendmsglist = [k]
588
+ await add_sent_files(message.from_user.id, file_id)
589
+
590
+ files = await send_more_files(title)
591
+ if files:
592
+ for file in files[1:]:
593
+ try:
594
+ k = await client.send_cached_media(
595
+ chat_id=message.from_user.id,
596
+ file_id=file.file_id,
597
+ caption=f"<code>{file.file_name}</code>",
598
+ protect_content=True if pre == 'filep' else False,
599
+ )
600
+ except FloodWait as e:
601
+ await asyncio.sleep(e.x)
602
+ logger.warning(f"Floodwait of {e.x} sec.")
603
+ k = await client.send_cached_media(
604
+ chat_id=message.from_user.id,
605
+ file_id=file.file_id,
606
+ caption=f"<code>{file.file_name}</code>",
607
+ protect_content=True if pre == 'filep' else False,
608
+ )
609
+
610
+ sendmsglist.append(k)
611
+ await add_sent_files(message.from_user.id, file.file_id)
612
+ await asyncio.sleep(2)
613
+
614
+ await message.reply("𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖 \n\n⭐Rate Me: <a href='https://t.me/tlgrmcbot?start=spaciousuniversebot-review'>Here</a>")
615
+ kk = await client.send_message(
616
+ chat_id=message.from_user.id,
617
+ text="""
618
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
619
+ """)
620
+
621
+ await asyncio.sleep(600)
622
+
623
+ for k in sendmsglist:
624
+ await k.delete()
625
+ sendmsglist = []
626
+
627
+ return await kk.delete()
628
+
629
+
630
+ @Client.on_message(filters.command("addseries") & filters.incoming & filters.user(ADMINS))
631
+ async def tvseries_adder(bot, message):
632
+ sts = await message.reply("Checking Your Request...")
633
+ if " " not in message.text:
634
+ return await message.reply("Use correct format.<code>/addseries (name of series without space) (language eng/hindi/tamil/span) (quility 480/ 720/ 1080) (tv series batch links without space , use commas)</code>\n\n\nExample <code>/addseries strangerthings eng 480 https://tinyurl.com/23smxlh3,https://tinyurl.com/2yq2ghfh,https://tinyurl.com/27d9xyww,https://tinyurl.com/259az578</code>.")
635
+ data = message.text.strip().split(" ")
636
+ try:
637
+ cmd, name, lang, quty, links = data
638
+ await add_tvseries_filter(name, lang, quty, links)
639
+ await message.reply("your series added")
640
+
641
+ except:
642
+ return await message.reply("May Be Error is you puts space between links: \nUse correct format.<code>/addseries (name of series without space) (language eng/hindi/tamil/span) (quility 480/ 720/ 1080) (tv series batch links without space , use commas)</code>\n\n\nExample <code>/addseries strangerthings eng 480 https://tinyurl.com/23smxlh3,https://tinyurl.com/2yq2ghfh,https://tinyurl.com/27d9xyww,https://tinyurl.com/259az578</code>.")
643
+ await sts.delete()
644
+
645
+
646
+ @Client.on_message(filters.command("updateseries") & filters.incoming & filters.user(ADMINS))
647
+ async def tvseries_updater(bot, message):
648
+ sts = await message.reply("Checking Your Request...")
649
+ if " " not in message.text:
650
+ return await message.reply("Use correct format.<code>/updateseries (name of series without space) (language eng/hindi/tamil/span) (quility 480/ 720/ 1080) (tv series batch links without space , use commas)</code>\n\n\nExample <code>/addseries strangerthings eng 480 https://tinyurl.com/23smxlh3,https://tinyurl.com/2yq2ghfh,https://tinyurl.com/27d9xyww,https://tinyurl.com/259az578</code>.")
651
+ data = message.text.strip().split(" ")
652
+ try:
653
+ cmd, name, lang, quty, links = data
654
+ await update_tvseries_filter(name, lang, quty, links)
655
+ await message.reply("your series added")
656
+
657
+ except:
658
+ return await message.reply("May Be Error is you puts space between links: \nUse correct format.<code>/addseries (name of series without space) (language eng/hindi/tamil/span) (quility 480/ 720/ 1080) (tv series batch links without space , use commas)</code>\n\n\nExample <code>/addseries strangerthings eng 480 https://tinyurl.com/23smxlh3,https://tinyurl.com/2yq2ghfh,https://tinyurl.com/27d9xyww,https://tinyurl.com/259az578</code>.")
659
+ await sts.delete()
660
+
661
+
662
+ @Client.on_message(filters.command("template") & filters.incoming)
663
+ async def add_template(bot, message):
664
+ sts = await message.reply("Checking Your Request...")
665
+ if " " not in message.text:
666
+ return await message.reply("Use correct format. <code>/template (group id) (custom template)</code>")
667
+ data = message.text.strip().split(" ", 2)
668
+ try:
669
+ cmd, groupid, template = data
670
+ user = await bot.get_chat_member(int(groupid), message.from_user.id)
671
+ if user.status == enums.ChatMemberStatus.OWNER or user.status == enums.ChatMemberStatus.ADMINISTRATOR:
672
+ await add_admingroup(groupid, template)
673
+ await message.reply("your template added ")
674
+ else:
675
+ await message.reply("sorry, you'r not admin on that group")
676
+
677
+ except Exception as e:
678
+ return await message.reply(f"Error : {e}.")
679
+ await sts.delete()
680
+
681
+
682
+ @Client.on_message(filters.command("viewtemp") & filters.incoming)
683
+ async def template_get(bot, message):
684
+ data = message.text.strip().split(" ")
685
+ cmd, groupid = data
686
+ k = await get_admingroup(int(groupid))
687
+ await message.reply(k)
688
+
689
+
690
+ @Client.on_message(filters.command("removetemplate") & filters.incoming)
691
+ async def template_remover(bot, message):
692
+ sts = await message.reply("Checking Your Request...")
693
+ if " " not in message.text:
694
+ return await message.reply("Use correct format.<code>/removetemplate (group id)")
695
+ data = message.text.strip().split(" ")
696
+ try:
697
+ cmd, name = data
698
+ user = await bot.get_chat_member(name, message.from_user.id)
699
+ if user.status == enums.ChatMemberStatus.OWNER or user.status == enums.ChatMemberStatus.ADMINISTRATOR:
700
+ await remove_admingroup(int(name))
701
+ await message.reply("your group template is removed")
702
+ else:
703
+ await message.reply("sorry, you'r not admin on that group")
704
+
705
+ except:
706
+ return await message.reply("Not Found.")
707
+ await sts.delete()
708
+
709
+
710
+ @Client.on_message(filters.command("removeseries") & filters.incoming & filters.user(ADMINS))
711
+ async def tvseries_remover(bot, message):
712
+ sts = await message.reply("Checking Your Request...")
713
+ if " " not in message.text:
714
+ return await message.reply("Use correct format.<code>/removeseries (name of series without space)")
715
+ data = message.text.strip().split(" ")
716
+ try:
717
+ cmd, name = data
718
+ await remove_tvseries(name)
719
+ await message.reply("your series removed")
720
+
721
+ except:
722
+ return await message.reply("Not Found.")
723
+ await sts.delete()
724
+
725
+
726
+ @Client.on_message(filters.command("alltvs") & filters.incoming)
727
+ async def tvseries_get(bot, message):
728
+ k = await getlinks()
729
+ await message.reply(k)
730
+
731
+
732
+ @Client.on_message(filters.command('channel') & filters.user(ADMINS))
733
+ async def channel_info(bot, message):
734
+
735
+ """Send basic information of channel"""
736
+ if isinstance(CHANNELS, (int, str)):
737
+ channels = [CHANNELS]
738
+ elif isinstance(CHANNELS, list):
739
+ channels = CHANNELS
740
+ else:
741
+ raise ValueError("Unexpected type of CHANNELS")
742
+
743
+ text = '📑 **Indexed channels/groups**\n'
744
+ for channel in channels:
745
+ chat = await bot.get_chat(channel)
746
+ if chat.username:
747
+ text += '\n@' + chat.username
748
+ else:
749
+ text += '\n' + chat.title or chat.first_name
750
+
751
+ text += f'\n\n**Total:** {len(CHANNELS)}'
752
+
753
+ if len(text) < 4096:
754
+ await message.reply(text)
755
+ else:
756
+ file = 'Indexed channels.txt'
757
+ with open(file, 'w') as f:
758
+ f.write(text)
759
+ await message.reply_document(file)
760
+ os.remove(file)
761
+
762
+
763
+ @Client.on_message(filters.command('dev') & filters.user(ADMINS))
764
+ async def devve(bot, message):
765
+ try:
766
+ user_stats = await get_verification(message.from_user.id)
767
+ await message.reply_text(user_stats)
768
+ except Exception as e:
769
+ await message.reply(str(e))
770
+
771
+
772
+ @Client.on_message((filters.command('notification') | filters.regex('Notification')) & filters.incoming)
773
+ async def get_notification(bot, message):
774
+ await message.reply_text(
775
+ 'Get Movies/ Tv series On realse Time 〽. Turned on notifications, you can change anytime',
776
+ reply_markup=InlineKeyboardMarkup(
777
+ [
778
+ [
779
+ InlineKeyboardButton(
780
+ text="On 🔛", callback_data="notification_on"
781
+ ),
782
+ InlineKeyboardButton(
783
+ text="Off 📴", callback_data="notification_off"
784
+ )
785
+ ]
786
+ ]
787
+ ),
788
+ quote=True,
789
+ )
790
+
791
+
792
+ @Client.on_callback_query(filters.regex(r'^notification_on'))
793
+ async def notification_on(bot, query):
794
+ user_id = query.from_user.id
795
+ userStatus = await find_notification(user_id)
796
+ if userStatus is None:
797
+ await add_notification(user_id, 'on')
798
+ else:
799
+ await update_notification(user_id, 'on')
800
+
801
+ return await query.message.edit('Succesfully Turned on notifications 💌. use /notification to change')
802
+
803
+
804
+ @Client.on_callback_query(filters.regex(r'^notification_off'))
805
+ async def notification_off(bot, query):
806
+ user_id = query.from_user.id
807
+ userStatus = await find_notification(user_id)
808
+ if userStatus is None:
809
+ await add_notification(user_id, 'off')
810
+ else:
811
+ await update_notification(user_id, 'off')
812
+ return await query.message.edit('Succesfully Turned off notifications 💌. use /notification to change')
813
+
814
+
815
+ @Client.on_message(filters.command('sendnoti') & filters.user(ADMINS))
816
+ async def sendnotifications(bot, message):
817
+ usersIdList = await find_allusers()
818
+ b_msg = message.reply_to_message
819
+ if not b_msg:
820
+ return await message.reply(f"Reply to message")
821
+ count = 0
822
+ msg = await message.reply("Processing...⏳", quote=True)
823
+ for usersId in usersIdList:
824
+ await broadcast_notification(int(usersId), b_msg)
825
+ await asyncio.sleep(2)
826
+ count += 1
827
+
828
+ await msg.delete()
829
+ return await message.reply(f"Succuesfully sended to {count} users")
830
+
831
+
832
+ @Client.on_message(filters.command('tmwad') & filters.user(ADMINS))
833
+ async def tmwad_update(bot, message):
834
+ updates = await get_update_msg()
835
+ if updates is not None:
836
+ await remove_update_msg()
837
+ prev_day_total_users = updates["totalUsers"]
838
+ prev_day_total_files = updates["files"]
839
+
840
+ else:
841
+ return
842
+
843
+ todaySentFiles = await count_sent_files()
844
+ total_users = await db.total_users_count()
845
+ files = await Media.count_documents()
846
+
847
+ todayUsers = int(total_users) - int(prev_day_total_users)
848
+ todayFiles = files - prev_day_total_files
849
+ t = time.localtime()
850
+ current_time = time.strftime("%D %H:%M:%S", t)
851
+
852
+ await add_update_msg(total_users, files)
853
+
854
+ try:
855
+ await bot.edit_message_text(
856
+ chat_id=str('TMWAD'),
857
+ message_id=int(49),
858
+ text=script.POST_TEXT.format(
859
+ todaySentFiles, todayUsers, todayFiles, total_users, files, current_time)
860
+ )
861
+ return await message.reply("Update Succusfully on @TMWAD")
862
+ except:
863
+ logger.exception('Some error occured!', exc_info=True)
864
+
865
+
866
+ @Client.on_message(filters.command('logs') & filters.user(ADMINS))
867
+ async def log_file(bot, message):
868
+ """Send log file"""
869
+ try:
870
+ await message.reply_document('TelegramBot.log')
871
+ except Exception as e:
872
+ await message.reply(str(e))
873
+
874
+
875
+ @Client.on_message(filters.command('delete') & filters.user(ADMINS))
876
+ async def delete(bot, message):
877
+ """Delete file from database"""
878
+ reply = message.reply_to_message
879
+ if reply and reply.media:
880
+ msg = await message.reply("Processing...⏳", quote=True)
881
+ else:
882
+ await message.reply('Reply to file with /delete which you want to delete', quote=True)
883
+ return
884
+
885
+ for file_type in ("document", "video", "audio"):
886
+ media = getattr(reply, file_type, None)
887
+ if media is not None:
888
+ break
889
+ else:
890
+ await msg.edit('This is not supported file format')
891
+ return
892
+
893
+ file_id, file_ref = unpack_new_file_id(media.file_id)
894
+
895
+ result = await Media.collection.delete_one({
896
+ '_id': file_id,
897
+ })
898
+ if result.deleted_count:
899
+ await msg.edit('File is successfully deleted from database')
900
+ else:
901
+ file_name = re.sub(r"(_|\-|\.|\+)", " ", str(media.file_name))
902
+ result = await Media.collection.delete_many({
903
+ 'file_name': file_name,
904
+ 'file_size': media.file_size,
905
+ 'mime_type': media.mime_type
906
+ })
907
+ if result.deleted_count:
908
+ await msg.edit('File is successfully deleted from database')
909
+ else:
910
+ # files indexed before https://github.com/EvamariaTG/EvaMaria/commit/f3d2a1bcb155faf44178e5d7a685a1b533e714bf#diff-86b613edf1748372103e94cacff3b578b36b698ef9c16817bb98fe9ef22fb669R39
911
+ # have original file name.
912
+ result = await Media.collection.delete_many({
913
+ 'file_name': media.file_name,
914
+ 'file_size': media.file_size,
915
+ 'mime_type': media.mime_type
916
+ })
917
+ if result.deleted_count:
918
+ await msg.edit('File is successfully deleted from database')
919
+ else:
920
+ await msg.edit('File not found in database')
921
+
922
+
923
+ @Client.on_message(filters.command('deleteall') & filters.user(ADMINS))
924
+ async def delete_all_index(bot, message):
925
+ await message.reply_text(
926
+ 'This will delete all indexed files.\nDo you want to continue??',
927
+ reply_markup=InlineKeyboardMarkup(
928
+ [
929
+ [
930
+ InlineKeyboardButton(
931
+ text="YES", callback_data="autofilter_delete"
932
+ )
933
+ ],
934
+ [
935
+ InlineKeyboardButton(
936
+ text="CANCEL", callback_data="close_data"
937
+ )
938
+ ],
939
+ ]
940
+ ),
941
+ quote=True,
942
+ )
943
+
944
+
945
+ @Client.on_callback_query(filters.regex(r'^autofilter_delete'))
946
+ async def delete_all_index_confirm(bot, message):
947
+ await Media.collection.drop()
948
+ await message.answer('Piracy Is Crime')
949
+ await message.message.edit('Succesfully Deleted All The Indexed Files.')
950
+
951
+
952
+ @Client.on_message(filters.regex('^[A-Z0-9]*$') & filters.private & filters.incoming)
953
+ async def A2Z_tvseries(bot, update):
954
+ listD = await find_tvseries_by_first(update.text.lower())
955
+ Tvserieslist = [series["name"] for series in listD]
956
+ Tvserieslist = list(dict.fromkeys(Tvserieslist))
957
+ Tvserieslist.append("Back↩")
958
+ buttonz = ReplyKeyboardMarkup(split_list(
959
+ Tvserieslist, 3), resize_keyboard=True)
960
+ return await bot.send_message(
961
+ chat_id=update.chat.id,
962
+ text="Select Tv Series Name | if not found please request in @TMWAD",
963
+ disable_web_page_preview=True,
964
+ reply_markup=buttonz,
965
+ reply_to_message_id=update.id
966
+ )
967
+
968
+
969
+ # @Client.on_message(filters.regex('^[A-Za-z0-9]*$') & filters.private & filters.incoming)
970
+ # async def A2z_tvseries(bot, update):
971
+ # name = update.text.lower()
972
+ # if "-|-" in name:
973
+ # series = name.split("-|-", 1)[0]
974
+ # quality = name.split("-|-", 1)[1]
975
+ # listD = await find_tvseries_filter(series)
976
+ # Tvserieslist = [f"{name}-|-{series['quality']}" for series in listD]
977
+
978
+ # listD = await find_tvseries_filter(name)
979
+ # if listD is None:
980
+ # return
981
+ # Tvserieslist = [f"{name}-|-{series['quality']}" for series in listD]
982
+ # Tvserieslist.append("Back↩")
983
+ # buttonz = ReplyKeyboardMarkup(split_list(
984
+ # Tvserieslist, 3), resize_keyboard=True)
985
+ # return await bot.send_message(
986
+ # chat_id=update.chat.id,
987
+ # text="Select Tv Series Qulity | if not found please request in @TMWAD",
988
+ # disable_web_page_preview=True,
989
+ # reply_markup=buttonz,
990
+ # reply_to_message_id=update.id
991
+ # )
992
+
993
+
994
+ @Client.on_message((filters.command('tvseries') | filters.regex('Tv▫Series🔷') | filters.regex("Back↩")) & filters.private)
995
+ async def tvseries(bot, update):
996
+ buttonz = ReplyKeyboardMarkup(
997
+ [
998
+ ["A", "B", "C", "E", "F", "G"],
999
+ ["H", "I", "J", "K", "L", "M"],
1000
+ ["N", "O", "P", "Q", "R", "S"],
1001
+ ["T", "U", "V", "W", "X", "Y"],
1002
+ ["Z", "1-9", "Home↩"]
1003
+ ],
1004
+ resize_keyboard=True
1005
+ )
1006
+ await bot.send_message(
1007
+ chat_id=update.chat.id,
1008
+ text="Selecet First leter of tv series",
1009
+ disable_web_page_preview=True,
1010
+ reply_markup=buttonz,
1011
+ reply_to_message_id=update.id
1012
+ )
1013
+
1014
+
1015
+ @Client.on_message(filters.regex('Home↩') & filters.private)
1016
+ async def homeseries(bot, update):
1017
+ buttonz = ReplyKeyboardMarkup(
1018
+ [
1019
+ ["Tv▫Series🔷"],
1020
+ ["Start", "Notification"]
1021
+
1022
+ ],
1023
+ resize_keyboard=True
1024
+ )
1025
+ await bot.send_message(
1026
+ chat_id=update.chat.id,
1027
+ text="Selecet First leter of tv series",
1028
+ disable_web_page_preview=True,
1029
+ reply_markup=buttonz,
1030
+ reply_to_message_id=update.id
1031
+ )
1032
+
1033
+
1034
+ @Client.on_message(filters.command('settings'))
1035
+ async def settings(client, message):
1036
+ userid = message.from_user.id if message.from_user else None
1037
+ if not userid:
1038
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
1039
+ chat_type = message.chat.type
1040
+
1041
+ if chat_type == "private":
1042
+ grpid = await active_connection(str(userid))
1043
+ if grpid is not None:
1044
+ grp_id = grpid
1045
+ try:
1046
+ chat = await client.get_chat(grpid)
1047
+ title = chat.title
1048
+ except:
1049
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
1050
+ return
1051
+ else:
1052
+ await message.reply_text("I'm not connected to any groups!", quote=True)
1053
+ return
1054
+
1055
+ elif chat_type in ["group", "supergroup"]:
1056
+ grp_id = message.chat.id
1057
+ title = message.chat.title
1058
+
1059
+ else:
1060
+ return
1061
+
1062
+ st = await client.get_chat_member(grp_id, userid)
1063
+ if (
1064
+ st.status != "administrator"
1065
+ and st.status != "creator"
1066
+ and str(userid) not in ADMINS
1067
+ ):
1068
+ return
1069
+
1070
+ settings = await get_settings(grp_id)
1071
+
1072
+ if settings is not None:
1073
+ buttons = [
1074
+ [
1075
+ InlineKeyboardButton(
1076
+ 'Filter Button',
1077
+ callback_data=f'setgs#button#{settings["button"]}#{grp_id}',
1078
+ ),
1079
+ InlineKeyboardButton(
1080
+ 'Single' if settings["button"] else 'Double',
1081
+ callback_data=f'setgs#button#{settings["button"]}#{grp_id}',
1082
+ ),
1083
+ ],
1084
+ [
1085
+ InlineKeyboardButton(
1086
+ 'Bot PM',
1087
+ callback_data=f'setgs#botpm#{settings["botpm"]}#{grp_id}',
1088
+ ),
1089
+ InlineKeyboardButton(
1090
+ '✅ Yes' if settings["botpm"] else '❌ No',
1091
+ callback_data=f'setgs#botpm#{settings["botpm"]}#{grp_id}',
1092
+ ),
1093
+ ],
1094
+ [
1095
+ InlineKeyboardButton(
1096
+ 'File Secure',
1097
+ callback_data=f'setgs#file_secure#{settings["file_secure"]}#{grp_id}',
1098
+ ),
1099
+ InlineKeyboardButton(
1100
+ '✅ Yes' if settings["file_secure"] else '❌ No',
1101
+ callback_data=f'setgs#file_secure#{settings["file_secure"]}#{grp_id}',
1102
+ ),
1103
+ ],
1104
+ [
1105
+ InlineKeyboardButton(
1106
+ 'IMDB',
1107
+ callback_data=f'setgs#imdb#{settings["imdb"]}#{grp_id}',
1108
+ ),
1109
+ InlineKeyboardButton(
1110
+ '✅ Yes' if settings["imdb"] else '❌ No',
1111
+ callback_data=f'setgs#imdb#{settings["imdb"]}#{grp_id}',
1112
+ ),
1113
+ ],
1114
+ [
1115
+ InlineKeyboardButton(
1116
+ 'Spell Check',
1117
+ callback_data=f'setgs#spell_check#{settings["spell_check"]}#{grp_id}',
1118
+ ),
1119
+ InlineKeyboardButton(
1120
+ '✅ Yes' if settings["spell_check"] else '❌ No',
1121
+ callback_data=f'setgs#spell_check#{settings["spell_check"]}#{grp_id}',
1122
+ ),
1123
+ ],
1124
+ [
1125
+ InlineKeyboardButton(
1126
+ 'Welcome',
1127
+ callback_data=f'setgs#welcome#{settings["welcome"]}#{grp_id}',
1128
+ ),
1129
+ InlineKeyboardButton(
1130
+ '✅ Yes' if settings["welcome"] else '❌ No',
1131
+ callback_data=f'setgs#welcome#{settings["welcome"]}#{grp_id}',
1132
+ ),
1133
+ ],
1134
+ ]
1135
+
1136
+ reply_markup = InlineKeyboardMarkup(buttons)
1137
+
1138
+ await message.reply_text(
1139
+ text=f"<b>Change Your Settings for {title} As Your Wish ⚙</b>",
1140
+ reply_markup=reply_markup,
1141
+ disable_web_page_preview=True,
1142
+ reply_to_message_id=message.id
1143
+ )
1144
+
1145
+
1146
+ @Client.on_message(filters.command('set_template'))
1147
+ async def save_template(client, message):
1148
+ sts = await message.reply("Checking template")
1149
+ userid = message.from_user.id if message.from_user else None
1150
+ if not userid:
1151
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
1152
+ chat_type = message.chat.type
1153
+
1154
+ if chat_type == "private":
1155
+ grpid = await active_connection(str(userid))
1156
+ if grpid is not None:
1157
+ grp_id = grpid
1158
+ try:
1159
+ chat = await client.get_chat(grpid)
1160
+ title = chat.title
1161
+ except:
1162
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
1163
+ return
1164
+ else:
1165
+ await message.reply_text("I'm not connected to any groups!", quote=True)
1166
+ return
1167
+
1168
+ elif chat_type in ["group", "supergroup"]:
1169
+ grp_id = message.chat.id
1170
+ title = message.chat.title
1171
+
1172
+ else:
1173
+ return
1174
+
1175
+ st = await client.get_chat_member(grp_id, userid)
1176
+ if (
1177
+ st.status != "administrator"
1178
+ and st.status != "creator"
1179
+ and str(userid) not in ADMINS
1180
+ ):
1181
+ return
1182
+
1183
+ if len(message.command) < 2:
1184
+ return await sts.edit("No Input!!")
1185
+ template = message.text.split(" ", 1)[1]
1186
+ await save_group_settings(grp_id, 'template', template)
1187
+ await sts.edit(f"Successfully changed template for {title} to\n\n{template}")
plugins/connection.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyrogram import filters, Client
2
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
3
+ from database.connections_mdb import add_connection, all_connections, if_active, delete_connection
4
+ from info import ADMINS
5
+ import logging
6
+
7
+ logger = logging.getLogger(__name__)
8
+ logger.setLevel(logging.ERROR)
9
+
10
+
11
+ @Client.on_message((filters.private | filters.group) & filters.command('connect'))
12
+ async def addconnection(client, message):
13
+ userid = message.from_user.id if message.from_user else None
14
+ if not userid:
15
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
16
+ chat_type = message.chat.type
17
+
18
+ if chat_type == "private":
19
+ try:
20
+ cmd, group_id = message.text.split(" ", 1)
21
+ except:
22
+ await message.reply_text(
23
+ "<b>Enter in correct format!</b>\n\n"
24
+ "<code>/connect groupid</code>\n\n"
25
+ "<i>Get your Group id by adding this bot to your group and use <code>/id</code></i>",
26
+ quote=True
27
+ )
28
+ return
29
+
30
+ elif chat_type in ["group", "supergroup"]:
31
+ group_id = message.chat.id
32
+
33
+ try:
34
+ group_id = message.chat.id
35
+ st = await client.get_chat_member(group_id, userid)
36
+ if (
37
+ st.status != "administrator"
38
+ and st.status != "creator"
39
+ and userid not in ADMINS
40
+ ):
41
+ await message.reply_text("You should be an admin in Given group!", quote=True)
42
+ return
43
+ except Exception as e:
44
+ logger.exception(e)
45
+ await message.reply_text(
46
+ "Invalid Group ID!\n\nIf correct, Make sure I'm present in your group!!",
47
+ quote=True,
48
+ )
49
+
50
+ return
51
+ try:
52
+ st = await client.get_chat_member(group_id, "me")
53
+ if st.status == "administrator":
54
+ ttl = await client.get_chat(group_id)
55
+ title = ttl.title
56
+
57
+ addcon = await add_connection(str(group_id), str(userid))
58
+ if addcon:
59
+ await message.reply_text(
60
+ f"Successfully connected to **{title}**\nNow manage your group from my pm !",
61
+ quote=True,
62
+ parse_mode="md"
63
+ )
64
+ if chat_type in ["group", "supergroup"]:
65
+ await client.send_message(
66
+ userid,
67
+ f"Connected to **{title}** !",
68
+ parse_mode="md"
69
+ )
70
+ else:
71
+ await message.reply_text(
72
+ "You're already connected to this chat!",
73
+ quote=True
74
+ )
75
+ else:
76
+ await message.reply_text("Add me as an admin in group", quote=True)
77
+ except Exception as e:
78
+ logger.exception(e)
79
+ await message.reply_text('Some error occurred! Try again later.', quote=True)
80
+ return
81
+
82
+
83
+ @Client.on_message((filters.private | filters.group) & filters.command('disconnect'))
84
+ async def deleteconnection(client, message):
85
+ userid = message.from_user.id if message.from_user else None
86
+ if not userid:
87
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
88
+ chat_type = message.chat.type
89
+
90
+ if chat_type == "private":
91
+ await message.reply_text("Run /connections to view or disconnect from groups!", quote=True)
92
+
93
+ elif chat_type in ["group", "supergroup"]:
94
+ group_id = message.chat.id
95
+
96
+ st = await client.get_chat_member(group_id, userid)
97
+ if (
98
+ st.status != "administrator"
99
+ and st.status != "creator"
100
+ and str(userid) not in ADMINS
101
+ ):
102
+ return
103
+
104
+ delcon = await delete_connection(str(userid), str(group_id))
105
+ if delcon:
106
+ await message.reply_text("Successfully disconnected from this chat", quote=True)
107
+ else:
108
+ await message.reply_text("This chat isn't connected to me!\nDo /connect to connect.", quote=True)
109
+
110
+
111
+ @Client.on_message(filters.private & filters.command(["connections"]))
112
+ async def connections(client, message):
113
+ userid = message.from_user.id
114
+
115
+ groupids = await all_connections(str(userid))
116
+ if groupids is None:
117
+ await message.reply_text(
118
+ "There are no active connections!! Connect to some groups first.",
119
+ quote=True
120
+ )
121
+ return
122
+ buttons = []
123
+ for groupid in groupids:
124
+ try:
125
+ ttl = await client.get_chat(int(groupid))
126
+ title = ttl.title
127
+ active = await if_active(str(userid), str(groupid))
128
+ act = " - ACTIVE" if active else ""
129
+ buttons.append(
130
+ [
131
+ InlineKeyboardButton(
132
+ text=f"{title}{act}", callback_data=f"groupcb:{groupid}:{act}"
133
+ )
134
+ ]
135
+ )
136
+ except:
137
+ pass
138
+ if buttons:
139
+ await message.reply_text(
140
+ "Your connected group details ;\n\n",
141
+ reply_markup=InlineKeyboardMarkup(buttons),
142
+ quote=True
143
+ )
144
+ else:
145
+ await message.reply_text(
146
+ "There are no active connections!! Connect to some groups first.",
147
+ quote=True
148
+ )
plugins/filters.py ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ from pyrogram import filters, Client
3
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
4
+ from database.filters_mdb import(
5
+ add_filter,
6
+ get_filters,
7
+ delete_filter,
8
+ count_filters
9
+ )
10
+
11
+ from database.connections_mdb import active_connection
12
+ from utils import get_file_id, parser, split_quotes
13
+ from info import ADMINS
14
+
15
+
16
+ @Client.on_message(filters.command(['filter', 'add']) & filters.incoming)
17
+ async def addfilter(client, message): # sourcery skip: low-code-quality
18
+ userid = message.from_user.id if message.from_user else None
19
+ if not userid:
20
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
21
+ chat_type = message.chat.type
22
+ args = message.text.html.split(None, 1)
23
+
24
+ if chat_type == "private":
25
+ grpid = await active_connection(str(userid))
26
+ if grpid is not None:
27
+ grp_id = grpid
28
+ try:
29
+ chat = await client.get_chat(grpid)
30
+ title = chat.title
31
+ except Exception:
32
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
33
+ return
34
+ else:
35
+ await message.reply_text("I'm not connected to any groups!", quote=True)
36
+ return
37
+
38
+ elif chat_type in ["group", "supergroup"]:
39
+ grp_id = message.chat.id
40
+ title = message.chat.title
41
+
42
+ else:
43
+ return
44
+
45
+ st = await client.get_chat_member(grp_id, userid)
46
+ if (
47
+ st.status != "administrator"
48
+ and st.status != "creator"
49
+ and str(userid) not in ADMINS
50
+ ):
51
+ return
52
+
53
+ if len(args) < 2:
54
+ await message.reply_text("Command Incomplete :(", quote=True)
55
+ return
56
+
57
+ extracted = split_quotes(args[1])
58
+ text = extracted[0].lower()
59
+
60
+ if not message.reply_to_message and len(extracted) < 2:
61
+ await message.reply_text("Add some content to save your filter!", quote=True)
62
+ return
63
+
64
+ if (len(extracted) >= 2) and not message.reply_to_message:
65
+ reply_text, btn, alert = parser(extracted[1], text)
66
+ fileid = None
67
+ if not reply_text:
68
+ await message.reply_text("You cannot have buttons alone, give some text to go with it!", quote=True)
69
+ return
70
+
71
+ elif message.reply_to_message and message.reply_to_message.reply_markup:
72
+ try:
73
+ rm = message.reply_to_message.reply_markup
74
+ btn = rm.inline_keyboard
75
+ if msg := get_file_id(message.reply_to_message):
76
+ fileid = msg.file_id
77
+ reply_text = message.reply_to_message.caption.html
78
+ else:
79
+ reply_text = message.reply_to_message.text.html
80
+ fileid = None
81
+ alert = None
82
+ except Exception:
83
+ reply_text = ""
84
+ btn = "[]"
85
+ fileid = None
86
+ alert = None
87
+
88
+ elif message.reply_to_message and message.reply_to_message.media:
89
+ try:
90
+ msg = get_file_id(message.reply_to_message)
91
+ fileid = msg.file_id if msg else None
92
+ reply_text, btn, alert = parser(extracted[1], text) if message.reply_to_message.sticker else parser(
93
+ message.reply_to_message.caption.html, text)
94
+ except Exception:
95
+ reply_text = ""
96
+ btn = "[]"
97
+ alert = None
98
+ elif message.reply_to_message and message.reply_to_message.text:
99
+ try:
100
+ fileid = None
101
+ reply_text, btn, alert = parser(
102
+ message.reply_to_message.text.html, text)
103
+ except Exception:
104
+ reply_text = ""
105
+ btn = "[]"
106
+ alert = None
107
+ else:
108
+ return
109
+
110
+ await add_filter(grp_id, text, reply_text, btn, fileid, alert)
111
+
112
+ await message.reply_text(
113
+ f"Filter for `{text}` added in **{title}**",
114
+ quote=True,
115
+ parse_mode="md"
116
+ )
117
+
118
+
119
+ @Client.on_message(filters.command(['viewfilters', 'filters']) & filters.incoming)
120
+ async def get_all(client, message):
121
+ chat_type = message.chat.type
122
+ userid = message.from_user.id if message.from_user else None
123
+ if not userid:
124
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
125
+
126
+ if chat_type == "private":
127
+ userid = message.from_user.id
128
+ grpid = await active_connection(str(userid))
129
+ if grpid is not None:
130
+ grp_id = grpid
131
+ try:
132
+ chat = await client.get_chat(grpid)
133
+ title = chat.title
134
+ except Exception:
135
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
136
+ return
137
+ else:
138
+ await message.reply_text("I'm not connected to any groups!", quote=True)
139
+ return
140
+ elif chat_type in ["group", "supergroup"]:
141
+ grp_id = message.chat.id
142
+ title = message.chat.title
143
+ else:
144
+ return
145
+ st = await client.get_chat_member(grp_id, userid)
146
+ if st.status != "administrator" and st.status != "creator" and str(userid) not in ADMINS:
147
+ return
148
+ texts = await get_filters(grp_id)
149
+ count = await count_filters(grp_id)
150
+ if count:
151
+ filterlist = f"Total number of filters in **{title}** : {count}\n\n"
152
+ for text in texts:
153
+ keywords = f" × `{text}`\n"
154
+ filterlist += keywords
155
+ if len(filterlist) > 4096:
156
+ with io.BytesIO(str.encode(filterlist.replace("`", ""))) as keyword_file:
157
+ keyword_file.name = "keywords.txt"
158
+ await message.reply_document(document=keyword_file, quote=True)
159
+ return
160
+ else:
161
+ filterlist = f"There are no active filters in **{title}**"
162
+ await message.reply_text(text=filterlist, quote=True, parse_mode="md")
163
+
164
+
165
+ @Client.on_message(filters.command('del') & filters.incoming)
166
+ async def deletefilter(client, message):
167
+ userid = message.from_user.id if message.from_user else None
168
+ if not userid:
169
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
170
+
171
+ chat_type = message.chat.type
172
+ if chat_type == "private":
173
+ grpid = await active_connection(str(userid))
174
+ if grpid is not None:
175
+ grp_id = grpid
176
+ try:
177
+ chat = await client.get_chat(grpid)
178
+ title = chat.title
179
+ except Exception:
180
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
181
+ return
182
+ else:
183
+ await message.reply_text("I'm not connected to any groups!", quote=True)
184
+ elif chat_type in ["group", "supergroup"]:
185
+ grp_id = message.chat.id
186
+ title = message.chat.title
187
+ else:
188
+ return
189
+ st = await client.get_chat_member(grp_id, userid)
190
+ if st.status != "administrator" and st.status != "creator" and str(userid) not in ADMINS:
191
+ return
192
+ try:
193
+ cmd, text = message.text.split(" ", 1)
194
+ except Exception:
195
+ await message.reply_text("<i>Mention the filtername which you wanna delete!</i>\n\n<code>/del filtername</code>\n\nUse /viewfilters to view all available filters", quote=True)
196
+
197
+ return
198
+ query = text.lower()
199
+ await delete_filter(message, query, grp_id)
200
+
201
+
202
+ @Client.on_message(filters.command('delall') & filters.incoming)
203
+ async def delallconfirm(client, message):
204
+ userid = message.from_user.id if message.from_user else None
205
+ if not userid:
206
+ return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
207
+
208
+ chat_type = message.chat.type
209
+ if chat_type == "private":
210
+ grpid = await active_connection(str(userid))
211
+ if grpid is not None:
212
+ grp_id = grpid
213
+ try:
214
+ chat = await client.get_chat(grpid)
215
+ title = chat.title
216
+ except Exception:
217
+ await message.reply_text("Make sure I'm present in your group!!", quote=True)
218
+ return
219
+ else:
220
+ await message.reply_text("I'm not connected to any groups!", quote=True)
221
+ return
222
+ elif chat_type in ["group", "supergroup"]:
223
+ grp_id = message.chat.id
224
+ title = message.chat.title
225
+ else:
226
+ return
227
+ st = await client.get_chat_member(grp_id, userid)
228
+ if st.status == "creator" or str(userid) in ADMINS:
229
+ await message.reply_text(f"This will delete all filters from '{title}'.\nDo you want to continue??", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="YES", callback_data="delallconfirm")], [InlineKeyboardButton(text="CANCEL", callback_data="delallcancel")]]), quote=True)
plugins/genlink.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from pyrogram import filters, Client, enums
3
+ from pyrogram.errors.exceptions.bad_request_400 import ChannelInvalid, UsernameInvalid, UsernameNotModified
4
+ from info import ADMINS, LOG_CHANNEL, FILE_STORE_CHANNEL, PUBLIC_FILE_STORE
5
+ from database.ia_filterdb import unpack_new_file_id
6
+ from utils import temp
7
+ import re
8
+ import os
9
+ import json
10
+ import base64
11
+ import logging
12
+
13
+ logger = logging.getLogger(__name__)
14
+ logger.setLevel(logging.INFO)
15
+
16
+
17
+ async def allowed(_, __, message):
18
+ if PUBLIC_FILE_STORE:
19
+ return True
20
+ return bool(message.from_user and message.from_user.id in ADMINS)
21
+
22
+
23
+ @Client.on_message(filters.command(['batch', 'pbatch']) & filters.create(allowed))
24
+ async def gen_link_batch(bot, message): # sourcery skip: low-code-quality
25
+ if " " not in message.text:
26
+ return await message.reply("Use correct format.\nExample <code>/batch https://t.me/TeamEvamaria/10 https://t.me/TeamEvamaria/20</code>.")
27
+ links = message.text.strip().split(" ")
28
+ if len(links) != 3:
29
+ return await message.reply("Use correct format.\nExample <code>/batch https://t.me/TeamEvamaria/10 https://t.me/TeamEvamaria/20</code>.")
30
+ cmd, first, last = links
31
+ regex = re.compile(
32
+ "(https://)?(t\.me/|telegram\.me/|telegram\.dog/)(c/)?(\d+|[a-zA-Z_0-9]+)/(\d+)$")
33
+ match = regex.match(first)
34
+ if not match:
35
+ return await message.reply('Invalid link')
36
+ f_chat_id = match[4]
37
+ f_msg_id = int(match[5])
38
+ if f_chat_id.isnumeric():
39
+ f_chat_id = int(f"-100{f_chat_id}")
40
+
41
+ match = regex.match(last)
42
+ if not match:
43
+ return await message.reply('Invalid link')
44
+ l_chat_id = match[4]
45
+ l_msg_id = int(match[5])
46
+ if l_chat_id.isnumeric():
47
+ l_chat_id = int(f"-100{l_chat_id}")
48
+
49
+ if f_chat_id != l_chat_id:
50
+ return await message.reply("Chat ids not matched.")
51
+ try:
52
+ chat_id = (await bot.get_chat(f_chat_id)).id
53
+ except ChannelInvalid:
54
+ return await message.reply('This may be a private channel / group. Make me an admin over there to index the files.')
55
+ except (UsernameInvalid, UsernameNotModified):
56
+ return await message.reply('Invalid Link specified.')
57
+ except Exception as e:
58
+ return await message.reply(f'Errors - {e}')
59
+
60
+ sts = await message.reply("Generating link for your message.\nThis may take time depending upon number of messages")
61
+
62
+ FRMT = "Generating Link...\nTotal Messages: `{total}`\nDone: `{current}`\nRemaining: `{rem}`\nStatus: `{sts}`"
63
+
64
+ outlist = []
65
+
66
+ # file store without db channel
67
+ og_msg = 0
68
+ tot = 0
69
+ async for msg in bot.iter_messages(f_chat_id, l_msg_id, f_msg_id):
70
+ tot += 1
71
+ if msg.empty or msg.service:
72
+ continue
73
+ if not msg.media:
74
+ # only media messages supported.
75
+ continue
76
+ try:
77
+ file_type = msg.media
78
+ file = getattr(msg, file_type.value)
79
+ caption = getattr(msg, 'caption', '')
80
+ if caption:
81
+ caption = caption.html
82
+ if file:
83
+ file = {
84
+ "file_id": file.file_id,
85
+ "caption": caption,
86
+ "title": getattr(file, "file_name", ""),
87
+ "size": file.file_size,
88
+ "protect": cmd.lower().strip() == "/pbatch",
89
+ }
90
+
91
+ og_msg += 1
92
+ outlist.append(file)
93
+ except Exception:
94
+ pass
95
+ if not og_msg % 20:
96
+ try:
97
+ await sts.edit(FRMT.format(total=l_msg_id-f_msg_id, current=tot, rem=((l_msg_id-f_msg_id) - tot), sts="Saving Messages"))
98
+ except Exception:
99
+ pass
100
+ with open(f"batchmode_{message.from_user.id}.json", "w+") as out:
101
+ json.dump(outlist, out)
102
+ post = await bot.send_document(LOG_CHANNEL, f"batchmode_{message.from_user.id}.json", file_name="Batch.json", caption="⚠️Generated for filestore.")
103
+ os.remove(f"batchmode_{message.from_user.id}.json")
104
+ file_id, ref = unpack_new_file_id(post.document.file_id)
105
+ await sts.edit(f"Here is your link\nContains `{og_msg}` files.\n https://t.me/{temp.U_NAME}?start=BATCH-{file_id}")
plugins/index.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from distutils.log import error
2
+ import logging
3
+ import asyncio
4
+ from queue import Empty
5
+ from pyrogram import Client, filters, enums
6
+ from pyrogram.errors import FloodWait
7
+ from pyrogram.errors.exceptions.bad_request_400 import ChannelInvalid, ChatAdminRequired, UsernameInvalid, UsernameNotModified
8
+ from info import ADMINS
9
+ from info import INDEX_REQ_CHANNEL as LOG_CHANNEL
10
+ from database.ia_filterdb import save_file
11
+ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
12
+ from utils import temp
13
+ import re
14
+ logger = logging.getLogger(__name__)
15
+ logger.setLevel(logging.INFO)
16
+ lock = asyncio.Lock()
17
+
18
+
19
+ @Client.on_callback_query(filters.regex('^index'))
20
+ async def index_files(bot, query):
21
+ if query.data.startswith('index_cancel'):
22
+ temp.CANCEL = True
23
+ return await query.answer("Cancelling Indexing")
24
+ _, raju, chat, lst_msg_id, from_user = query.data.split("#")
25
+ if raju == 'reject':
26
+ await query.message.delete()
27
+ await bot.send_message(int(from_user), f'Your Submission for indexing {chat} has been decliened by our moderators.', reply_to_message_id=int(lst_msg_id))
28
+
29
+ return
30
+ if lock.locked():
31
+ return await query.answer('Wait until previous process complete.', show_alert=True)
32
+
33
+ msg = query.message
34
+ await query.answer('Processing...⏳', show_alert=True)
35
+ if int(from_user) not in ADMINS:
36
+ await bot.send_message(int(from_user), f'Your Submission for indexing {chat} has been accepted by our moderators and will be added soon.', reply_to_message_id=int(lst_msg_id))
37
+
38
+ await msg.edit("Starting Indexing", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton('Cancel', callback_data='index_cancel')]]))
39
+
40
+ try:
41
+ chat = int(chat)
42
+ except Exception:
43
+ chat = chat
44
+ await index_files_to_db(int(lst_msg_id), chat, msg, bot)
45
+
46
+
47
+ @Client.on_message(filters.forwarded & filters.private & filters.incoming)
48
+ async def send_for_index(bot, message):
49
+ if message.chat.type in [enums.ChatType.PRIVATE, enums.ChatType.BOT]:
50
+ return await message.reply(f'Privet Channel Groups And Bots Not Accept')
51
+ last_msg_id = message.forward_from_message_id
52
+ chat_id = message.forward_from_chat.id
53
+ try:
54
+ await bot.get_chat(chat_id)
55
+ except ChannelInvalid:
56
+ return await message.reply('This may be a private channel / group. Make me an admin over there to index the files.')
57
+ except (UsernameInvalid, UsernameNotModified):
58
+ return await message.reply('Invalid Link specified.')
59
+ except Exception as e:
60
+ logger.exception(e)
61
+ return await message.reply(f'Errors - {e}')
62
+ try:
63
+ k = await bot.get_messages(chat_id, last_msg_id)
64
+ except Exception:
65
+ return await message.reply('Make Sure That Iam An Admin In The Channel, if channel is private')
66
+ if k.empty:
67
+ return await message.reply('This may be group and iam not a admin of the group.')
68
+
69
+ if message.from_user.id in ADMINS:
70
+ buttons = [
71
+ [
72
+ InlineKeyboardButton('Yes',
73
+ callback_data=f'index#accept#{chat_id}#{last_msg_id}#{message.from_user.id}')
74
+ ],
75
+ [
76
+ InlineKeyboardButton('close', callback_data='close_data'),
77
+ ]
78
+ ]
79
+ reply_markup = InlineKeyboardMarkup(buttons)
80
+ return await message.reply(
81
+ f'Do you Want To Index This Channel/ Group ?\n\nChat ID/ Username: <code>{chat_id}</code>\nLast Message ID: <code>{last_msg_id}</code>',
82
+ reply_markup=reply_markup)
83
+
84
+ if type(chat_id) is int:
85
+ try:
86
+ link = (await bot.create_chat_invite_link(chat_id)).invite_link
87
+ except ChatAdminRequired:
88
+ return await message.reply('Make sure iam an admin in the chat and have permission to invite users.')
89
+ else:
90
+ link = f"@{message.forward_from_chat.username}"
91
+ buttons = [
92
+ [
93
+ InlineKeyboardButton('Accept Index',
94
+ callback_data=f'index#accept#{chat_id}#{last_msg_id}#{message.from_user.id}')
95
+ ],
96
+ [
97
+ InlineKeyboardButton('Reject Index',
98
+ callback_data=f'index#reject#{chat_id}#{message.message_id}#{message.from_user.id}'),
99
+ ]
100
+ ]
101
+ reply_markup = InlineKeyboardMarkup(buttons)
102
+ await bot.send_message(LOG_CHANNEL,
103
+ f'#IndexRequest\n\nBy : {message.from_user.mention} (<code>{message.from_user.id}</code>)\nChat ID/ Username - <code> {chat_id}</code>\nLast Message ID - <code>{last_msg_id}</code>\nInviteLink - {link}',
104
+ reply_markup=reply_markup)
105
+ await message.reply('ThankYou For the Contribution, Wait For My Moderators to verify the files.')
106
+
107
+
108
+ async def index_files_to_db(lst_msg_id, chat, msg, bot):
109
+ # sourcery skip: low-code-quality
110
+ errors, total_files, duplicate, deleted, no_media, unsupported, current = 0, 0, 0, 0, 0, 0, 0
111
+ msg_id = lst_msg_id
112
+ try:
113
+ for msgs in range(abs(lst_msg_id)):
114
+ current += 1
115
+ if current % 20 == 0:
116
+ can = [[InlineKeyboardButton(
117
+ 'Cancel', callback_data='index_cancel')]]
118
+ reply = InlineKeyboardMarkup(can)
119
+ await msg.edit_text(
120
+ text=f"Total messages fetched: <code>{current}</code>\nTotal messages saved: <code>{total_files}</code>\nDuplicate Files Skipped: <code>{duplicate}</code>\nDeleted Messages Skipped: <code>{deleted}</code>\nNon-Media messages skipped: <code>{no_media + unsupported}</code>(Unsupported Media - `{unsupported}` )\nErrors Occurred: <code>{errors}</code>",
121
+ reply_markup=reply)
122
+ message = await bot.get_messages(chat, msg_id)
123
+ if message.empty or not message.media:
124
+ no_media += 1
125
+ continue
126
+
127
+ for file_type in ("document", "video"):
128
+ media = getattr(message, file_type, None)
129
+ if media is not None:
130
+ break
131
+
132
+ if not media:
133
+ no_media += 1
134
+ continue
135
+
136
+ media.file_type = file_type
137
+ media.caption = message.caption
138
+
139
+ aynav, vnay = await save_file(media)
140
+
141
+ if aynav:
142
+ total_files += 1
143
+ elif vnay == 0:
144
+ duplicate += 1
145
+ elif vnay == 2:
146
+ errors += 1
147
+
148
+ msgs += 1
149
+ msg_id -= 1
150
+
151
+ except Exception as e:
152
+ logger.exception(e)
153
+ await msg.edit(f'Error: {e}')
154
+ else:
155
+ await msg.edit(f'Succesfully saved <code>{total_files}</code> to dataBase!\nDuplicate Files Skipped: <code>{duplicate}</code>\nDeleted Messages Skipped: <code>{deleted}</code>\nNon-Media messages skipped: <code>{no_media + unsupported}</code>(Unsupported Media - `{unsupported}` )\nErrors Occurred: <code>{errors}</code>')
plugins/inline.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from pyrogram import Client, emoji, filters
3
+ from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
4
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultCachedDocument, InlineQuery
5
+ from database.ia_filterdb import get_search_results
6
+ from utils import is_subscribed, get_size, temp
7
+ from info import CACHE_TIME, AUTH_USERS, AUTH_CHANNEL, CUSTOM_FILE_CAPTION
8
+
9
+ logger = logging.getLogger(__name__)
10
+ cache_time = 0 if AUTH_USERS or AUTH_CHANNEL else CACHE_TIME
11
+
12
+ async def inline_users(query: InlineQuery):
13
+ if AUTH_USERS:
14
+ return bool(query.from_user and query.from_user.id in AUTH_USERS)
15
+ return bool(query.from_user and query.from_user.id not in temp.BANNED_USERS)
16
+
17
+ @Client.on_inline_query()
18
+ async def answer(bot, query):
19
+ """Show search results for given inline query"""
20
+
21
+ if not await inline_users(query):
22
+ await query.answer(results=[],
23
+ cache_time=0,
24
+ switch_pm_text='okDa',
25
+ switch_pm_parameter="hehe")
26
+ return
27
+
28
+ if AUTH_CHANNEL and not await is_subscribed(bot, query):
29
+ await query.answer(results=[],
30
+ cache_time=0,
31
+ switch_pm_text='You have to subscribe my channel to use the bot',
32
+ switch_pm_parameter="subscribe")
33
+ return
34
+
35
+ results = []
36
+ if '|' in query.query:
37
+ string, file_type = query.query.split('|', maxsplit=1)
38
+ string = string.strip()
39
+ file_type = file_type.strip().lower()
40
+ else:
41
+ string = query.query.strip()
42
+ file_type = None
43
+
44
+ offset = int(query.offset or 0)
45
+ reply_markup = get_reply_markup(query=string)
46
+ files, next_offset, total = await get_search_results(string,
47
+ file_type=file_type,
48
+ max_results=10,
49
+ offset=offset)
50
+
51
+ for file in files:
52
+ title=file.file_name
53
+ size=get_size(file.file_size)
54
+ f_caption=file.caption
55
+ if CUSTOM_FILE_CAPTION:
56
+ try:
57
+ 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)
58
+ except Exception as e:
59
+ logger.exception(e)
60
+ f_caption=f_caption
61
+ if f_caption is None:
62
+ f_caption = f"{file.file_name}"
63
+ results.append(
64
+ InlineQueryResultCachedDocument(
65
+ title=file.file_name,
66
+ file_id=file.file_id,
67
+ caption=f_caption,
68
+ description=f'Size: {get_size(file.file_size)}\nType: {file.file_type}',
69
+ reply_markup=reply_markup))
70
+
71
+ if results:
72
+ switch_pm_text = f"{emoji.FILE_FOLDER} Results - {total}"
73
+ if string:
74
+ switch_pm_text += f" for {string}"
75
+ try:
76
+ await query.answer(results=results,
77
+ is_personal = True,
78
+ cache_time=cache_time,
79
+ switch_pm_text=switch_pm_text,
80
+ switch_pm_parameter="start",
81
+ next_offset=str(next_offset))
82
+ except QueryIdInvalid:
83
+ pass
84
+ except Exception as e:
85
+ logging.exception(str(e))
86
+ else:
87
+ switch_pm_text = f'{emoji.CROSS_MARK} No results'
88
+ if string:
89
+ switch_pm_text += f' for "{string}"'
90
+
91
+ await query.answer(results=[],
92
+ is_personal = True,
93
+ cache_time=cache_time,
94
+ switch_pm_text=switch_pm_text,
95
+ switch_pm_parameter="okay")
96
+
97
+
98
+ def get_reply_markup(query):
99
+ buttons = [
100
+ [
101
+ InlineKeyboardButton('Search again', switch_inline_query_current_chat=query)
102
+ ]
103
+ ]
104
+ return InlineKeyboardMarkup(buttons)
105
+
106
+
107
+
108
+
plugins/misc.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pyrogram import Client, filters
3
+ from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty
4
+ from info import IMDB_TEMPLATE
5
+ from utils import extract_user, get_file_id, get_poster, last_online
6
+ import time
7
+ from datetime import datetime
8
+ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
9
+ import logging
10
+ logger = logging.getLogger(__name__)
11
+ logger.setLevel(logging.ERROR)
12
+
13
+
14
+ @Client.on_message(filters.command('id'))
15
+ async def showid(client, message):
16
+ chat_type = message.chat.type
17
+ if chat_type == "private":
18
+ user_id = message.chat.id
19
+ first = message.from_user.first_name
20
+ last = message.from_user.last_name or ""
21
+ username = message.from_user.username or ""
22
+ dc_id = message.from_user.dc_id or ""
23
+ await message.reply_text(
24
+ f"<b>➲ First Name:</b> {first}\n<b>➲ Last Name:</b> {last}\n<b>➲ Username:</b> {username}\n<b>➲ Telegram ID:</b> <code>{user_id}</code>\n<b>➲ Data Centre:</b> <code>{dc_id}</code>",
25
+ quote=True
26
+ )
27
+
28
+ elif chat_type in ["group", "supergroup"]:
29
+ _id = ""
30
+ _id += (
31
+ "<b>➲ Chat ID</b>: "
32
+ f"<code>{message.chat.id}</code>\n"
33
+ )
34
+ if message.reply_to_message:
35
+ _id += (
36
+ "<b>➲ User ID</b>: "
37
+ f"<code>{message.from_user.id if message.from_user else 'Anonymous'}</code>\n"
38
+ "<b>➲ Replied User ID</b>: "
39
+ f"<code>{message.reply_to_message.from_user.id if message.reply_to_message.from_user else 'Anonymous'}</code>\n"
40
+ )
41
+ file_info = get_file_id(message.reply_to_message)
42
+ else:
43
+ _id += (
44
+ "<b>➲ User ID</b>: "
45
+ f"<code>{message.from_user.id if message.from_user else 'Anonymous'}</code>\n"
46
+ )
47
+ file_info = get_file_id(message)
48
+ if file_info:
49
+ _id += (
50
+ f"<b>{file_info.message_type}</b>: "
51
+ f"<code>{file_info.file_id}</code>\n"
52
+ )
53
+ await message.reply_text(
54
+ _id,
55
+ quote=True
56
+ )
57
+
58
+
59
+ @Client.on_message(filters.command(["info"]))
60
+ async def who_is(client, message):
61
+ # https://github.com/SpEcHiDe/PyroGramBot/blob/master/pyrobot/plugins/admemes/whois.py#L19
62
+ status_message = await message.reply_text(
63
+ "`Fetching user info...`"
64
+ )
65
+ await status_message.edit(
66
+ "`Processing user info...`"
67
+ )
68
+ from_user = None
69
+ from_user_id, _ = extract_user(message)
70
+ try:
71
+ from_user = await client.get_users(from_user_id)
72
+ except Exception as error:
73
+ await status_message.edit(str(error))
74
+ return
75
+ if from_user is None:
76
+ return await status_message.edit("no valid user_id / message specified")
77
+ message_out_str = ""
78
+ message_out_str += f"<b>➲First Name:</b> {from_user.first_name}\n"
79
+ last_name = from_user.last_name or "<b>None</b>"
80
+ message_out_str += f"<b>➲Last Name:</b> {last_name}\n"
81
+ message_out_str += f"<b>➲Telegram ID:</b> <code>{from_user.id}</code>\n"
82
+ username = from_user.username or "<b>None</b>"
83
+ dc_id = from_user.dc_id or "[User Doesn't Have A Valid DP]"
84
+ message_out_str += f"<b>➲Data Centre:</b> <code>{dc_id}</code>\n"
85
+ message_out_str += f"<b>➲User Name:</b> @{username}\n"
86
+ message_out_str += f"<b>➲User 𝖫𝗂𝗇𝗄:</b> <a href='tg://user?id={from_user.id}'><b>Click Here</b></a>\n"
87
+ if message.chat.type in (("supergroup", "channel")):
88
+ try:
89
+ chat_member_p = await message.chat.get_member(from_user.id)
90
+ joined_date = datetime.fromtimestamp(
91
+ chat_member_p.joined_date or time.time()
92
+ ).strftime("%Y.%m.%d %H:%M:%S")
93
+ message_out_str += (
94
+ "<b>➲Joined this Chat on:</b> <code>"
95
+ f"{joined_date}"
96
+ "</code>\n"
97
+ )
98
+ except UserNotParticipant:
99
+ pass
100
+ if chat_photo := from_user.photo:
101
+ local_user_photo = await client.download_media(
102
+ message=chat_photo.big_file_id
103
+ )
104
+ buttons = [[
105
+ InlineKeyboardButton('🔐 Close', callback_data='close_data')
106
+ ]]
107
+ reply_markup = InlineKeyboardMarkup(buttons)
108
+ await message.reply_photo(
109
+ photo=local_user_photo,
110
+ quote=True,
111
+ reply_markup=reply_markup,
112
+ caption=message_out_str,
113
+ disable_notification=True
114
+ )
115
+ os.remove(local_user_photo)
116
+ else:
117
+ buttons = [[
118
+ InlineKeyboardButton('🔐 Close', callback_data='close_data')
119
+ ]]
120
+ reply_markup = InlineKeyboardMarkup(buttons)
121
+ await message.reply_text(
122
+ text=message_out_str,
123
+ reply_markup=reply_markup,
124
+ quote=True,
125
+ disable_notification=True
126
+ )
127
+ await status_message.delete()
128
+
129
+
130
+ @Client.on_message(filters.command(["imdb", 'search']))
131
+ async def imdb_search(client, message):
132
+ if ' ' in message.text:
133
+ k = await message.reply('Searching ImDB')
134
+ r, title = message.text.split(None, 1)
135
+ movies = await get_poster(title, bulk=True)
136
+ if not movies:
137
+ return await message.reply("No results Found")
138
+ btn = [
139
+ [
140
+ InlineKeyboardButton(
141
+ text=f"{movie.get('title')} - {movie.get('year')}",
142
+ callback_data=f"imdb#{movie.movieID}",
143
+ )
144
+ ]
145
+ for movie in movies
146
+ ]
147
+ await k.edit('Here is what i found on IMDb', reply_markup=InlineKeyboardMarkup(btn))
148
+ else:
149
+ await message.reply('Give me a movie / series Name')
150
+
151
+
152
+ @Client.on_callback_query(filters.regex('^imdb'))
153
+ async def imdb_callback(bot: Client, quer_y: CallbackQuery):
154
+ i, movie = quer_y.data.split('#')
155
+ imdb = await get_poster(query=movie, id=True)
156
+ btn = [
157
+ [
158
+ InlineKeyboardButton(
159
+ text=f"{imdb.get('title')}",
160
+ url=imdb['url'],
161
+ )
162
+ ]
163
+ ]
164
+ message = quer_y.message.reply_to_message or quer_y.message
165
+ if imdb:
166
+ caption = IMDB_TEMPLATE.format(
167
+ query=imdb['title'],
168
+ title=imdb['title'],
169
+ votes=imdb['votes'],
170
+ aka=imdb["aka"],
171
+ seasons=imdb["seasons"],
172
+ box_office=imdb['box_office'],
173
+ localized_title=imdb['localized_title'],
174
+ kind=imdb['kind'],
175
+ imdb_id=imdb["imdb_id"],
176
+ cast=imdb["cast"],
177
+ runtime=imdb["runtime"],
178
+ countries=imdb["countries"],
179
+ certificates=imdb["certificates"],
180
+ languages=imdb["languages"],
181
+ director=imdb["director"],
182
+ writer=imdb["writer"],
183
+ producer=imdb["producer"],
184
+ composer=imdb["composer"],
185
+ cinematographer=imdb["cinematographer"],
186
+ music_team=imdb["music_team"],
187
+ distributors=imdb["distributors"],
188
+ release_date=imdb['release_date'],
189
+ year=imdb['year'],
190
+ genres=imdb['genres'],
191
+ poster=imdb['poster'],
192
+ plot=imdb['plot'],
193
+ rating=imdb['rating'],
194
+ url=imdb['url'],
195
+ **locals()
196
+ )
197
+ else:
198
+ caption = "No Results"
199
+ if imdb.get('poster'):
200
+ try:
201
+ await quer_y.message.reply_photo(photo=imdb['poster'], caption=caption, reply_markup=InlineKeyboardMarkup(btn))
202
+ except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
203
+ pic = imdb.get('poster')
204
+ poster = pic.replace('.jpg', "._V1_UX360.jpg")
205
+ await quer_y.message.reply_photo(photo=poster, caption=caption, reply_markup=InlineKeyboardMarkup(btn))
206
+ except Exception as e:
207
+ logger.exception(e)
208
+ await quer_y.message.reply(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
209
+ await quer_y.message.delete()
210
+ else:
211
+ await quer_y.message.edit(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
212
+ await quer_y.answer()
plugins/p_ttishow.py ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyrogram import Client, filters
2
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
3
+ from pyrogram.errors.exceptions.bad_request_400 import MessageTooLong, PeerIdInvalid
4
+ from info import ADMINS, LOG_CHANNEL, SUPPORT_CHAT, MELCOW_NEW_USERS
5
+ from database.users_chats_db import db
6
+ from database.ia_filterdb import Media
7
+ from utils import get_size, temp, get_settings
8
+ from Script import script
9
+ from pyrogram.errors import ChatAdminRequired
10
+
11
+ """-----------------------------------------https://t.me/GetTGLink/4179 --------------------------------------"""
12
+
13
+ @Client.on_message(filters.new_chat_members & filters.group)
14
+ async def save_group(bot, message):
15
+ r_j_check = [u.id for u in message.new_chat_members]
16
+ if temp.ME in r_j_check:
17
+ if not await db.get_chat(message.chat.id):
18
+ total=await bot.get_chat_members_count(message.chat.id)
19
+ r_j = message.from_user.mention if message.from_user else "Anonymous"
20
+ await bot.send_message(LOG_CHANNEL, script.LOG_TEXT_G.format(message.chat.title, message.chat.id, total, r_j))
21
+ await db.add_chat(message.chat.id, message.chat.title)
22
+ if message.chat.id in temp.BANNED_CHATS:
23
+ # Inspired from a boat of a banana tree
24
+ buttons = [[
25
+ InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
26
+ ]]
27
+ reply_markup=InlineKeyboardMarkup(buttons)
28
+ k = await message.reply(
29
+ text='<b>CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..</b>',
30
+ reply_markup=reply_markup,
31
+ )
32
+
33
+ try:
34
+ await k.pin()
35
+ except:
36
+ pass
37
+ await bot.leave_chat(message.chat.id)
38
+ return
39
+ buttons = [[
40
+ InlineKeyboardButton('ℹ️ Help', url=f"https://t.me/{temp.U_NAME}?start=help"),
41
+ InlineKeyboardButton('📢 Updates', url='https://t.me/TMWAD')
42
+ ]]
43
+ reply_markup=InlineKeyboardMarkup(buttons)
44
+ await message.reply_text(
45
+ text=f"<b>Thankyou For Adding Me In {message.chat.title} ❣️\n\nIf you have any questions & doubts about using me contact support.</b>",
46
+ reply_markup=reply_markup)
47
+ else:
48
+ settings = await get_settings(message.chat.id)
49
+ if settings["welcome"]:
50
+ for u in message.new_chat_members:
51
+ if (temp.MELCOW).get('welcome') is not None:
52
+ try:
53
+ await (temp.MELCOW['welcome']).delete()
54
+ except:
55
+ pass
56
+ temp.MELCOW['welcome'] = await message.reply(f"<b>Hey , {u.mention}, Welcome to {message.chat.title}</b>")
57
+
58
+
59
+ @Client.on_message(filters.command('leave') & filters.user(ADMINS))
60
+ async def leave_a_chat(bot, message):
61
+ if len(message.command) == 1:
62
+ return await message.reply('Give me a chat id')
63
+ chat = message.command[1]
64
+ try:
65
+ chat = int(chat)
66
+ except:
67
+ chat = chat
68
+ try:
69
+ buttons = [[
70
+ InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
71
+ ]]
72
+ reply_markup=InlineKeyboardMarkup(buttons)
73
+ await bot.send_message(
74
+ chat_id=chat,
75
+ text='<b>Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group.</b>',
76
+ reply_markup=reply_markup,
77
+ )
78
+
79
+ await bot.leave_chat(chat)
80
+ await message.reply(f"left the chat `{chat}`")
81
+ except Exception as e:
82
+ await message.reply(f'Error - {e}')
83
+
84
+ @Client.on_message(filters.command('disable') & filters.user(ADMINS))
85
+ async def disable_chat(bot, message):
86
+ if len(message.command) == 1:
87
+ return await message.reply('Give me a chat id')
88
+ r = message.text.split(None)
89
+ if len(r) > 2:
90
+ reason = message.text.split(None, 2)[2]
91
+ chat = message.text.split(None, 2)[1]
92
+ else:
93
+ chat = message.command[1]
94
+ reason = "No reason Provided"
95
+ try:
96
+ chat_ = int(chat)
97
+ except:
98
+ return await message.reply('Give Me A Valid Chat ID')
99
+ cha_t = await db.get_chat(chat_)
100
+ if not cha_t:
101
+ return await message.reply("Chat Not Found In DB")
102
+ if cha_t['is_disabled']:
103
+ return await message.reply(f"This chat is already disabled:\nReason-<code> {cha_t['reason']} </code>")
104
+ await db.disable_chat(chat_, reason)
105
+ temp.BANNED_CHATS.append(chat_)
106
+ await message.reply('Chat Successfully Disabled')
107
+ try:
108
+ buttons = [[
109
+ InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
110
+ ]]
111
+ reply_markup=InlineKeyboardMarkup(buttons)
112
+ await bot.send_message(
113
+ chat_id=chat_,
114
+ text=f'<b>Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group.</b> \nReason : <code>{reason}</code>',
115
+ reply_markup=reply_markup)
116
+ await bot.leave_chat(chat_)
117
+ except Exception as e:
118
+ await message.reply(f"Error - {e}")
119
+
120
+
121
+ @Client.on_message(filters.command('enable') & filters.user(ADMINS))
122
+ async def re_enable_chat(bot, message):
123
+ if len(message.command) == 1:
124
+ return await message.reply('Give me a chat id')
125
+ chat = message.command[1]
126
+ try:
127
+ chat_ = int(chat)
128
+ except:
129
+ return await message.reply('Give Me A Valid Chat ID')
130
+ sts = await db.get_chat(int(chat))
131
+ if not sts:
132
+ return await message.reply("Chat Not Found In DB !")
133
+ if not sts.get('is_disabled'):
134
+ return await message.reply('This chat is not yet disabled.')
135
+ await db.re_enable_chat(chat_)
136
+ temp.BANNED_CHATS.remove(chat_)
137
+ await message.reply("Chat Successfully re-enabled")
138
+
139
+
140
+ @Client.on_message(filters.command('stats') & filters.incoming)
141
+ async def get_ststs(bot, message):
142
+ rju = await message.reply('Fetching stats..')
143
+ total_users = await db.total_users_count()
144
+ totl_chats = await db.total_chat_count()
145
+ files = await Media.count_documents()
146
+ size = await db.get_db_size()
147
+ free = 536870912 - size
148
+ size = get_size(size)
149
+ free = get_size(free)
150
+ await rju.edit(script.STATUS_TXT.format(files, total_users, totl_chats, size, free))
151
+
152
+
153
+ # a function for trespassing into others groups, Inspired by a Vazha
154
+ # Not to be used , But Just to showcase his vazhatharam.
155
+ # @Client.on_message(filters.command('invite') & filters.user(ADMINS))
156
+ async def gen_invite(bot, message):
157
+ if len(message.command) == 1:
158
+ return await message.reply('Give me a chat id')
159
+ chat = message.command[1]
160
+ try:
161
+ chat = int(chat)
162
+ except Exception:
163
+ return await message.reply('Give Me A Valid Chat ID')
164
+ try:
165
+ link = await bot.create_chat_invite_link(chat)
166
+ except ChatAdminRequired:
167
+ return await message.reply("Invite Link Generation Failed, Iam Not Having Sufficient Rights")
168
+ except Exception as e:
169
+ return await message.reply(f'Error {e}')
170
+ await message.reply(f'Here is your Invite Link {link.invite_link}')
171
+
172
+ @Client.on_message(filters.command('ban') & filters.user(ADMINS))
173
+ async def ban_a_user(bot, message):
174
+ if len(message.command) == 1:
175
+ return await message.reply('Give me a user id / username')
176
+ r = message.text.split(None)
177
+ if len(r) > 2:
178
+ reason = message.text.split(None, 2)[2]
179
+ chat = message.text.split(None, 2)[1]
180
+ else:
181
+ chat = message.command[1]
182
+ reason = "No reason Provided"
183
+ try:
184
+ chat = int(chat)
185
+ except:
186
+ pass
187
+ try:
188
+ k = await bot.get_users(chat)
189
+ except PeerIdInvalid:
190
+ return await message.reply("This is an invalid user, make sure ia have met him before.")
191
+ except IndexError:
192
+ return await message.reply("This might be a channel, make sure its a user.")
193
+ except Exception as e:
194
+ return await message.reply(f'Error - {e}')
195
+ else:
196
+ jar = await db.get_ban_status(k.id)
197
+ if jar['is_banned']:
198
+ return await message.reply(f"{k.mention} is already banned\nReason: {jar['ban_reason']}")
199
+ await db.ban_user(k.id, reason)
200
+ temp.BANNED_USERS.append(k.id)
201
+ await message.reply(f"Successfully banned {k.mention}")
202
+
203
+
204
+
205
+ @Client.on_message(filters.command('unban') & filters.user(ADMINS))
206
+ async def unban_a_user(bot, message):
207
+ if len(message.command) == 1:
208
+ return await message.reply('Give me a user id / username')
209
+ r = message.text.split(None)
210
+ if len(r) > 2:
211
+ reason = message.text.split(None, 2)[2]
212
+ chat = message.text.split(None, 2)[1]
213
+ else:
214
+ chat = message.command[1]
215
+ reason = "No reason Provided"
216
+
217
+ chat = int(chat)
218
+ try:
219
+ k = await bot.get_users(chat)
220
+ except PeerIdInvalid:
221
+ return await message.reply("This is an invalid user, make sure ia have met him before.")
222
+
223
+ except IndexError:
224
+ return await message.reply("Thismight be a channel, make sure its a user.")
225
+ except Exception as e:
226
+ return await message.reply(f'Error - {e}')
227
+ else:
228
+ jar = await db.get_ban_status(k.id)
229
+ if not jar['is_banned']:
230
+ return await message.reply(f"{k.mention} is not yet banned.")
231
+ await db.remove_ban(k.id)
232
+ temp.BANNED_USERS.remove(k.id)
233
+ await message.reply(f"Successfully unbanned {k.mention}")
234
+
235
+
236
+
237
+ @Client.on_message(filters.command('users') & filters.user(ADMINS))
238
+ async def list_users(bot, message):
239
+ # https://t.me/GetTGLink/4184
240
+ raju = await message.reply('Getting List Of Users')
241
+ users = await db.get_all_users()
242
+ out = "Users Saved In DB Are:\n\n"
243
+ async for user in users:
244
+ out += f"<a href=tg://user?id={user['id']}>{user['name']}</a>"
245
+ if user['ban_status']['is_banned']:
246
+ out += '( Banned User )'
247
+ out += '\n'
248
+ try:
249
+ await raju.edit_text(out)
250
+ except MessageTooLong:
251
+ with open('users.txt', 'w+') as outfile:
252
+ outfile.write(out)
253
+ await message.reply_document('users.txt', caption="List Of Users")
254
+
255
+ @Client.on_message(filters.command('chats') & filters.user(ADMINS))
256
+ async def list_chats(bot, message):
257
+ raju = await message.reply('Getting List Of chats')
258
+ chats = await db.get_all_chats()
259
+ out = "Chats Saved In DB Are:\n\n"
260
+ async for chat in chats:
261
+ out += f"**Title:** `{chat['title']}`\n**- ID:** `{chat['id']}`"
262
+ if chat['chat_status']['is_disabled']:
263
+ out += '( Disabled Chat )'
264
+ out += '\n'
265
+ try:
266
+ await raju.edit_text(out)
267
+ except MessageTooLong:
268
+ with open('chats.txt', 'w+') as outfile:
269
+ outfile.write(out)
270
+ await message.reply_document('chats.txt', caption="List Of Chats")
plugins/pm_filter.py ADDED
@@ -0,0 +1,1250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Kanged From @TroJanZheX
2
+ import asyncio
3
+ import os
4
+ import re
5
+ import ast
6
+ import time
7
+ from PIL import Image
8
+ import urllib.request
9
+ from pyrogram.errors.exceptions.bad_request_400 import MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty, MessageEmpty
10
+ from Script import script
11
+ import pyrogram
12
+ from database.admin_group import get_admingroup
13
+ from database.connections_mdb import active_connection, all_connections, delete_connection, if_active, make_active, \
14
+ make_inactive
15
+ from info import ADMINS, AUTH_CHANNEL, AUTH_USERS, CUSTOM_FILE_CAPTION, AUTH_GROUPS, P_TTI_SHOW_OFF, IMDB, \
16
+ SINGLE_BUTTON, SPELL_CHECK_REPLY, IMDB_TEMPLATE
17
+ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
18
+ from pyrogram import Client, filters, enums
19
+ from pyrogram.errors import FloodWait, UserIsBlocked, MessageNotModified, PeerIdInvalid
20
+ from utils import get_size, is_subscribed, get_poster, search_gagala, temp, get_settings, save_group_settings, get_name, getseries, send_more_files, gen_url
21
+ from database.users_chats_db import db
22
+ from database.ia_filterdb import Media, get_file_details, get_search_results
23
+ from database.tvseriesfilters import add_tvseries_filter, update_tvseries_filter, getlinks, find_tvseries_filter, remove_tvseries
24
+ from database.quickdb import remove_inst, get_ids, add_sent_files, get_verification, remove_verification, add_verification
25
+ from database.filters_mdb import (
26
+ del_all,
27
+ find_filter,
28
+ get_filters,
29
+ )
30
+ import logging
31
+
32
+ logger = logging.getLogger(__name__)
33
+ logger.setLevel(logging.ERROR)
34
+
35
+ BUTTONS = {}
36
+ SPELL_CHECK = {}
37
+
38
+ DOWNLOAD_LOCATION = "./DOWNLOADS"
39
+
40
+
41
+ @Client.on_message(filters.group & filters.text & filters.incoming)
42
+ async def give_filter(client, message):
43
+ # await tvseries_filters(client, message)
44
+ await auto_filter(client, message)
45
+ # await manual_filters(client, message)
46
+
47
+
48
+ @Client.on_message(filters.private & filters.text & filters.incoming)
49
+ async def pm_give_filter(client, message):
50
+ k = await tvseries_filters(client, message)
51
+
52
+ if k is False:
53
+ await pm_auto_filter(client, message)
54
+
55
+
56
+ @Client.on_callback_query(filters.regex("^next"))
57
+ async def next_page(bot, query):
58
+ ident, req, key, offset = query.data.split("_")
59
+ if int(req) not in [query.from_user.id, 0]:
60
+ return await query.answer("This is Not For You !!!", show_alert=True)
61
+ try:
62
+ offset = int(offset)
63
+ except Exception:
64
+ offset = 0
65
+ search = BUTTONS.get(key)
66
+ if not search:
67
+ await query.answer("You are using one of my old messages, please send the request again.", show_alert=True)
68
+
69
+ return
70
+ files, n_offset, total = await get_search_results(search, offset=offset, filter=True)
71
+
72
+ try:
73
+ n_offset = int(n_offset)
74
+ except Exception:
75
+ n_offset = 0
76
+ if not files:
77
+ return
78
+ fileids = [file.file_id for file in files]
79
+ dbid = fileids[0]
80
+ fileids = "L_I_N_K".join(fileids)
81
+
82
+ btn = [[InlineKeyboardButton(text=f"{get_size(file.file_size)} ║ {get_name(file.file_name)}", url=gen_url(
83
+ f'https://telegram.dog/SpaciousUniverseBot?start=FEND-{file.file_id}'))] for file in files]
84
+
85
+ btn.insert(0, [InlineKeyboardButton("◈ All Files ◈", url=gen_url(
86
+ f'https://telegram.dog/SpaciousUniverseBot?start=FEND-{dbid}'))])
87
+
88
+ if 0 < offset <= 10:
89
+ off_set = 0
90
+ elif offset == 0:
91
+ off_set = None
92
+ else:
93
+ off_set = offset - 10
94
+ if n_offset == 0:
95
+ btn.append([InlineKeyboardButton("◄ Back", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(
96
+ f"❏ Pages {round(offset / 10) + 1} / {round(total / 10)}", callback_data="pages")])
97
+
98
+ elif off_set is None:
99
+ btn.append([InlineKeyboardButton(f"❏ {round(offset / 10) + 1} / {round(total / 10)}",
100
+ callback_data="pages"), InlineKeyboardButton("Next ►", callback_data=f"next_{req}_{key}_{n_offset}")])
101
+
102
+ else:
103
+ btn.append([InlineKeyboardButton("◄ Back", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(
104
+ f"❏ {round(offset / 10) + 1} / {round(total / 10)}", callback_data="pages"), InlineKeyboardButton("Next ►", callback_data=f"next_{req}_{key}_{n_offset}")])
105
+
106
+ try:
107
+ await query.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(btn))
108
+ except MessageNotModified:
109
+ pass
110
+ await query.answer()
111
+
112
+
113
+ @Client.on_callback_query(filters.regex("^pmnext"))
114
+ async def pm_next_page(bot, query):
115
+ ident, req, key, offset = query.data.split("_")
116
+ try:
117
+ offset = int(offset)
118
+ except Exception:
119
+ offset = 0
120
+ search = BUTTONS.get(key)
121
+ if not search:
122
+ await query.answer("You are using one of my old messages, please send the request again.", show_alert=True)
123
+
124
+ return
125
+ files, n_offset, total = await get_search_results(search, offset=offset, filter=True)
126
+
127
+ try:
128
+ n_offset = int(n_offset)
129
+ except Exception:
130
+ n_offset = 0
131
+ if not files:
132
+ return
133
+ fileids = [file.file_id for file in files]
134
+ dbid = fileids[0]
135
+ fileids = "L_I_N_K".join(fileids)
136
+ btn = [[InlineKeyboardButton(text=f"{get_size(file.file_size)} ║ {get_name(file.file_name)}",
137
+ callback_data=f'pmfiles#{file.file_id}')] for file in files]
138
+
139
+ if 0 < offset <= 10:
140
+ off_set = 0
141
+ elif offset == 0:
142
+ off_set = None
143
+ else:
144
+ off_set = offset - 10
145
+ if n_offset == 0:
146
+ btn.append([InlineKeyboardButton("◄ Back", callback_data=f"pmnext_{req}_{key}_{off_set}"), InlineKeyboardButton(
147
+ f"❏ Pages {round(offset / 10) + 1} / {round(total / 10)}", callback_data="pages")])
148
+
149
+ elif off_set is None:
150
+ btn.append([InlineKeyboardButton(f"❏ {round(offset / 10) + 1} / {round(total / 10)}", callback_data="pages"),
151
+ InlineKeyboardButton("Next ►", callback_data=f"pmnext_{req}_{key}_{n_offset}")])
152
+
153
+ else:
154
+ btn.append([InlineKeyboardButton("◄ Back", callback_data=f"pmnext_{req}_{key}_{off_set}"), InlineKeyboardButton(
155
+ f"❏ {round(offset / 10) + 1} / {round(total / 10)}", callback_data="pages"), InlineKeyboardButton("Next ►", callback_data=f"pmnext_{req}_{key}_{n_offset}")])
156
+
157
+ btn.insert(0, [InlineKeyboardButton(
158
+ "◈ All Files ◈", callback_data=f'pmfiles#{dbid}')])
159
+
160
+ try:
161
+ await query.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(btn))
162
+ except MessageNotModified:
163
+ pass
164
+ await query.answer()
165
+
166
+
167
+ @Client.on_callback_query(filters.regex("^spolling"))
168
+ async def advantage_spoll_choker(bot, query):
169
+ _, user, movie_ = query.data.split('#')
170
+ if int(user) != 0 and query.from_user.id != int(user):
171
+ return await query.answer("This is not for you", show_alert=True)
172
+ if movie_ == "close_spellcheck":
173
+ return await query.message.delete()
174
+ try:
175
+ movies = SPELL_CHECK.get(query.message.reply_to_message.id)
176
+ except Exception:
177
+ return await query.answer('Something went wrong...')
178
+ if not movies:
179
+ return await query.answer("You are clicking on an old button which is expired.", show_alert=True)
180
+
181
+ movie = movies[int(movie_)]
182
+ await query.answer('Checking for Movie in database...')
183
+ k = await manual_filters(bot, query.message, text=movie)
184
+ if k == False:
185
+ files, offset, total_results = await get_search_results(movie, offset=0, filter=True)
186
+
187
+ if files:
188
+ k = movie, files, offset, total_results
189
+ await auto_filter(bot, query, k)
190
+ else:
191
+ try:
192
+ k = await query.message.edit('This Movie Not Found In DataBase. \nTry Request Again with correct spelling')
193
+
194
+ await asyncio.sleep(10)
195
+ await k.delete()
196
+ except Exception:
197
+ return
198
+
199
+
200
+ @Client.on_callback_query()
201
+ async def cb_handler(client: Client, query: CallbackQuery):
202
+ if query.data == "close_data":
203
+ await query.message.delete()
204
+ elif query.data == "delallconfirm":
205
+ userid = query.from_user.id
206
+ chat_type = query.message.chat.type
207
+
208
+ if chat_type == "private":
209
+ grpid = await active_connection(str(userid))
210
+ if grpid is not None:
211
+ grp_id = grpid
212
+ try:
213
+ chat = await client.get_chat(grpid)
214
+ title = chat.title
215
+ except:
216
+ await query.message.edit_text("Make sure I'm present in your group!!", quote=True)
217
+ return await query.answer('Piracy Is Crime')
218
+ else:
219
+ await query.message.edit_text(
220
+ "I'm not connected to any groups!\nCheck /connections or connect to any groups",
221
+ quote=True
222
+ )
223
+ return await query.answer('Piracy Is Crime')
224
+
225
+ elif chat_type in ["group", "supergroup"]:
226
+ grp_id = query.message.chat.id
227
+ title = query.message.chat.title
228
+
229
+ else:
230
+ return await query.answer('Piracy Is Crime')
231
+
232
+ st = await client.get_chat_member(grp_id, userid)
233
+ if (st.status == "creator") or (str(userid) in ADMINS):
234
+ await del_all(query.message, grp_id, title)
235
+ else:
236
+ await query.answer("You need to be Group Owner or an Auth User to do that!", show_alert=True)
237
+ elif query.data == "delallcancel":
238
+ userid = query.from_user.id
239
+ chat_type = query.message.chat.type
240
+
241
+ if chat_type == "private":
242
+ await query.message.reply_to_message.delete()
243
+ await query.message.delete()
244
+
245
+ elif chat_type in ["group", "supergroup"]:
246
+ grp_id = query.message.chat.id
247
+ st = await client.get_chat_member(grp_id, userid)
248
+ if (st.status == "creator") or (str(userid) in ADMINS):
249
+ await query.message.delete()
250
+ try:
251
+ await query.message.reply_to_message.delete()
252
+ except:
253
+ pass
254
+ else:
255
+ await query.answer("That's not for you!!", show_alert=True)
256
+ elif "groupcb" in query.data:
257
+ await query.answer()
258
+
259
+ group_id = query.data.split(":")[1]
260
+
261
+ act = query.data.split(":")[2]
262
+ hr = await client.get_chat(int(group_id))
263
+ title = hr.title
264
+ user_id = query.from_user.id
265
+
266
+ if act == "":
267
+ stat = "CONNECT"
268
+ cb = "connectcb"
269
+ else:
270
+ stat = "DISCONNECT"
271
+ cb = "disconnect"
272
+
273
+ keyboard = InlineKeyboardMarkup([
274
+ [InlineKeyboardButton(f"{stat}", callback_data=f"{cb}:{group_id}"),
275
+ InlineKeyboardButton("DELETE", callback_data=f"deletecb:{group_id}")],
276
+ [InlineKeyboardButton("BACK", callback_data="backcb")]
277
+ ])
278
+
279
+ await query.message.edit_text(
280
+ f"Group Name : **{title}**\nGroup ID : `{group_id}`",
281
+ reply_markup=keyboard,
282
+ parse_mode="md"
283
+ )
284
+ return await query.answer('Piracy Is Crime')
285
+ elif "connectcb" in query.data:
286
+ await query.answer()
287
+
288
+ group_id = query.data.split(":")[1]
289
+
290
+ hr = await client.get_chat(int(group_id))
291
+
292
+ title = hr.title
293
+
294
+ user_id = query.from_user.id
295
+
296
+ mkact = await make_active(str(user_id), str(group_id))
297
+
298
+ if mkact:
299
+ await query.message.edit_text(
300
+ f"Connected to **{title}**",
301
+ parse_mode="md"
302
+ )
303
+ else:
304
+ await query.message.edit_text('Some error occurred!!', parse_mode="md")
305
+ return await query.answer('Piracy Is Crime')
306
+ elif "disconnect" in query.data:
307
+ await query.answer()
308
+
309
+ group_id = query.data.split(":")[1]
310
+
311
+ hr = await client.get_chat(int(group_id))
312
+
313
+ title = hr.title
314
+ user_id = query.from_user.id
315
+
316
+ mkinact = await make_inactive(str(user_id))
317
+
318
+ if mkinact:
319
+ await query.message.edit_text(
320
+ f"Disconnected from **{title}**",
321
+ parse_mode="md"
322
+ )
323
+ else:
324
+ await query.message.edit_text(
325
+ f"Some error occurred!!",
326
+ parse_mode="md"
327
+ )
328
+ return await query.answer('Piracy Is Crime')
329
+ elif "deletecb" in query.data:
330
+ await query.answer()
331
+
332
+ user_id = query.from_user.id
333
+ group_id = query.data.split(":")[1]
334
+
335
+ delcon = await delete_connection(str(user_id), str(group_id))
336
+
337
+ if delcon:
338
+ await query.message.edit_text(
339
+ "Successfully deleted connection"
340
+ )
341
+ else:
342
+ await query.message.edit_text(
343
+ f"Some error occurred!!",
344
+ parse_mode="md"
345
+ )
346
+ return await query.answer('Piracy Is Crime')
347
+ elif query.data == "backcb":
348
+ await query.answer()
349
+
350
+ userid = query.from_user.id
351
+
352
+ groupids = await all_connections(str(userid))
353
+ if groupids is None:
354
+ await query.message.edit_text(
355
+ "There are no active connections!! Connect to some groups first.",
356
+ )
357
+ return await query.answer('Piracy Is Crime')
358
+ buttons = []
359
+ for groupid in groupids:
360
+ try:
361
+ ttl = await client.get_chat(int(groupid))
362
+ title = ttl.title
363
+ active = await if_active(str(userid), str(groupid))
364
+ act = " - ACTIVE" if active else ""
365
+ buttons.append(
366
+ [
367
+ InlineKeyboardButton(
368
+ text=f"{title}{act}", callback_data=f"groupcb:{groupid}:{act}"
369
+ )
370
+ ]
371
+ )
372
+ except:
373
+ pass
374
+ if buttons:
375
+ await query.message.edit_text(
376
+ "Your connected group details ;\n\n",
377
+ reply_markup=InlineKeyboardMarkup(buttons)
378
+ )
379
+ elif "alertmessage" in query.data:
380
+ grp_id = query.message.chat.id
381
+ i = query.data.split(":")[1]
382
+ keyword = query.data.split(":")[2]
383
+ reply_text, btn, alerts, fileid = await find_filter(grp_id, keyword)
384
+ if alerts is not None:
385
+ alerts = ast.literal_eval(alerts)
386
+ alert = alerts[int(i)]
387
+ alert = alert.replace("\\n", "\n").replace("\\t", "\t")
388
+ await query.answer(alert, show_alert=True)
389
+
390
+ if query.data.startswith("gpfile"):
391
+ ident, file_id = query.data.split("#")
392
+ return await query.answer(url=f"https://t.me/{temp.U_NAME}?start={file_id}")
393
+
394
+ if query.data.startswith("pmfile"):
395
+ ident, file_id = query.data.split("#")
396
+ idstring = await get_ids(file_id)
397
+ if idstring:
398
+ await remove_inst(file_id)
399
+ idstring = idstring['links']
400
+ fileids = idstring.split("L_I_N_K")
401
+ sendmsglist = []
402
+ for file_id in fileids:
403
+ files_ = await get_file_details(file_id)
404
+ if not files_:
405
+ try:
406
+ msg = await client.send_cached_media(
407
+ chat_id=query.from_user.id,
408
+ file_id=file_id
409
+ )
410
+ filetype = msg.media
411
+ file = getattr(msg, filetype)
412
+ title = file.file_name
413
+ size = get_size(file.file_size)
414
+ f_caption = f"<code>{title}</code>"
415
+ if CUSTOM_FILE_CAPTION:
416
+ try:
417
+ f_caption = CUSTOM_FILE_CAPTION.format(
418
+ file_name='' if title is None else title, file_size='' if size is None else size, file_caption='')
419
+ except:
420
+ return
421
+ await msg.edit_caption(f_caption)
422
+ return
423
+ except:
424
+ pass
425
+ files = files_[0]
426
+ title = files.file_name
427
+ size = get_size(files.file_size)
428
+ f_caption = files.caption
429
+ if CUSTOM_FILE_CAPTION:
430
+ try:
431
+ f_caption = CUSTOM_FILE_CAPTION.format(
432
+ 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)
433
+ except Exception as e:
434
+ logger.exception(e)
435
+ f_caption = f_caption
436
+ if f_caption is None:
437
+ f_caption = f"{files.file_name}"
438
+ try:
439
+ k = await client.send_cached_media(
440
+ chat_id=query.from_user.id,
441
+ file_id=file_id,
442
+ caption=f_caption,
443
+ )
444
+ except FloodWait as e:
445
+ await asyncio.sleep(e.x)
446
+ logger.warning(f"Floodwait of {e.x} sec.")
447
+ k = await client.send_cached_media(
448
+ chat_id=query.from_user.id,
449
+ file_id=file_id,
450
+ caption=f_caption,
451
+ )
452
+ await asyncio.sleep(1)
453
+ sendmsglist.append(k)
454
+ await add_sent_files(query.from_user.id, file_id)
455
+
456
+ await query.answer('𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖')
457
+ kk = await client.send_message(
458
+ chat_id=query.from_user.id,
459
+ text="""
460
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
461
+ """)
462
+
463
+ await asyncio.sleep(600)
464
+ for k in sendmsglist:
465
+ await k.delete()
466
+ sendmsglist = []
467
+ return await kk.delete()
468
+
469
+ files_ = await get_file_details(file_id)
470
+ if not files_:
471
+ return await query.answer('No such file exist.')
472
+
473
+ files = files_[0]
474
+ title = files.file_name
475
+ size = get_size(files.file_size)
476
+ f_caption = files.caption
477
+ settings = await get_settings(query.message.chat.id)
478
+ if CUSTOM_FILE_CAPTION:
479
+ try:
480
+ f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
481
+ file_size='' if size is None else size,
482
+ file_caption='' if f_caption is None else f_caption)
483
+ except Exception as e:
484
+ logger.exception(e)
485
+ f_caption = f_caption
486
+ if f_caption is None:
487
+ f_caption = f"{get_name(files.file_name)}"
488
+
489
+ try:
490
+ if AUTH_CHANNEL and not await is_subscribed(client, query):
491
+ return await query.answer(url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{file_id}'))
492
+
493
+ k = await client.send_cached_media(
494
+ chat_id=query.from_user.id,
495
+ file_id=file_id,
496
+ caption=f_caption,
497
+ protect_content=ident == "filep",
498
+ )
499
+ sendmsglist = [k]
500
+ await add_sent_files(query.from_user.id, file_id)
501
+ files = await send_more_files(title)
502
+ if files:
503
+ for file in files[1:]:
504
+ try:
505
+ k = await client.send_cached_media(
506
+ chat_id=query.from_user.id,
507
+ file_id=file.file_id,
508
+ caption=f"<code>{file.file_name}</code>",
509
+ )
510
+ except FloodWait as e:
511
+ await asyncio.sleep(e.x)
512
+ logger.warning(f"Floodwait of {e.x} sec.")
513
+ k = await client.send_cached_media(
514
+ chat_id=query.from_user.id,
515
+ file_id=file.file_id,
516
+ caption=f"<code>{file.file_name}</code>",
517
+ )
518
+ await asyncio.sleep(1)
519
+ sendmsglist.append(k)
520
+ await add_sent_files(query.from_user.id, file.file_id)
521
+
522
+ await query.answer("𝕋𝕙𝕒𝕟𝕜 𝕐𝕠𝕦 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕄𝕖 \n\n⭐Rate Me: <a href='https://t.me/tlgrmcbot?start=spaciousuniversebot-review'>Here</a>")
523
+ kk = await client.send_message(
524
+ chat_id=query.from_user.id,
525
+ text="""
526
+ This Files Will delete in 10min Please Forward To Saved Messages folder before download. \n\nTurned On /notification for get new movie|tv Serieses
527
+ """)
528
+ await asyncio.sleep(600)
529
+ for k in sendmsglist:
530
+ await k.delete()
531
+ sendmsglist = []
532
+ return await kk.delete()
533
+
534
+ except UserIsBlocked:
535
+ await query.answer('Unblock the bot!', show_alert=True)
536
+ except PeerIdInvalid:
537
+ await query.answer(url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{file_id}'))
538
+ except Exception as e:
539
+ await query.answer(url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=REAL-{file_id}'))
540
+
541
+ elif query.data.startswith("checksub"):
542
+ if AUTH_CHANNEL and not await is_subscribed(client, query):
543
+ await query.answer("I Like Your Smartness, But Don't Be Oversmart 😒", show_alert=True)
544
+ return
545
+ ident, file_id = query.data.split("#")
546
+ files_ = await get_file_details(file_id)
547
+ if not files_:
548
+ return await query.answer('No such file exist.')
549
+ files = files_[0]
550
+ title = files.file_name
551
+ size = get_size(files.file_size)
552
+ f_caption = files.caption
553
+ if CUSTOM_FILE_CAPTION:
554
+ try:
555
+ f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
556
+ file_size='' if size is None else size,
557
+ file_caption='' if f_caption is None else f_caption)
558
+ except Exception as e:
559
+ logger.exception(e)
560
+ f_caption = f_caption
561
+ if f_caption is None:
562
+ f_caption = f"{title}"
563
+ await query.answer()
564
+ await client.send_cached_media(
565
+ chat_id=query.from_user.id,
566
+ file_id=file_id,
567
+ caption=f_caption,
568
+ protect_content=ident == 'checksubp',
569
+ )
570
+ elif query.data == "pages":
571
+ await query.answer()
572
+ elif query.data == "start":
573
+ buttons = [[
574
+ InlineKeyboardButton('➕ Add Me To Your Groups ➕',
575
+ url=f'http://t.me/{temp.U_NAME}?startgroup=true')
576
+ ], [
577
+ InlineKeyboardButton(
578
+ '🔍 Search', switch_inline_query_current_chat=''),
579
+ InlineKeyboardButton('🤖 Updates', url='https://t.me/TMWAD')
580
+ ], [
581
+ InlineKeyboardButton('ℹ️ Help', callback_data='help'),
582
+ InlineKeyboardButton('😊 About', callback_data='about')
583
+ ]]
584
+ reply_markup = InlineKeyboardMarkup(buttons)
585
+ await query.message.edit_text(
586
+ text=script.START_TXT.format(
587
+ query.from_user.mention, temp.U_NAME, temp.B_NAME),
588
+ reply_markup=reply_markup,
589
+
590
+ )
591
+ await query.answer('Piracy Is Crime')
592
+ elif query.data == "help":
593
+ buttons = [[
594
+ InlineKeyboardButton(
595
+ 'Manual Filter', callback_data='manuelfilter'),
596
+ InlineKeyboardButton('Auto Filter', callback_data='autofilter')
597
+ ], [
598
+ InlineKeyboardButton('Connection', callback_data='coct'),
599
+ InlineKeyboardButton('Extra Mods', callback_data='extra')
600
+ ], [
601
+ InlineKeyboardButton('🏠 Home', callback_data='start'),
602
+ InlineKeyboardButton('🔮 Status', callback_data='stats')
603
+ ]]
604
+ reply_markup = InlineKeyboardMarkup(buttons)
605
+ await query.message.edit_text(
606
+ text=script.HELP_TXT.format(query.from_user.mention),
607
+ reply_markup=reply_markup,
608
+
609
+ )
610
+ elif query.data == "about":
611
+ buttons = [[
612
+ InlineKeyboardButton('🤖 Updates', url='https://t.me/TMWAD'),
613
+ InlineKeyboardButton('♥️ Source', callback_data='source')
614
+ ], [
615
+ InlineKeyboardButton('🏠 Home', callback_data='start'),
616
+ InlineKeyboardButton('🔐 Close', callback_data='close_data')
617
+ ]]
618
+ reply_markup = InlineKeyboardMarkup(buttons)
619
+ await query.message.edit_text(
620
+ text=script.ABOUT_TXT.format(temp.B_NAME),
621
+ reply_markup=reply_markup,
622
+
623
+ )
624
+ elif query.data == "source":
625
+ buttons = [[
626
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='about')
627
+ ]]
628
+ reply_markup = InlineKeyboardMarkup(buttons)
629
+ await query.message.edit_text(
630
+ text=script.SOURCE_TXT,
631
+ reply_markup=reply_markup,
632
+
633
+ )
634
+ elif query.data == "manuelfilter":
635
+ buttons = [[
636
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help'),
637
+ InlineKeyboardButton('⏹️ Buttons', callback_data='button')
638
+ ]]
639
+ reply_markup = InlineKeyboardMarkup(buttons)
640
+ await query.message.edit_text(
641
+ text=script.MANUELFILTER_TXT,
642
+ reply_markup=reply_markup,
643
+
644
+ )
645
+ elif query.data == "button":
646
+ buttons = [[
647
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='manuelfilter')
648
+ ]]
649
+ reply_markup = InlineKeyboardMarkup(buttons)
650
+ await query.message.edit_text(
651
+ text=script.BUTTON_TXT,
652
+ reply_markup=reply_markup,
653
+
654
+ )
655
+ elif query.data == "autofilter":
656
+ buttons = [[
657
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help')
658
+ ]]
659
+ reply_markup = InlineKeyboardMarkup(buttons)
660
+ await query.message.edit_text(
661
+ text=script.AUTOFILTER_TXT,
662
+ reply_markup=reply_markup,
663
+
664
+ )
665
+ elif query.data == "coct":
666
+ buttons = [[
667
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help')
668
+ ]]
669
+ reply_markup = InlineKeyboardMarkup(buttons)
670
+ await query.message.edit_text(
671
+ text=script.CONNECTION_TXT,
672
+ reply_markup=reply_markup,
673
+
674
+ )
675
+ elif query.data == "extra":
676
+ buttons = [[
677
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help'),
678
+ InlineKeyboardButton('👮‍♂️ Admin', callback_data='admin')
679
+ ]]
680
+ reply_markup = InlineKeyboardMarkup(buttons)
681
+ await query.message.edit_text(
682
+ text=script.EXTRAMOD_TXT,
683
+ reply_markup=reply_markup,
684
+
685
+ )
686
+ elif query.data == "admin":
687
+ buttons = [[
688
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='extra')
689
+ ]]
690
+ reply_markup = InlineKeyboardMarkup(buttons)
691
+ await query.message.edit_text(
692
+ text=script.ADMIN_TXT,
693
+ reply_markup=reply_markup,
694
+
695
+ )
696
+ elif query.data == "stats":
697
+ buttons = [[
698
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help'),
699
+ InlineKeyboardButton('♻️', callback_data='rfrsh')
700
+ ]]
701
+ reply_markup = InlineKeyboardMarkup(buttons)
702
+ total = await Media.count_documents()
703
+ users = await db.total_users_count()
704
+ chats = await db.total_chat_count()
705
+ monsize = await db.get_db_size()
706
+ free = 536870912 - monsize
707
+ monsize = get_size(monsize)
708
+ free = get_size(free)
709
+ await query.message.edit_text(
710
+ text=script.STATUS_TXT.format(total, users, chats, monsize, free),
711
+ reply_markup=reply_markup,
712
+
713
+ )
714
+ elif query.data == "rfrsh":
715
+ await query.answer("Fetching MongoDb DataBase")
716
+ buttons = [[
717
+ InlineKeyboardButton('👩‍🦯 Back', callback_data='help'),
718
+ InlineKeyboardButton('♻️', callback_data='rfrsh')
719
+ ]]
720
+ reply_markup = InlineKeyboardMarkup(buttons)
721
+ total = await Media.count_documents()
722
+ users = await db.total_users_count()
723
+ chats = await db.total_chat_count()
724
+ monsize = await db.get_db_size()
725
+ free = 536870912 - monsize
726
+ monsize = get_size(monsize)
727
+ free = get_size(free)
728
+ await query.message.edit_text(
729
+ text=script.STATUS_TXT.format(total, users, chats, monsize, free),
730
+ reply_markup=reply_markup,
731
+
732
+ )
733
+ elif query.data.startswith("setgs"):
734
+ ident, set_type, status, grp_id = query.data.split("#")
735
+ grpid = await active_connection(str(query.from_user.id))
736
+
737
+ if str(grp_id) != str(grpid):
738
+ await query.message.edit("Your Active Connection Has Been Changed. Go To /settings.")
739
+ return await query.answer('Piracy Is Crime')
740
+
741
+ if status == "True":
742
+ await save_group_settings(grpid, set_type, False)
743
+ else:
744
+ await save_group_settings(grpid, set_type, True)
745
+
746
+ settings = await get_settings(grpid)
747
+
748
+ if settings is not None:
749
+ buttons = [
750
+ [
751
+ InlineKeyboardButton('Filter Button',
752
+ callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}'),
753
+ InlineKeyboardButton('Single' if settings["button"] else 'Double',
754
+ callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}')
755
+ ],
756
+ [
757
+ InlineKeyboardButton(
758
+ 'Bot PM', callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}'),
759
+ InlineKeyboardButton('✅ Yes' if settings["botpm"] else '❌ No',
760
+ callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}')
761
+ ],
762
+ [
763
+ InlineKeyboardButton('File Secure',
764
+ callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}'),
765
+ InlineKeyboardButton('✅ Yes' if settings["file_secure"] else '❌ No',
766
+ callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}')
767
+ ],
768
+ [
769
+ InlineKeyboardButton(
770
+ 'IMDB', callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}'),
771
+ InlineKeyboardButton('✅ Yes' if settings["imdb"] else '❌ No',
772
+ callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}')
773
+ ],
774
+ [
775
+ InlineKeyboardButton('Spell Check',
776
+ callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}'),
777
+ InlineKeyboardButton('✅ Yes' if settings["spell_check"] else '❌ No',
778
+ callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}')
779
+ ],
780
+ [
781
+ InlineKeyboardButton(
782
+ 'Welcome', callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}'),
783
+ InlineKeyboardButton('✅ Yes' if settings["welcome"] else '❌ No',
784
+ callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}')
785
+ ]
786
+ ]
787
+ reply_markup = InlineKeyboardMarkup(buttons)
788
+ await query.message.edit_reply_markup(reply_markup)
789
+ await query.answer('Piracy Is Crime')
790
+
791
+
792
+ async def auto_filter(client, msg, spoll=False):
793
+
794
+ if not spoll:
795
+ message = msg
796
+ if message.text.startswith("/"):
797
+ return # ignore commands
798
+ if re.findall("((^\/|^,|^!|^\.|^[\U0001F600-\U000E007F]).*)", message.text):
799
+ return
800
+ if 2 < len(message.text) < 100:
801
+ search = message.text
802
+ files, offset, total_results = await get_search_results(search.lower(), offset=0, filter=True)
803
+ if not files:
804
+ return await advantage_spell_chok(msg)
805
+
806
+ else:
807
+ return
808
+ else:
809
+ message = msg.message.reply_to_message # msg will be callback query
810
+ search, files, offset, total_results = spoll
811
+
812
+ fileids = [file.file_id for file in files]
813
+ dbid = fileids[0]
814
+ fileids = "L_I_N_K".join(fileids)
815
+
816
+ btn = [
817
+ [
818
+ InlineKeyboardButton(
819
+ text=f"{get_size(file.file_size)} ║ {get_name(file.file_name)}", url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=FEND-{file.file_id}')
820
+ ),
821
+ ]
822
+ for file in files
823
+ ]
824
+ btn.insert(0,
825
+ [InlineKeyboardButton(
826
+ "◈ All Files ◈", url=gen_url(f'https://telegram.dog/SpaciousUniverseBot?start=FEND-{dbid}'))]
827
+ )
828
+
829
+ if offset != "":
830
+ key = f"{message.chat.id}-{message.id}"
831
+ BUTTONS[key] = search
832
+ req = message.from_user.id if message.from_user else 0
833
+ btn.append(
834
+ [InlineKeyboardButton(text=f"❏ 1/{round(int(total_results) / 10)}", callback_data="pages"),
835
+ InlineKeyboardButton(text="Next ►", callback_data=f"next_{req}_{key}_{offset}")]
836
+ )
837
+
838
+ else:
839
+ btn.append(
840
+ [InlineKeyboardButton(text="❏ 1/1", callback_data="pages")]
841
+ )
842
+
843
+ imdb = await get_poster(message.text)
844
+ if message.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
845
+ Template = await get_admingroup(int(message.chat.id))
846
+ if Template is not None:
847
+ IMDB_TEMPLATE = Template["template"]
848
+
849
+ if imdb:
850
+ cap = IMDB_TEMPLATE.format(
851
+ query=search,
852
+ title=imdb['title'],
853
+ votes=imdb['votes'],
854
+ aka=imdb["aka"],
855
+ seasons=imdb["seasons"],
856
+ box_office=imdb['box_office'],
857
+ localized_title=imdb['localized_title'],
858
+ kind=imdb['kind'],
859
+ imdb_id=imdb["imdb_id"],
860
+ cast=imdb["cast"],
861
+ runtime=imdb["runtime"],
862
+ countries=imdb["countries"],
863
+ certificates=imdb["certificates"],
864
+ languages=imdb["languages"],
865
+ director=imdb["director"],
866
+ writer=imdb["writer"],
867
+ producer=imdb["producer"],
868
+ composer=imdb["composer"],
869
+ cinematographer=imdb["cinematographer"],
870
+ music_team=imdb["music_team"],
871
+ distributors=imdb["distributors"],
872
+ release_date=imdb['release_date'],
873
+ year=imdb['year'],
874
+ genres=imdb['genres'],
875
+ poster=imdb['poster'],
876
+ plot=imdb['plot'],
877
+ rating=imdb['rating'],
878
+ url=imdb['url'],
879
+ **locals()
880
+ )
881
+ else:
882
+ cap = f"Here is what i found for your query {search}"
883
+ if imdb and imdb.get('poster'):
884
+ try:
885
+ await message.reply_photo(photo=imdb.get('poster'), caption=cap[:1024],
886
+ reply_markup=InlineKeyboardMarkup(btn))
887
+ except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
888
+ pic = imdb.get('poster')
889
+ poster = pic.replace('.jpg', "._V1_UX360.jpg")
890
+ await message.reply_photo(photo=poster, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btn))
891
+ except Exception as e:
892
+ logger.exception(e)
893
+ else:
894
+ await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btn))
895
+ if spoll:
896
+ await msg.message.delete()
897
+
898
+
899
+ async def pm_auto_filter(client, msg, spoll=False):
900
+ if not spoll:
901
+ message = msg
902
+ if message.text.startswith("/"):
903
+ return # ignore commands
904
+ if re.findall("((^\/|^,|^!|^\.|^[\U0001F600-\U000E007F]).*)", message.text):
905
+ return
906
+ if 2 < len(message.text) < 100:
907
+ search = message.text
908
+ files, offset, total_results = await get_search_results(search.lower(), offset=0, filter=True)
909
+ if not files:
910
+ return await advantage_spell_chok(msg)
911
+
912
+ else:
913
+ return
914
+ else:
915
+ message = msg.message.reply_to_message # msg will be callback query
916
+ search, files, offset, total_results = spoll
917
+
918
+ fileids = [file.file_id for file in files]
919
+ dbid = fileids[0]
920
+ fileids = "L_I_N_K".join(fileids)
921
+
922
+ btn = [
923
+ [
924
+ InlineKeyboardButton(
925
+ text=f"{get_size(file.file_size)} ║ {get_name(file.file_name)}", callback_data=f'pmfiles#{file.file_id}'
926
+ ),
927
+ ]
928
+ for file in files
929
+ ]
930
+
931
+ if offset != "":
932
+ key = f"{message.chat.id}-{message.id}"
933
+ BUTTONS[key] = search
934
+ req = message.from_user.id if message.from_user else 0
935
+ btn.append(
936
+ [InlineKeyboardButton(text=f"❏ 1/{round(int(total_results) / 10)}", callback_data="pages"),
937
+ InlineKeyboardButton(text="Next ►", callback_data=f"pmnext_{req}_{key}_{offset}")]
938
+ )
939
+ btn.insert(0,
940
+ [InlineKeyboardButton(
941
+ "◈ All Files ◈", callback_data=f'pmfiles#{dbid}')]
942
+ )
943
+
944
+ else:
945
+ btn.append(
946
+ [InlineKeyboardButton(text="❏ 1/1", callback_data="pages")]
947
+ )
948
+ btn.insert(0,
949
+ [InlineKeyboardButton(
950
+ "◈ All Files ◈", callback_data=f'pmfiles#{dbid}')]
951
+ )
952
+
953
+ imdb = await get_poster(message.text)
954
+ if imdb:
955
+ cap = IMDB_TEMPLATE.format(
956
+ query=search,
957
+ title=imdb['title'],
958
+ votes=imdb['votes'],
959
+ aka=imdb["aka"],
960
+ seasons=imdb["seasons"],
961
+ box_office=imdb['box_office'],
962
+ localized_title=imdb['localized_title'],
963
+ kind=imdb['kind'],
964
+ imdb_id=imdb["imdb_id"],
965
+ cast=imdb["cast"],
966
+ runtime=imdb["runtime"],
967
+ countries=imdb["countries"],
968
+ certificates=imdb["certificates"],
969
+ languages=imdb["languages"],
970
+ director=imdb["director"],
971
+ writer=imdb["writer"],
972
+ producer=imdb["producer"],
973
+ composer=imdb["composer"],
974
+ cinematographer=imdb["cinematographer"],
975
+ music_team=imdb["music_team"],
976
+ distributors=imdb["distributors"],
977
+ release_date=imdb['release_date'],
978
+ year=imdb['year'],
979
+ genres=imdb['genres'],
980
+ poster=imdb['poster'],
981
+ plot=imdb['plot'],
982
+ rating=imdb['rating'],
983
+ url=imdb['url'],
984
+ **locals()
985
+ )
986
+ else:
987
+ cap = f"Here is what i found for your query {search}"
988
+ if imdb and imdb.get('poster'):
989
+ try:
990
+ await message.reply_photo(photo=imdb.get('poster'), caption=cap[:1024],
991
+ reply_markup=InlineKeyboardMarkup(btn))
992
+ except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
993
+ pic = imdb.get('poster')
994
+ poster = pic.replace('.jpg', "._V1_UX360.jpg")
995
+ await message.reply_photo(photo=poster, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btn))
996
+ except Exception as e:
997
+ logger.exception(e)
998
+ else:
999
+ await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btn))
1000
+ if spoll:
1001
+ await msg.message.delete()
1002
+
1003
+
1004
+ async def advantage_spell_chok(msg):
1005
+ query = re.sub(
1006
+ 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)?)",
1007
+ "", msg.text, flags=re.IGNORECASE) # plis contribute some common words
1008
+ query = query.strip() + " movie"
1009
+ g_s = await search_gagala(query)
1010
+ g_s += await search_gagala(msg.text)
1011
+ gs_parsed = []
1012
+ if not g_s:
1013
+ k = await msg.reply("I couldn't find any movie in that name.")
1014
+ await asyncio.sleep(8)
1015
+ await k.delete()
1016
+ return
1017
+ # look for imdb / wiki results
1018
+ regex = re.compile(r".*(imdb|wikipedia).*", re.IGNORECASE)
1019
+ gs = list(filter(regex.match, g_s))
1020
+ gs_parsed = [re.sub(
1021
+ r'\b(\-([a-zA-Z-\s])\-\simdb|(\-\s)?imdb|(\-\s)?wikipedia|\(|\)|\-|reviews|full|all|episode(s)?|film|movie|series)',
1022
+ '', i, flags=re.IGNORECASE) for i in gs]
1023
+ if not gs_parsed:
1024
+ reg = re.compile(r"watch(\s[a-zA-Z0-9_\s\-\(\)]*)*\|.*",
1025
+ re.IGNORECASE) # match something like Watch Niram | Amazon Prime
1026
+ for mv in g_s:
1027
+ match = reg.match(mv)
1028
+ if match:
1029
+ gs_parsed.append(match.group(1))
1030
+ user = msg.from_user.id if msg.from_user else 0
1031
+ movielist = []
1032
+ # removing duplicates https://stackoverflow.com/a/7961425
1033
+ gs_parsed = list(dict.fromkeys(gs_parsed))
1034
+ if len(gs_parsed) > 3:
1035
+ gs_parsed = gs_parsed[:3]
1036
+ if gs_parsed:
1037
+ for mov in gs_parsed:
1038
+ # searching each keyword in imdb
1039
+ try:
1040
+ imdb_s = await get_poster(mov.strip(), bulk=True)
1041
+ except:
1042
+ continue
1043
+ if imdb_s:
1044
+ movielist += [movie.get('title') for movie in imdb_s]
1045
+ movielist += [(re.sub(r'(\-|\(|\)|_)', '', i, flags=re.IGNORECASE)).strip()
1046
+ for i in gs_parsed]
1047
+ movielist = list(dict.fromkeys(movielist)) # removing duplicates
1048
+ if not movielist:
1049
+ name = msg.text
1050
+ name = name.replace(" ", "%20")
1051
+ btns = [
1052
+ [
1053
+ InlineKeyboardButton(
1054
+ text="Check Spelling On Google 🧩", url=f"https://www.google.com/search?q={name}")
1055
+ ],
1056
+ [
1057
+ InlineKeyboardButton(
1058
+ text="IMDB 💠", url=f"https://www.imdb.com/find?q={name}"),
1059
+ InlineKeyboardButton(
1060
+ text="Wikipedia 💠", url=f"https://en.m.wikipedia.org/w/index.php?search={name}")
1061
+ ]
1062
+ ]
1063
+ try:
1064
+ k = await msg.reply(
1065
+ text="I couldn't find anything related to that.Please Check your spelling",
1066
+ reply_markup=InlineKeyboardMarkup(btns),
1067
+ disable_web_page_preview=True,
1068
+ )
1069
+ except Exception as e:
1070
+ logger.exception(e)
1071
+ k = await msg.reply(
1072
+ text="I couldn't find anything related to that.Please Check your spelling",
1073
+ disable_web_page_preview=True,
1074
+ )
1075
+ await asyncio.sleep(30)
1076
+ await k.delete()
1077
+ return
1078
+ SPELL_CHECK[msg.id] = movielist
1079
+ btn = [[
1080
+ InlineKeyboardButton(
1081
+ text=movie.strip(),
1082
+ callback_data=f"spolling#{user}#{k}",
1083
+ )
1084
+ ] for k, movie in enumerate(movielist)]
1085
+ btn.append([InlineKeyboardButton(
1086
+ text="Close", callback_data=f'spolling#{user}#close_spellcheck')])
1087
+ await msg.reply("I couldn't find anything related to that\nDid you mean any one of these?",
1088
+ reply_markup=InlineKeyboardMarkup(btn))
1089
+
1090
+
1091
+ async def manual_filters(client, message, text=False):
1092
+ group_id = message.chat.id
1093
+ name = text or message.text
1094
+ reply_id = message.reply_to_message.id if message.reply_to_message else message.id
1095
+ keywords = await get_filters(group_id)
1096
+ for keyword in reversed(sorted(keywords, key=len)):
1097
+ pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
1098
+ if re.search(pattern, name, flags=re.IGNORECASE):
1099
+ reply_text, btn, alert, fileid = await find_filter(group_id, keyword)
1100
+
1101
+ if reply_text:
1102
+ reply_text = reply_text.replace(
1103
+ "\\n", "\n").replace("\\t", "\t")
1104
+
1105
+ elif btn is not None:
1106
+ if reply_text is None:
1107
+ break
1108
+ try:
1109
+ if fileid == "None":
1110
+ if btn == "[]":
1111
+ await client.send_message(group_id, reply_text, disable_web_page_preview=True)
1112
+ else:
1113
+ button = eval(btn)
1114
+ await client.send_message(
1115
+ group_id,
1116
+ reply_text,
1117
+ disable_web_page_preview=True,
1118
+ reply_markup=InlineKeyboardMarkup(button),
1119
+ reply_to_message_id=reply_id
1120
+ )
1121
+ elif btn == "[]":
1122
+ await client.send_cached_media(
1123
+ group_id,
1124
+ fileid,
1125
+ caption=reply_text or "",
1126
+ reply_to_message_id=reply_id
1127
+ )
1128
+ else:
1129
+ button = eval(btn)
1130
+ await message.reply_cached_media(
1131
+ fileid,
1132
+ caption=reply_text or "",
1133
+ reply_markup=InlineKeyboardMarkup(button),
1134
+ reply_to_message_id=reply_id
1135
+ )
1136
+ except Exception as e:
1137
+ logger.exception(e)
1138
+ break
1139
+ else:
1140
+ return False
1141
+
1142
+
1143
+ async def tvseries_filters(client, message, text=False):
1144
+ name = getseries(message.text)
1145
+ if len(name) < 3:
1146
+ return False
1147
+
1148
+ elif name:
1149
+ seriess = await find_tvseries_filter(name)
1150
+
1151
+ if len(seriess) > 4:
1152
+ return False
1153
+ else:
1154
+ return False
1155
+
1156
+ if seriess:
1157
+ btns = [[InlineKeyboardButton(
1158
+ text=f"{name.capitalize()} TV Series", callback_data="pages")]]
1159
+ for series in seriess:
1160
+ language = series['language']
1161
+ quality = series['quality']
1162
+ links = series['seasonlink']
1163
+ links = links.split(",")
1164
+
1165
+ btn = [[InlineKeyboardButton(text=f'Season {link + 1}', url=links[link]), InlineKeyboardButton(
1166
+ text=f'Season {link + 2}', url=links[link + 1])] for link in range(len(links) - 1) if link % 2 != 1]
1167
+ if len(links) % 2 == 1:
1168
+ btn.append([InlineKeyboardButton(
1169
+ text=f'Season {len(links)}', url=links[-1])])
1170
+
1171
+ btn.insert(0,
1172
+ [InlineKeyboardButton(
1173
+ text=f"{language} - {quality}", callback_data="pages")]
1174
+ )
1175
+ btns.extend(btn)
1176
+
1177
+ imdb = await get_poster(message.text)
1178
+ if message.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
1179
+ Template = await get_admingroup(int(message.chat.id))
1180
+ if Template is not None:
1181
+ IMDB_TEMPLATE = Template["template"]
1182
+
1183
+ if imdb:
1184
+ cap = IMDB_TEMPLATE.format(
1185
+ title=imdb['title'],
1186
+ votes=imdb['votes'],
1187
+ aka=imdb["aka"],
1188
+ seasons=imdb["seasons"],
1189
+ box_office=imdb['box_office'],
1190
+ localized_title=imdb['localized_title'],
1191
+ kind=imdb['kind'],
1192
+ imdb_id=imdb["imdb_id"],
1193
+ cast=imdb["cast"],
1194
+ runtime=imdb["runtime"],
1195
+ countries=imdb["countries"],
1196
+ certificates=imdb["certificates"],
1197
+ languages=imdb["languages"],
1198
+ director=imdb["director"],
1199
+ writer=imdb["writer"],
1200
+ producer=imdb["producer"],
1201
+ composer=imdb["composer"],
1202
+ cinematographer=imdb["cinematographer"],
1203
+ music_team=imdb["music_team"],
1204
+ distributors=imdb["distributors"],
1205
+ release_date=imdb['release_date'],
1206
+ year=imdb['year'],
1207
+ genres=imdb['genres'],
1208
+ poster=imdb['poster'],
1209
+ plot=imdb['plot'],
1210
+ rating=imdb['rating'],
1211
+ url=imdb['url'],
1212
+ **locals()
1213
+ )
1214
+ if imdb.get('poster'):
1215
+ try:
1216
+ if not os.path.isdir(DOWNLOAD_LOCATION):
1217
+ os.makedirs(DOWNLOAD_LOCATION)
1218
+ pic = imdb.get('poster')
1219
+ urllib.request.urlretrieve(pic, "gfg.png")
1220
+ im = Image.open("gfg.png")
1221
+ width, height = im.size
1222
+ left = 0
1223
+ right = width
1224
+ top = height / 5
1225
+ bottom = height * 3 / 5
1226
+ pic = im.crop((left, top, right, bottom))
1227
+ img_location = DOWNLOAD_LOCATION + "tvseries" + ".png"
1228
+ pic.save(img_location)
1229
+
1230
+ except Exception as e:
1231
+ logger.exception(e)
1232
+ pic = imdb.get('poster')
1233
+
1234
+ try:
1235
+ await message.reply_photo(photo=img_location, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btns))
1236
+ except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
1237
+ poster = img_location.replace('.jpg', "._V1_UX360.jpg")
1238
+ await message.reply_photo(photo=poster, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btns))
1239
+ except Exception as e:
1240
+ logger.exception(e)
1241
+ cap = "Here is what i found for your Request"
1242
+ await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btns))
1243
+
1244
+ os.remove(img_location)
1245
+ else:
1246
+ cap = "Here is what i found for your Request"
1247
+ await message.reply_text(cap, reply_markup=InlineKeyboardMarkup(btns))
1248
+
1249
+ else:
1250
+ return False