Update plugins/admin_control.py
Browse files- plugins/admin_control.py +216 -92
plugins/admin_control.py
CHANGED
@@ -14,50 +14,46 @@ import logging, re, asyncio, time, shutil, psutil, os, sys
|
|
14 |
logger = logging.getLogger(__name__)
|
15 |
logger.setLevel(logging.ERROR)
|
16 |
|
17 |
-
|
18 |
-
@Client.on_message(filters.new_chat_members & filters.group)
|
19 |
-
async def savegroup_and_welcome(bot, message):
|
20 |
-
r_j_check = [u.id for u in message.new_chat_members]
|
21 |
-
if bot.id in r_j_check:
|
22 |
-
if not await db.get_chat(message.chat.id):
|
23 |
-
total=await bot.get_chat_members_count(message.chat.id)
|
24 |
-
r_j = message.from_user.mention if message.from_user else "Anonymous"
|
25 |
-
await bot.send_message(LOG_CHANNEL, script.LOG_TEXT_G.format(a=message.chat.title, b=message.chat.id, c=message.chat.username, d=total, e=r_j, f=bot.mention))
|
26 |
-
await db.add_chat(message.chat.id, message.chat.title, message.chat.username)
|
27 |
-
if message.chat.id in temp.BANNED_CHATS:
|
28 |
-
buttons = [[InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url=f'https://t.me/{SUPPORT_CHAT}')]]
|
29 |
-
k = await message.reply("CHAT NOT ALLOWED 🐞\n\nMʏ Aᴅᴍɪɴs Hᴀs Rᴇsᴛʀɪᴄᴛᴇᴅ Mᴇ Fʀᴏᴍ Wᴏʀᴋɪɴɢ Hᴇʀᴇ ! Iғ Yᴏᴜ Wᴀɴᴛ Tᴏ Kɴᴏᴡ Mᴏʀᴇ Aʙᴏᴜᴛ Iᴛ Cᴏɴᴛᴀᴄᴛ Sᴜᴘᴘᴏʀᴛ", reply_markup=InlineKeyboardMarkup(buttons))
|
30 |
-
try: await k.pin()
|
31 |
-
except: pass
|
32 |
-
return await bot.leave_chat(message.chat.id)
|
33 |
-
|
34 |
-
buttons = [[InlineKeyboardButton('Hᴇʟᴩ', url=f"https://t.me/{temp.U_NAME}?start=help")]]
|
35 |
-
await message.reply(text="❤️ Tʜᴀɴᴋs Tᴏ Aᴅᴅ Mᴇ Tᴏ Yᴏᴜ'ʀ Gʀᴏᴜᴘ.\n» Dᴏɴ'ᴛ Fᴏʀɢᴇᴛ Tᴏ Mᴀᴋᴇ Mᴇ Aᴅᴍɪɴ.\n» Is Aɴʏ Dᴏᴜʙᴛ's Aʙᴏᴜᴛ Usɪɴɢ Mᴇ Cʟɪᴄᴋ Bᴇʟᴏᴡ Bᴜᴛᴛᴏɴ...✨", reply_markup=InlineKeyboardMarkup(buttons))
|
36 |
-
else:
|
37 |
-
for u in message.new_chat_members:
|
38 |
-
if (temp.MELCOW).get('welcome') is not None:
|
39 |
-
try: await (temp.MELCOW['welcome']).delete()
|
40 |
-
except: pass
|
41 |
-
if WELCOM_PIC: temp.MELCOW['welcome'] = await message.reply_photo(photo=WELCOM_PIC, caption=WELCOM_TEXT.format(user=u.mention, chat=message.chat.title))
|
42 |
-
else: temp.MELCOW['welcome'] = await message.reply_text(text=WELCOM_TEXT.format(user=u.mention, chat=message.chat.title))
|
43 |
-
|
44 |
-
|
45 |
@Client.on_message(filters.command('leave') & filters.user(ADMINS))
|
46 |
async def leave_a_chat(bot, message):
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
chat = message.command[1]
|
49 |
-
try:
|
50 |
-
|
|
|
|
|
|
|
51 |
try:
|
52 |
buttons = [[InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url=f'https://t.me/{SUPPORT_CHAT}')]]
|
53 |
-
await bot.send_message(chat_id=chat, text='<b>Hᴇʟʟᴏ Fʀɪᴇɴᴅs, \nMʏ Aᴅᴍɪɴ Hᴀs
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
except Exception as e:
|
56 |
-
|
|
|
57 |
|
58 |
@Client.on_message(filters.command('disable') & filters.user(ADMINS))
|
59 |
async def disable_chat(bot, message):
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
r = message.text.split(None)
|
62 |
if len(r) > 2:
|
63 |
reason = message.text.split(None, 2)[2]
|
@@ -68,40 +64,63 @@ async def disable_chat(bot, message):
|
|
68 |
try:
|
69 |
chat_ = int(chat)
|
70 |
except:
|
|
|
71 |
return await message.reply('Gɪᴠᴇ Mᴇ A Vᴀʟɪᴅ Cʜᴀᴛ ID')
|
72 |
cha_t = await db.get_chat(int(chat_))
|
73 |
if not cha_t:
|
|
|
74 |
return await message.reply("Cʜᴀᴛ Nᴏᴛ Fᴏᴜɴᴅ Iɴ DB")
|
75 |
if cha_t['is_disabled']:
|
|
|
76 |
return await message.reply(f"Tʜɪꜱ Cʜᴀᴛ Is Aʟʀᴇᴅʏ Dɪꜱᴀʙʟᴇᴅ:\nRᴇᴀꜱᴏɴ: <code> {cha_t['reason']} </code>")
|
77 |
await db.disable_chat(int(chat_), reason)
|
78 |
temp.BANNED_CHATS.append(int(chat_))
|
79 |
await message.reply('Cʜᴀᴛ Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Dɪꜱᴀʙʟᴇᴅ')
|
|
|
80 |
try:
|
81 |
buttons = [[InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url=f'https://t.me/{SUPPORT_CHAT}')]]
|
82 |
await bot.send_message(chat_id=chat_, text=f'<b>Hᴇʟʟᴏ Fʀɪᴇɴᴅs, \nᴍʏ Aᴅᴍɪɴ Hᴀs Tᴏʟᴅ Mᴇ Tᴏ Lᴇᴀᴠᴇ Fʀᴏᴍ Gʀᴏᴜᴘ Sᴏ I Gᴏ! Iғ Yᴏᴜ Wᴀɴɴᴀ Aᴅᴅ Mᴇ Aɢᴀɪɴ Cᴏɴᴛᴀᴄᴛ Mʏ Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ.</b> \nRᴇᴀꜱᴏɴ : <code>{reason}</code>', reply_markup=InlineKeyboardMarkup(buttons))
|
83 |
await bot.leave_chat(chat_)
|
|
|
84 |
except Exception as e:
|
|
|
85 |
await message.reply(f"Eʀʀᴏʀ: {e}")
|
86 |
|
87 |
-
|
88 |
@Client.on_message(filters.command('enable') & filters.user(ADMINS))
|
89 |
async def re_enable_chat(bot, message):
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
chat = message.command[1]
|
92 |
-
try:
|
93 |
-
|
|
|
|
|
|
|
94 |
sts = await db.get_chat(int(chat))
|
95 |
-
if not sts:
|
|
|
|
|
96 |
if not sts.get('is_disabled'):
|
|
|
97 |
return await message.reply('Tʜɪꜱ Cʜᴀᴛ Iꜱ Nᴏᴛ Yᴇᴛ Dɪꜱᴀʙʟᴇᴅ')
|
98 |
await db.re_enable_chat(int(chat_))
|
99 |
temp.BANNED_CHATS.remove(int(chat_))
|
100 |
await message.reply("Cʜᴀᴛ Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Rᴇ-Eɴᴀʙʟᴇᴅ")
|
101 |
-
|
102 |
|
103 |
@Client.on_message(filters.command('stats') & filters.incoming)
|
104 |
async def get_ststs(bot, message):
|
|
|
|
|
|
|
|
|
|
|
105 |
rju = await message.reply('<b>Pʟᴇᴀꜱᴇ Wᴀɪᴛ...</b>')
|
106 |
total_users = await db.total_users_count()
|
107 |
totl_chats = await db.total_chat_count()
|
@@ -111,25 +130,46 @@ async def get_ststs(bot, message):
|
|
111 |
size = get_size(size)
|
112 |
free = get_size(free)
|
113 |
await rju.edit(script.STATUS_TXT.format(files, total_users, totl_chats, size, free))
|
114 |
-
|
115 |
|
116 |
@Client.on_message(filters.command('invite') & filters.user(ADMINS))
|
117 |
async def gen_invite(bot, message):
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
chat = message.command[1]
|
120 |
-
try:
|
121 |
-
|
|
|
|
|
|
|
122 |
try:
|
123 |
-
link = await bot.create_chat_invite_link(
|
|
|
124 |
except ChatAdminRequired:
|
125 |
-
|
|
|
126 |
except Exception as e:
|
|
|
127 |
return await message.reply(f'Eʀʀᴏʀ: {e}')
|
128 |
await message.reply(f'Hᴇʀᴇ Iꜱ Yᴏᴜʀ Iɴᴠɪᴛᴇ Lɪɴᴋ: {link.invite_link}')
|
|
|
129 |
|
130 |
@Client.on_message(filters.command('ban_user') & filters.user(ADMINS))
|
131 |
async def ban_a_user(bot, message):
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
r = message.text.split(None)
|
134 |
if len(r) > 2:
|
135 |
reason = message.text.split(None, 2)[2]
|
@@ -137,24 +177,42 @@ async def ban_a_user(bot, message):
|
|
137 |
else:
|
138 |
chat = message.command[1]
|
139 |
reason = "No reason Provided"
|
140 |
-
try:
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
else:
|
147 |
jar = await db.get_ban_status(k.id)
|
148 |
-
if jar['is_banned']:
|
|
|
|
|
149 |
await db.ban_user(k.id, reason)
|
150 |
temp.BANNED_USERS.append(k.id)
|
151 |
await message.reply(f"Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Bᴀɴɴᴇᴅ {k.mention}")
|
|
|
152 |
|
153 |
-
|
154 |
-
|
155 |
@Client.on_message(filters.command('unban_user') & filters.user(ADMINS))
|
156 |
async def unban_a_user(bot, message):
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
r = message.text.split(None)
|
159 |
if len(r) > 2:
|
160 |
reason = message.text.split(None, 2)[2]
|
@@ -162,23 +220,39 @@ async def unban_a_user(bot, message):
|
|
162 |
else:
|
163 |
chat = message.command[1]
|
164 |
reason = "No reason Provided"
|
165 |
-
try:
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
else:
|
172 |
jar = await db.get_ban_status(k.id)
|
173 |
-
if not jar['is_banned']:
|
|
|
|
|
174 |
await db.remove_ban(k.id)
|
175 |
temp.BANNED_USERS.remove(k.id)
|
176 |
await message.reply(f"Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Uɴʙᴀɴɴᴇᴅ {k.mention}")
|
|
|
177 |
|
178 |
-
|
179 |
-
|
180 |
@Client.on_message(filters.command('users') & filters.user(ADMINS))
|
181 |
async def list_users(bot, message):
|
|
|
|
|
|
|
|
|
|
|
182 |
sps = await message.reply('Gᴇᴛᴛɪɴɢ Lɪꜱᴛ Oꜰ Uꜱᴇʀꜱ')
|
183 |
users = await db.get_all_users()
|
184 |
out = "Uꜱᴇʀꜱ Sᴀᴠᴇᴅ Iɴ DB Aʀᴇ:\n\n"
|
@@ -186,13 +260,21 @@ async def list_users(bot, message):
|
|
186 |
out += f"<a href=tg://user?id={user['id']}>{user['name']}</a>\n"
|
187 |
try:
|
188 |
await sps.edit_text(out)
|
|
|
189 |
except MessageTooLong:
|
190 |
with open('users.txt', 'w+') as outfile:
|
191 |
outfile.write(out)
|
192 |
await message.reply_document('users.txt', caption="Lɪꜱᴛ Oꜰ Uꜱᴇʀꜱ")
|
|
|
|
|
193 |
|
194 |
@Client.on_message(filters.command('chats') & filters.user(ADMINS))
|
195 |
async def list_chats(bot, message):
|
|
|
|
|
|
|
|
|
|
|
196 |
sps = await message.reply('Gᴇᴛᴛɪɴɢ Lɪꜱᴛ Oꜰ Cʜᴀᴛꜱ')
|
197 |
chats = await db.get_all_chats()
|
198 |
out = "Cʜᴀᴛꜱ Sᴀᴠᴇᴅ Iɴ DB Aʀᴇ:\n\n"
|
@@ -202,15 +284,21 @@ async def list_chats(bot, message):
|
|
202 |
out += f"**- Tɪᴛʟᴇ:** `{chat['title']}`\n**- ID:** `{chat['id']}`\n**Uꜱᴇʀɴᴀᴍᴇ:** {username}\n"
|
203 |
try:
|
204 |
await sps.edit_text(out)
|
|
|
205 |
except MessageTooLong:
|
206 |
with open('chats.txt', 'w+') as outfile:
|
207 |
outfile.write(out)
|
208 |
await message.reply_document('chats.txt', caption="Lɪꜱᴛ Oꜰ Cʜᴀᴛꜱ")
|
|
|
|
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
@Client.on_message(filters.command('id'))
|
213 |
async def show_id(client, message):
|
|
|
|
|
|
|
|
|
|
|
214 |
chat_type = message.chat.type
|
215 |
if chat_type == enums.ChatType.PRIVATE:
|
216 |
user_id = message.chat.id
|
@@ -219,11 +307,10 @@ async def show_id(client, message):
|
|
219 |
username = message.from_user.username
|
220 |
dc_id = message.from_user.dc_id or ""
|
221 |
await message.reply_text(f"<b>➲ ꜰɪʀꜱᴛ ɴᴀᴍᴇ:</b> {first}\n<b>➲ ʟᴀꜱᴛ ɴᴀᴍᴇ:</b> {last}\n<b>➲ ᴜꜱᴇʀɴᴀᴍᴇ:</b> {username}\n<b>➲ ᴛᴇʟᴇɢʀᴀᴍ ɪᴅ:</b> <code>{user_id}</code>\n<b>➲ ᴅᴄ ɪᴅ:</b> <code>{dc_id}</code>", quote=True)
|
222 |
-
|
223 |
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
|
224 |
_id = ""
|
225 |
_id += f"<b>➲ ᴄʜᴀᴛ ɪᴅ</b>: <code>{message.chat.id}</code>\n"
|
226 |
-
|
227 |
if message.reply_to_message:
|
228 |
_id += (
|
229 |
"<b>➲ ᴜꜱᴇʀ ɪᴅ</b>: "
|
@@ -244,19 +331,27 @@ async def show_id(client, message):
|
|
244 |
f"<code>{file_info.file_id}</code>\n"
|
245 |
)
|
246 |
await message.reply_text(_id, quote=True)
|
247 |
-
|
248 |
|
249 |
@Client.on_message(filters.command(["info"]))
|
250 |
async def user_info(client, message):
|
|
|
|
|
|
|
|
|
|
|
251 |
status_message = await message.reply_text("`ᴩʟᴇᴀꜱᴇ ᴡᴀɪᴛ....`")
|
252 |
from_user = None
|
253 |
from_user_id, _ = extract_user(message)
|
254 |
try:
|
255 |
from_user = await client.get_users(from_user_id)
|
|
|
256 |
except Exception as error:
|
|
|
257 |
return await status_message.edit(str(error))
|
258 |
if from_user is None:
|
259 |
-
|
|
|
260 |
message_out_str = ""
|
261 |
message_out_str += f"<b>➲ꜰɪʀꜱᴛ ɴᴀᴍᴇ:</b> {from_user.first_name}\n"
|
262 |
last_name = from_user.last_name or "<b>ɴᴏɴᴇ</b>"
|
@@ -269,10 +364,13 @@ async def user_info(client, message):
|
|
269 |
message_out_str += f"<b>➲ᴜꜱᴇʀ ʟɪɴᴋ:</b> <a href='tg://user?id={from_user.id}'><b>ᴄʟɪᴄᴋ ʜᴇʀᴇ</b></a>\n"
|
270 |
if message.chat.type in ((enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)):
|
271 |
try:
|
272 |
-
chat_member_p = await message.chat.get_member(
|
273 |
joined_date = (chat_member_p.joined_date or datetime.now()).strftime("%Y.%m.%d %H:%M:%S")
|
274 |
message_out_str += f"<b>➲ᴊᴏɪɴᴇᴅ ᴛʜɪꜱ ᴄʜᴀᴛ ᴏɴ:</b> <code>{joined_date}</code>\n"
|
275 |
-
|
|
|
|
|
|
|
276 |
chat_photo = from_user.photo
|
277 |
if chat_photo:
|
278 |
local_user_photo = await client.download_media(message=chat_photo.big_file_id)
|
@@ -286,6 +384,7 @@ async def user_info(client, message):
|
|
286 |
disable_notification=True
|
287 |
)
|
288 |
os.remove(local_user_photo)
|
|
|
289 |
else:
|
290 |
buttons = [[InlineKeyboardButton('ᴄʟᴏꜱᴇ ✘', callback_data='close_data')]]
|
291 |
await message.reply_text(
|
@@ -295,24 +394,35 @@ async def user_info(client, message):
|
|
295 |
parse_mode=enums.ParseMode.HTML,
|
296 |
disable_notification=True
|
297 |
)
|
298 |
-
|
299 |
|
300 |
@Client.on_message(filters.command(["imdb", 'search']))
|
301 |
async def imdb_search(client, message):
|
|
|
|
|
|
|
|
|
|
|
302 |
if ' ' in message.text:
|
303 |
k = await message.reply('ꜱᴇᴀʀᴄʜɪɴɢ ɪᴍᴅʙ..')
|
304 |
r, title = message.text.split(None, 1)
|
305 |
movies = await get_poster(title, bulk=True)
|
306 |
if not movies:
|
|
|
307 |
return await message.reply("ɴᴏ ʀᴇꜱᴜʟᴛ ꜰᴏᴜɴᴅ")
|
308 |
btn = [[InlineKeyboardButton(f"{movie.get('title')} - {movie.get('year')}", callback_data=f"imdb#{movie.movieID}")] for movie in movies ]
|
309 |
await k.edit('Hᴇʀᴇ Is Wʜᴀᴛ I Fᴏᴜɴᴅ Oɴ Iᴍᴅʙ', reply_markup=InlineKeyboardMarkup(btn))
|
|
|
310 |
else:
|
311 |
-
|
312 |
-
|
313 |
|
314 |
@Client.on_callback_query(filters.regex('^imdb'))
|
315 |
async def imdb_callback(bot: Client, quer_y: CallbackQuery):
|
|
|
|
|
|
|
|
|
316 |
i, movie = quer_y.data.split('#')
|
317 |
imdb = await get_poster(query=movie, id=True)
|
318 |
btn = [[InlineKeyboardButton(f"{imdb.get('title')}", url=imdb['url'])]]
|
@@ -349,39 +459,53 @@ async def imdb_callback(bot: Client, quer_y: CallbackQuery):
|
|
349 |
url = imdb['url'],
|
350 |
**locals()
|
351 |
)
|
|
|
352 |
else:
|
353 |
caption = "ɴᴏ ʀᴇꜱᴜʟᴛꜱ"
|
|
|
|
|
354 |
if imdb.get('poster'):
|
355 |
try:
|
356 |
await quer_y.message.reply_photo(photo=imdb['poster'], caption=caption, reply_markup=InlineKeyboardMarkup(btn))
|
|
|
357 |
except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
|
358 |
pic = imdb.get('poster')
|
359 |
poster = pic.replace('.jpg', "._V1_UX360.jpg")
|
360 |
await quer_y.message.reply_photo(photo=poster, caption=caption, reply_markup=InlineKeyboardMarkup(btn))
|
|
|
361 |
except Exception as e:
|
362 |
-
logger.
|
363 |
await quer_y.message.reply(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
|
|
|
364 |
await quer_y.message.delete()
|
|
|
365 |
else:
|
366 |
await quer_y.message.edit(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
|
367 |
-
|
368 |
-
|
369 |
@Client.on_message(filters.command('logs') & filters.user(ADMINS))
|
370 |
async def log_file(bot, msg):
|
371 |
-
|
372 |
-
|
373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
374 |
|
375 |
@Client.on_message(filters.command("restart") & filters.user(ADMINS))
|
376 |
async def restart_bot(bot, msg):
|
|
|
|
|
|
|
|
|
|
|
377 |
await msg.reply("Rᴇꜱᴛᴀᴛɪɴɢ........")
|
378 |
await asyncio.sleep(2)
|
379 |
await sts.delete()
|
380 |
os.execl(sys.executable, sys.executable, *sys.argv)
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
|
|
14 |
logger = logging.getLogger(__name__)
|
15 |
logger.setLevel(logging.ERROR)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
@Client.on_message(filters.command('leave') & filters.user(ADMINS))
|
18 |
async def leave_a_chat(bot, message):
|
19 |
+
"""
|
20 |
+
Command to make the bot leave a chat.
|
21 |
+
Only accessible to admins.
|
22 |
+
"""
|
23 |
+
logger.info(f"User {message.from_user.id} issued 'leave' command.")
|
24 |
+
if len(message.command) == 1:
|
25 |
+
logger.info("Command incomplete, no chat ID provided.")
|
26 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Cʜᴀᴛ Iᴅ')
|
27 |
chat = message.command[1]
|
28 |
+
try:
|
29 |
+
chat = int(chat)
|
30 |
+
except:
|
31 |
+
logger.info("Invalid chat ID provided.")
|
32 |
+
chat = chat
|
33 |
try:
|
34 |
buttons = [[InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url=f'https://t.me/{SUPPORT_CHAT}')]]
|
35 |
+
await bot.send_message(chat_id=chat, text='<b>Hᴇʟʟᴏ Fʀɪᴇɴᴅs, \nMʏ Aᴅᴍɪɴ Hᴀs Rᴇsᴛʀɪᴄᴛᴇᴅ Mᴇ Fʀᴏᴍ Wᴏʀᴋɪɴɢ Hᴇʀᴇ ! Iғ Yᴏᴜ Wᴀɴɴᴀ Aᴅᴅ Mᴇ Aɢᴀɪɴ Cᴏɴᴛᴀᴄᴛ Sᴜᴘᴘᴏʀᴛ</b>', reply_markup=InlineKeyboardMarkup(buttons))
|
36 |
+
logger.info(f"Bot left chat {chat} at user {message.from_user.id}'s request.")
|
37 |
+
try:
|
38 |
+
await k.pin()
|
39 |
+
except:
|
40 |
+
logger.info("Failed to pin message in chat {chat}.")
|
41 |
+
pass
|
42 |
+
return await bot.leave_chat(message.chat.id)
|
43 |
except Exception as e:
|
44 |
+
logger.error(f"Error leaving chat {chat}: {e}")
|
45 |
+
return await message.reply(f'Eʀʀᴏʀ: {e}')
|
46 |
|
47 |
@Client.on_message(filters.command('disable') & filters.user(ADMINS))
|
48 |
async def disable_chat(bot, message):
|
49 |
+
"""
|
50 |
+
Command to disable a chat.
|
51 |
+
Only accessible to admins.
|
52 |
+
"""
|
53 |
+
logger.info(f"User {message.from_user.id} issued 'disable' command.")
|
54 |
+
if len(message.command) == 1:
|
55 |
+
logger.info("Command incomplete, no chat ID provided.")
|
56 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Cʜᴀᴛ Iᴅ')
|
57 |
r = message.text.split(None)
|
58 |
if len(r) > 2:
|
59 |
reason = message.text.split(None, 2)[2]
|
|
|
64 |
try:
|
65 |
chat_ = int(chat)
|
66 |
except:
|
67 |
+
logger.info("Invalid chat ID provided.")
|
68 |
return await message.reply('Gɪᴠᴇ Mᴇ A Vᴀʟɪᴅ Cʜᴀᴛ ID')
|
69 |
cha_t = await db.get_chat(int(chat_))
|
70 |
if not cha_t:
|
71 |
+
logger.info(f"Chat {chat_} not found in DB.")
|
72 |
return await message.reply("Cʜᴀᴛ Nᴏᴛ Fᴏᴜɴᴅ Iɴ DB")
|
73 |
if cha_t['is_disabled']:
|
74 |
+
logger.info(f"Chat {chat_} is already disabled.")
|
75 |
return await message.reply(f"Tʜɪꜱ Cʜᴀᴛ Is Aʟʀᴇᴅʏ Dɪꜱᴀʙʟᴇᴅ:\nRᴇᴀꜱᴏɴ: <code> {cha_t['reason']} </code>")
|
76 |
await db.disable_chat(int(chat_), reason)
|
77 |
temp.BANNED_CHATS.append(int(chat_))
|
78 |
await message.reply('Cʜᴀᴛ Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Dɪꜱᴀʙʟᴇᴅ')
|
79 |
+
logger.info(f"Chat {chat_} disabled successfully.")
|
80 |
try:
|
81 |
buttons = [[InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url=f'https://t.me/{SUPPORT_CHAT}')]]
|
82 |
await bot.send_message(chat_id=chat_, text=f'<b>Hᴇʟʟᴏ Fʀɪᴇɴᴅs, \nᴍʏ Aᴅᴍɪɴ Hᴀs Tᴏʟᴅ Mᴇ Tᴏ Lᴇᴀᴠᴇ Fʀᴏᴍ Gʀᴏᴜᴘ Sᴏ I Gᴏ! Iғ Yᴏᴜ Wᴀɴɴᴀ Aᴅᴅ Mᴇ Aɢᴀɪɴ Cᴏɴᴛᴀᴄᴛ Mʏ Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ.</b> \nRᴇᴀꜱᴏɴ : <code>{reason}</code>', reply_markup=InlineKeyboardMarkup(buttons))
|
83 |
await bot.leave_chat(chat_)
|
84 |
+
logger.info(f"Bot left chat {chat_} after disabling.")
|
85 |
except Exception as e:
|
86 |
+
logger.error(f"Error leaving chat {chat_}: {e}")
|
87 |
await message.reply(f"Eʀʀᴏʀ: {e}")
|
88 |
|
|
|
89 |
@Client.on_message(filters.command('enable') & filters.user(ADMINS))
|
90 |
async def re_enable_chat(bot, message):
|
91 |
+
"""
|
92 |
+
Command to re-enable a chat.
|
93 |
+
Only accessible to admins.
|
94 |
+
"""
|
95 |
+
logger.info(f"User {message.from_user.id} issued 'enable' command.")
|
96 |
+
if len(message.command) == 1:
|
97 |
+
logger.info("Command incomplete, no chat ID provided.")
|
98 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Cʜᴀᴛ Iᴅ')
|
99 |
chat = message.command[1]
|
100 |
+
try:
|
101 |
+
chat_ = int(chat)
|
102 |
+
except:
|
103 |
+
logger.info("Invalid chat ID provided.")
|
104 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Vᴀʟɪᴅ Cʜᴀᴛ ID')
|
105 |
sts = await db.get_chat(int(chat))
|
106 |
+
if not sts:
|
107 |
+
logger.info(f"Chat {chat_} not found in DB.")
|
108 |
+
return await message.reply("Cʜᴀᴛ Nᴏᴛ Fᴏᴜɴᴅ Iɴ DB")
|
109 |
if not sts.get('is_disabled'):
|
110 |
+
logger.info(f"Chat {chat_} is not disabled.")
|
111 |
return await message.reply('Tʜɪꜱ Cʜᴀᴛ Iꜱ Nᴏᴛ Yᴇᴛ Dɪꜱᴀʙʟᴇᴅ')
|
112 |
await db.re_enable_chat(int(chat_))
|
113 |
temp.BANNED_CHATS.remove(int(chat_))
|
114 |
await message.reply("Cʜᴀᴛ Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Rᴇ-Eɴᴀʙʟᴇᴅ")
|
115 |
+
logger.info(f"Chat {chat_} re-enabled successfully.")
|
116 |
|
117 |
@Client.on_message(filters.command('stats') & filters.incoming)
|
118 |
async def get_ststs(bot, message):
|
119 |
+
"""
|
120 |
+
Command to get bot statistics.
|
121 |
+
Accessible to both admins and users.
|
122 |
+
"""
|
123 |
+
logger.info(f"User {message.from_user.id} issued 'stats' command.")
|
124 |
rju = await message.reply('<b>Pʟᴇᴀꜱᴇ Wᴀɪᴛ...</b>')
|
125 |
total_users = await db.total_users_count()
|
126 |
totl_chats = await db.total_chat_count()
|
|
|
130 |
size = get_size(size)
|
131 |
free = get_size(free)
|
132 |
await rju.edit(script.STATUS_TXT.format(files, total_users, totl_chats, size, free))
|
133 |
+
logger.info(f"Bot statistics sent to user {message.from_user.id}.")
|
134 |
|
135 |
@Client.on_message(filters.command('invite') & filters.user(ADMINS))
|
136 |
async def gen_invite(bot, message):
|
137 |
+
"""
|
138 |
+
Command to generate an invite link for a chat.
|
139 |
+
Only accessible to admins.
|
140 |
+
"""
|
141 |
+
logger.info(f"User {message.from_user.id} issued 'invite' command.")
|
142 |
+
if len(message.command) == 1:
|
143 |
+
logger.info("Command incomplete, no chat ID provided.")
|
144 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Cʜᴀᴛ Iᴅ')
|
145 |
chat = message.command[1]
|
146 |
+
try:
|
147 |
+
chat_ = int(chat)
|
148 |
+
except:
|
149 |
+
logger.info("Invalid chat ID provided.")
|
150 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Vᴀʟɪᴅ Cʜᴀᴛ ID')
|
151 |
try:
|
152 |
+
link = await bot.create_chat_invite_link(chat_)
|
153 |
+
logger.info(f"Invite link generated for chat {chat_}.")
|
154 |
except ChatAdminRequired:
|
155 |
+
logger.error(f"Bot is not an admin in chat {chat_}.")
|
156 |
+
return await message.reply("Iɴᴠɪᴛᴇ Lɪɴᴋ Gᴇɴᴇʀᴀᴛɪᴏɴ Fᴀɪʟᴇᴅ, Iᴀᴍ Nᴏᴛ Hᴀᴠɪɴɢ Sᴜғғɪᴄɪᴇɴᴛ Rɪɢʜᴛꜱ")
|
157 |
except Exception as e:
|
158 |
+
logger.error(f"Error generating invite link for chat {chat_}: {e}")
|
159 |
return await message.reply(f'Eʀʀᴏʀ: {e}')
|
160 |
await message.reply(f'Hᴇʀᴇ Iꜱ Yᴏᴜʀ Iɴᴠɪᴛᴇ Lɪɴᴋ: {link.invite_link}')
|
161 |
+
logger.info(f"Invite link sent to user {message.from_user.id}.")
|
162 |
|
163 |
@Client.on_message(filters.command('ban_user') & filters.user(ADMINS))
|
164 |
async def ban_a_user(bot, message):
|
165 |
+
"""
|
166 |
+
Command to ban a user.
|
167 |
+
Only accessible to admins.
|
168 |
+
"""
|
169 |
+
logger.info(f"User {message.from_user.id} issued 'ban_user' command.")
|
170 |
+
if len(message.command) == 1:
|
171 |
+
logger.info("Command incomplete, no user ID provided.")
|
172 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Uꜱᴇʀ Iᴅ / Uꜱᴇʀɴᴀᴍᴇ')
|
173 |
r = message.text.split(None)
|
174 |
if len(r) > 2:
|
175 |
reason = message.text.split(None, 2)[2]
|
|
|
177 |
else:
|
178 |
chat = message.command[1]
|
179 |
reason = "No reason Provided"
|
180 |
+
try:
|
181 |
+
chat = int(chat)
|
182 |
+
except:
|
183 |
+
pass
|
184 |
+
try:
|
185 |
+
k = await bot.get_users(chat)
|
186 |
+
logger.info(f"User {chat} found: {k.mention}.")
|
187 |
+
except PeerIdInvalid:
|
188 |
+
logger.error(f"Peer ID invalid for user {chat}.")
|
189 |
+
return await message.reply("Tʜɪs Is Aɴ Iɴᴠᴀʟɪᴅ Usᴇʀ, Mᴀᴋᴇ Sᴜʀᴇ Iᴀ Hᴀᴠᴇ Mᴇᴛ Hɪᴍ Bᴇғᴏʀᴇ")
|
190 |
+
except IndexError:
|
191 |
+
logger.error(f"Index error for user {chat}.")
|
192 |
+
return await message.reply("Tʜɪs Mɪɢʜᴛ Bᴇ A Cʜᴀɴɴᴇʟ, Mᴀᴋᴇ Sᴜʀᴇ Iᴛs A Usᴇʀ.")
|
193 |
+
except Exception as e:
|
194 |
+
logger.error(f"Error getting user {chat}: {e}")
|
195 |
+
return await message.reply(f'Eʀʀᴏʀ: {e}')
|
196 |
else:
|
197 |
jar = await db.get_ban_status(k.id)
|
198 |
+
if jar['is_banned']:
|
199 |
+
logger.info(f"User {k.id} is already banned.")
|
200 |
+
return await message.reply(f"{k.mention} Iꜱ Aʟʀᴇᴅʏ Bᴀɴɴᴇᴅ\nRᴇᴀꜱᴏɴ: {jar['ban_reason']}")
|
201 |
await db.ban_user(k.id, reason)
|
202 |
temp.BANNED_USERS.append(k.id)
|
203 |
await message.reply(f"Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Bᴀɴɴᴇᴅ {k.mention}")
|
204 |
+
logger.info(f"User {k.id} banned successfully by user {message.from_user.id}.")
|
205 |
|
|
|
|
|
206 |
@Client.on_message(filters.command('unban_user') & filters.user(ADMINS))
|
207 |
async def unban_a_user(bot, message):
|
208 |
+
"""
|
209 |
+
Command to unban a user.
|
210 |
+
Only accessible to admins.
|
211 |
+
"""
|
212 |
+
logger.info(f"User {message.from_user.id} issued 'unban_user' command.")
|
213 |
+
if len(message.command) == 1:
|
214 |
+
logger.info("Command incomplete, no user ID provided.")
|
215 |
+
return await message.reply('Gɪᴠᴇ Mᴇ A Uꜱᴇʀ Iᴅ / Uꜱᴇʀɴᴀᴍᴇ')
|
216 |
r = message.text.split(None)
|
217 |
if len(r) > 2:
|
218 |
reason = message.text.split(None, 2)[2]
|
|
|
220 |
else:
|
221 |
chat = message.command[1]
|
222 |
reason = "No reason Provided"
|
223 |
+
try:
|
224 |
+
chat = int(chat)
|
225 |
+
except:
|
226 |
+
pass
|
227 |
+
try:
|
228 |
+
k = await bot.get_users(chat)
|
229 |
+
logger.info(f"User {chat} found: {k.mention}.")
|
230 |
+
except PeerIdInvalid:
|
231 |
+
logger.error(f"Peer ID invalid for user {chat}.")
|
232 |
+
return await message.reply("Tʜɪs Is Aɴ Iɴᴠᴀʟɪᴅ Usᴇʀ, Mᴀᴋᴇ Sᴜʀᴇ Iᴀ Hᴀᴠᴇ Mᴇᴛ Hɪᴍ Bᴇғᴏʀᴇ")
|
233 |
+
except IndexError:
|
234 |
+
logger.error(f"Index error for user {chat}.")
|
235 |
+
return await message.reply("Tʜɪs Mɪɢʜᴛ Bᴇ A Cʜᴀɴɴᴇʟ, Mᴀᴋᴇ Sᴜʀᴇ Iᴛs A Usᴇʀ.")
|
236 |
+
except Exception as e:
|
237 |
+
logger.error(f"Error getting user {chat}: {e}")
|
238 |
+
return await message.reply(f'Eʀʀᴏʀ: {e}')
|
239 |
else:
|
240 |
jar = await db.get_ban_status(k.id)
|
241 |
+
if not jar['is_banned']:
|
242 |
+
logger.info(f"User {k.id} is not banned.")
|
243 |
+
return await message.reply(f"{k.mention} Iꜱ Nᴏᴛ Yᴇᴛ Bᴀɴɴᴇᴅ")
|
244 |
await db.remove_ban(k.id)
|
245 |
temp.BANNED_USERS.remove(k.id)
|
246 |
await message.reply(f"Sᴜᴄᴄᴇꜱꜰᴜʟʟʏ Uɴʙᴀɴɴᴇᴅ {k.mention}")
|
247 |
+
logger.info(f"User {k.id} unbanned successfully by user {message.from_user.id}.")
|
248 |
|
|
|
|
|
249 |
@Client.on_message(filters.command('users') & filters.user(ADMINS))
|
250 |
async def list_users(bot, message):
|
251 |
+
"""
|
252 |
+
Command to list all users.
|
253 |
+
Only accessible to admins.
|
254 |
+
"""
|
255 |
+
logger.info(f"User {message.from_user.id} issued 'users' command.")
|
256 |
sps = await message.reply('Gᴇᴛᴛɪɴɢ Lɪꜱᴛ Oꜰ Uꜱᴇʀꜱ')
|
257 |
users = await db.get_all_users()
|
258 |
out = "Uꜱᴇʀꜱ Sᴀᴠᴇᴅ Iɴ DB Aʀᴇ:\n\n"
|
|
|
260 |
out += f"<a href=tg://user?id={user['id']}>{user['name']}</a>\n"
|
261 |
try:
|
262 |
await sps.edit_text(out)
|
263 |
+
logger.info(f"User list sent to user {message.from_user.id}.")
|
264 |
except MessageTooLong:
|
265 |
with open('users.txt', 'w+') as outfile:
|
266 |
outfile.write(out)
|
267 |
await message.reply_document('users.txt', caption="Lɪꜱᴛ Oꜰ Uꜱᴇʀꜱ")
|
268 |
+
logger.info(f"User list too long, sent as document to user {message.from_user.id}.")
|
269 |
+
os.remove('users.txt')
|
270 |
|
271 |
@Client.on_message(filters.command('chats') & filters.user(ADMINS))
|
272 |
async def list_chats(bot, message):
|
273 |
+
"""
|
274 |
+
Command to list all chats.
|
275 |
+
Only accessible to admins.
|
276 |
+
"""
|
277 |
+
logger.info(f"User {message.from_user.id} issued 'chats' command.")
|
278 |
sps = await message.reply('Gᴇᴛᴛɪɴɢ Lɪꜱᴛ Oꜰ Cʜᴀᴛꜱ')
|
279 |
chats = await db.get_all_chats()
|
280 |
out = "Cʜᴀᴛꜱ Sᴀᴠᴇᴅ Iɴ DB Aʀᴇ:\n\n"
|
|
|
284 |
out += f"**- Tɪᴛʟᴇ:** `{chat['title']}`\n**- ID:** `{chat['id']}`\n**Uꜱᴇʀɴᴀᴍᴇ:** {username}\n"
|
285 |
try:
|
286 |
await sps.edit_text(out)
|
287 |
+
logger.info(f"Chat list sent to user {message.from_user.id}.")
|
288 |
except MessageTooLong:
|
289 |
with open('chats.txt', 'w+') as outfile:
|
290 |
outfile.write(out)
|
291 |
await message.reply_document('chats.txt', caption="Lɪꜱᴛ Oꜰ Cʜᴀᴛꜱ")
|
292 |
+
logger.info(f"Chat list too long, sent as document to user {message.from_user.id}.")
|
293 |
+
os.remove('chats.txt')
|
294 |
|
295 |
+
@Client.on_message(filters.command(["id"]))
|
|
|
|
|
296 |
async def show_id(client, message):
|
297 |
+
"""
|
298 |
+
Command to show user/group ID.
|
299 |
+
Accessible to both admins and users.
|
300 |
+
"""
|
301 |
+
logger.info(f"User {message.from_user.id} issued 'id' command.")
|
302 |
chat_type = message.chat.type
|
303 |
if chat_type == enums.ChatType.PRIVATE:
|
304 |
user_id = message.chat.id
|
|
|
307 |
username = message.from_user.username
|
308 |
dc_id = message.from_user.dc_id or ""
|
309 |
await message.reply_text(f"<b>➲ ꜰɪʀꜱᴛ ɴᴀᴍᴇ:</b> {first}\n<b>➲ ʟᴀꜱᴛ ɴᴀᴍᴇ:</b> {last}\n<b>➲ ᴜꜱᴇʀɴᴀᴍᴇ:</b> {username}\n<b>➲ ᴛᴇʟᴇɢʀᴀᴍ ɪᴅ:</b> <code>{user_id}</code>\n<b>➲ ᴅᴄ ɪᴅ:</b> <code>{dc_id}</code>", quote=True)
|
310 |
+
logger.info(f"ID information sent to user {message.from_user.id}.")
|
311 |
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
|
312 |
_id = ""
|
313 |
_id += f"<b>➲ ᴄʜᴀᴛ ɪᴅ</b>: <code>{message.chat.id}</code>\n"
|
|
|
314 |
if message.reply_to_message:
|
315 |
_id += (
|
316 |
"<b>➲ ᴜꜱᴇʀ ɪᴅ</b>: "
|
|
|
331 |
f"<code>{file_info.file_id}</code>\n"
|
332 |
)
|
333 |
await message.reply_text(_id, quote=True)
|
334 |
+
logger.info(f"ID information sent to user {message.from_user.id} in chat {message.chat.id}.")
|
335 |
|
336 |
@Client.on_message(filters.command(["info"]))
|
337 |
async def user_info(client, message):
|
338 |
+
"""
|
339 |
+
Command to get detailed user information.
|
340 |
+
Accessible to both admins and users.
|
341 |
+
"""
|
342 |
+
logger.info(f"User {message.from_user.id} issued 'info' command.")
|
343 |
status_message = await message.reply_text("`ᴩʟᴇᴀꜱᴇ ᴡᴀɪᴛ....`")
|
344 |
from_user = None
|
345 |
from_user_id, _ = extract_user(message)
|
346 |
try:
|
347 |
from_user = await client.get_users(from_user_id)
|
348 |
+
logger.info(f"User {from_user_id} found: {from_user.first_name}.")
|
349 |
except Exception as error:
|
350 |
+
logger.error(f"Error getting user {from_user_id}: {error}")
|
351 |
return await status_message.edit(str(error))
|
352 |
if from_user is None:
|
353 |
+
logger.info(f"User {from_user_id} not found.")
|
354 |
+
return await status_message.edit("ɴᴏ ᴠᴀʟɪᴅ ᴜꜱᴇʀ_ɪᴅ / ᴍᴇꜱꜱᴀɢᴇ sᴘᴇᴄɪꜰɪᴇᴅ")
|
355 |
message_out_str = ""
|
356 |
message_out_str += f"<b>➲ꜰɪʀꜱᴛ ɴᴀᴍᴇ:</b> {from_user.first_name}\n"
|
357 |
last_name = from_user.last_name or "<b>ɴᴏɴᴇ</b>"
|
|
|
364 |
message_out_str += f"<b>➲ᴜꜱᴇʀ ʟɪɴᴋ:</b> <a href='tg://user?id={from_user.id}'><b>ᴄʟɪᴄᴋ ʜᴇʀᴇ</b></a>\n"
|
365 |
if message.chat.type in ((enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)):
|
366 |
try:
|
367 |
+
chat_member_p = await message.chat.get_member(from_user_id)
|
368 |
joined_date = (chat_member_p.joined_date or datetime.now()).strftime("%Y.%m.%d %H:%M:%S")
|
369 |
message_out_str += f"<b>➲ᴊᴏɪɴᴇᴅ ᴛʜɪꜱ ᴄʜᴀᴛ ᴏɴ:</b> <code>{joined_date}</code>\n"
|
370 |
+
logger.info(f"User {from_user_id} joined chat {message.chat.id} on {joined_date}.")
|
371 |
+
except UserNotParticipant:
|
372 |
+
logger.info(f"User {from_user_id} is not a participant in chat {message.chat.id}.")
|
373 |
+
pass
|
374 |
chat_photo = from_user.photo
|
375 |
if chat_photo:
|
376 |
local_user_photo = await client.download_media(message=chat_photo.big_file_id)
|
|
|
384 |
disable_notification=True
|
385 |
)
|
386 |
os.remove(local_user_photo)
|
387 |
+
logger.info(f"User photo sent to user {message.from_user.id}.")
|
388 |
else:
|
389 |
buttons = [[InlineKeyboardButton('ᴄʟᴏꜱᴇ ✘', callback_data='close_data')]]
|
390 |
await message.reply_text(
|
|
|
394 |
parse_mode=enums.ParseMode.HTML,
|
395 |
disable_notification=True
|
396 |
)
|
397 |
+
logger.info(f"User information sent to user {message.from_user.id}.")
|
398 |
|
399 |
@Client.on_message(filters.command(["imdb", 'search']))
|
400 |
async def imdb_search(client, message):
|
401 |
+
"""
|
402 |
+
Command to search for a movie on IMDb.
|
403 |
+
Accessible to both admins and users.
|
404 |
+
"""
|
405 |
+
logger.info(f"User {message.from_user.id} issued 'imdb' or 'search' command.")
|
406 |
if ' ' in message.text:
|
407 |
k = await message.reply('ꜱᴇᴀʀᴄʜɪɴɢ ɪᴍᴅʙ..')
|
408 |
r, title = message.text.split(None, 1)
|
409 |
movies = await get_poster(title, bulk=True)
|
410 |
if not movies:
|
411 |
+
logger.info(f"No IMDb results found for title: {title}.")
|
412 |
return await message.reply("ɴᴏ ʀᴇꜱᴜʟᴛ ꜰᴏᴜɴᴅ")
|
413 |
btn = [[InlineKeyboardButton(f"{movie.get('title')} - {movie.get('year')}", callback_data=f"imdb#{movie.movieID}")] for movie in movies ]
|
414 |
await k.edit('Hᴇʀᴇ Is Wʜᴀᴛ I Fᴏᴜɴᴅ Oɴ Iᴍᴅʙ', reply_markup=InlineKeyboardMarkup(btn))
|
415 |
+
logger.info(f"IMDb results found and sent to user {message.from_user.id}.")
|
416 |
else:
|
417 |
+
logger.info(f"Command 'imdb' or 'search' issued without a title.")
|
418 |
+
await message.reply('Gɪᴠᴇ Mᴇ A Mᴏᴠɪᴇ / Sᴇʀɪᴇꜱ Nᴀᴍᴇ')
|
419 |
|
420 |
@Client.on_callback_query(filters.regex('^imdb'))
|
421 |
async def imdb_callback(bot: Client, quer_y: CallbackQuery):
|
422 |
+
"""
|
423 |
+
Callback to handle IMDb search results.
|
424 |
+
"""
|
425 |
+
logger.info(f"Callback query received for IMDb: {quer_y.data}")
|
426 |
i, movie = quer_y.data.split('#')
|
427 |
imdb = await get_poster(query=movie, id=True)
|
428 |
btn = [[InlineKeyboardButton(f"{imdb.get('title')}", url=imdb['url'])]]
|
|
|
459 |
url = imdb['url'],
|
460 |
**locals()
|
461 |
)
|
462 |
+
logger.info(f"IMDb caption generated for movie: {imdb['title']}.")
|
463 |
else:
|
464 |
caption = "ɴᴏ ʀᴇꜱᴜʟᴛꜱ"
|
465 |
+
logger.info(f"No IMDb results found for movie ID: {movie}.")
|
466 |
+
|
467 |
if imdb.get('poster'):
|
468 |
try:
|
469 |
await quer_y.message.reply_photo(photo=imdb['poster'], caption=caption, reply_markup=InlineKeyboardMarkup(btn))
|
470 |
+
logger.info(f"IMDb poster sent to user {quer_y.from_user.id}.")
|
471 |
except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
|
472 |
pic = imdb.get('poster')
|
473 |
poster = pic.replace('.jpg', "._V1_UX360.jpg")
|
474 |
await quer_y.message.reply_photo(photo=poster, caption=caption, reply_markup=InlineKeyboardMarkup(btn))
|
475 |
+
logger.info(f"IMDb poster (fallback) sent to user {quer_y.from_user.id}.")
|
476 |
except Exception as e:
|
477 |
+
logger.error(f"Error sending IMDb poster: {e}")
|
478 |
await quer_y.message.reply(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
|
479 |
+
logger.info(f"IMDb caption sent to user {quer_y.from_user.id}.")
|
480 |
await quer_y.message.delete()
|
481 |
+
logger.info(f"Original message deleted after sending IMDb results.")
|
482 |
else:
|
483 |
await quer_y.message.edit(caption, reply_markup=InlineKeyboardMarkup(btn), disable_web_page_preview=False)
|
484 |
+
logger.info(f"IMDb caption edited in message for user {quer_y.from_user.id}.")
|
485 |
+
|
486 |
@Client.on_message(filters.command('logs') & filters.user(ADMINS))
|
487 |
async def log_file(bot, msg):
|
488 |
+
"""
|
489 |
+
Command to send bot logs.
|
490 |
+
Only accessible to admins.
|
491 |
+
"""
|
492 |
+
logger.info(f"User {msg.from_user.id} issued 'logs' command.")
|
493 |
+
try:
|
494 |
+
await msg.reply_document('BotLog.txt')
|
495 |
+
logger.info(f"Bot logs sent to user {msg.from_user.id}.")
|
496 |
+
except Exception as e:
|
497 |
+
logger.error(f"Error sending bot logs: {e}")
|
498 |
+
await msg.reply(str(e))
|
499 |
|
500 |
@Client.on_message(filters.command("restart") & filters.user(ADMINS))
|
501 |
async def restart_bot(bot, msg):
|
502 |
+
"""
|
503 |
+
Command to restart the bot.
|
504 |
+
Only accessible to admins.
|
505 |
+
"""
|
506 |
+
logger.info(f"User {msg.from_user.id} issued 'restart' command.")
|
507 |
await msg.reply("Rᴇꜱᴛᴀᴛɪɴɢ........")
|
508 |
await asyncio.sleep(2)
|
509 |
await sts.delete()
|
510 |
os.execl(sys.executable, sys.executable, *sys.argv)
|
511 |
+
logger.info(f"Bot restarted by user {msg.from_user.id}.")
|
|
|
|
|
|
|
|
|
|
|
|