Fix
Browse files
akn/AllDownloaderBot/admins.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from pyrogram import *
|
2 |
from pyrogram.types import *
|
3 |
from pyrogram.enums import *
|
@@ -36,6 +37,59 @@ async def extract_userid(message, text: str):
|
|
36 |
return entity.user.id
|
37 |
return None
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
async def extract_user_and_reason(message, sender_chat=False):
|
41 |
args = message.text.strip().split()
|
@@ -76,6 +130,32 @@ async def extract_user_and_reason(message, sender_chat=False):
|
|
76 |
async def extract_user(message):
|
77 |
return (await extract_user_and_reason(message))[0]
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
@Client.on_message(
|
81 |
~filters.scheduled
|
@@ -182,18 +262,13 @@ async def arz_ban_me(client: Client, message: Message):
|
|
182 |
if reason:
|
183 |
msg += f"**Reason:** {reason}"
|
184 |
await message.chat.ban_member(user_id)
|
185 |
-
await db.alldl_bot.update_one(
|
186 |
-
{"bot_id": client.me.id},
|
187 |
-
{"$set": {"ban_user": user_id}},
|
188 |
-
upsert=True,
|
189 |
-
)
|
190 |
await message.reply_text(
|
191 |
msg,
|
192 |
reply_markup=InlineKeyboardMarkup(
|
193 |
[
|
194 |
[
|
195 |
InlineKeyboardButton(
|
196 |
-
"Unban", callback_data=f"arzunban_{user_id}"
|
197 |
)
|
198 |
]
|
199 |
]
|
@@ -244,7 +319,7 @@ async def arz_mute(client: Client, message: Message):
|
|
244 |
[
|
245 |
[
|
246 |
InlineKeyboardButton(
|
247 |
-
"Unmute", callback_data=f"arzunmute_{user_id}"
|
248 |
)
|
249 |
]
|
250 |
]
|
@@ -278,6 +353,7 @@ async def arz_unmute(client: Client, message: Message):
|
|
278 |
)
|
279 |
if reason:
|
280 |
msg += f"**Reason:** {reason}"
|
|
|
281 |
await message.chat.unban_member(user_id)
|
282 |
await db.alldl_bot.update_one(
|
283 |
{"bot_id": client.me.id},
|
|
|
1 |
+
from datetime import datetime as dt
|
2 |
from pyrogram import *
|
3 |
from pyrogram.types import *
|
4 |
from pyrogram.enums import *
|
|
|
37 |
return entity.user.id
|
38 |
return None
|
39 |
|
40 |
+
cached_admins = {}
|
41 |
+
|
42 |
+
async def arz_update_admin_cache(client, chat_id):
|
43 |
+
admin_list = []
|
44 |
+
async for m in client.get_chat_members(chat_id, filter=ChatMembersFilter.ADMINISTRATORS):
|
45 |
+
if not m.user.is_bot and not m.user.is_deleted:
|
46 |
+
admin_list.append(m.user.id)
|
47 |
+
cached_admins[chat_id] = admin_list
|
48 |
+
return admin_list
|
49 |
+
|
50 |
+
@Client.on_callback_query(filters.regex(r"^arzunmute_(\d+)_(\d+)$"))
|
51 |
+
async def arzunmute_callbackx(client, callback):
|
52 |
+
chat_id = int(callback.matches[0].group(1))
|
53 |
+
user_id = int(callback.matches[0].group(2))
|
54 |
+
|
55 |
+
admins = cached_admins.get(chat_id, [])
|
56 |
+
if not admins:
|
57 |
+
chat_data = await db.alldl_bot.find_one({"chat_ids": chat_id})
|
58 |
+
admins = chat_data.get("chat_admins", []) if chat_data else []
|
59 |
+
|
60 |
+
if callback.from_user.id not in admins:
|
61 |
+
await callback.answer("β οΈ Only admins can unmute!", show_alert=True)
|
62 |
+
return
|
63 |
+
try:
|
64 |
+
await client.restrict_chat_member(chat_id, user_id, unmute_permissions)
|
65 |
+
await callback.message.edit_text(
|
66 |
+
f"β
User {user_id} unmuted by @{callback.from_user.username}",
|
67 |
+
reply_markup=None
|
68 |
+
)
|
69 |
+
except Exception as e:
|
70 |
+
await callback.message.edit_text(f"β Failed: {str(e)}")
|
71 |
+
|
72 |
+
@Client.on_callback_query(filters.regex(r"^arzunban_(\d+)_(\d+)$"))
|
73 |
+
async def arzunban_callbackx(client, callback):
|
74 |
+
chat_id = int(callback.matches[0].group(1))
|
75 |
+
user_id = int(callback.matches[0].group(2))
|
76 |
+
|
77 |
+
admins = cached_admins.get(chat_id, [])
|
78 |
+
if not admins:
|
79 |
+
chat_data = await db.alldl_bot.find_one({"chat_ids": chat_id})
|
80 |
+
admins = chat_data.get("chat_admins", []) if chat_data else []
|
81 |
+
|
82 |
+
if callback.from_user.id not in admins:
|
83 |
+
await callback.answer("β οΈ Only admins can unmute!", show_alert=True)
|
84 |
+
return
|
85 |
+
try:
|
86 |
+
await client.unban_chat_member(chat_id, user_id)
|
87 |
+
await callback.message.edit_text(
|
88 |
+
f"β
User {user_id} unbanned by @{callback.from_user.username}",
|
89 |
+
reply_markup=None
|
90 |
+
)
|
91 |
+
except Exception as e:
|
92 |
+
await callback.message.edit_text(f"β Failed: {str(e)}")
|
93 |
|
94 |
async def extract_user_and_reason(message, sender_chat=False):
|
95 |
args = message.text.strip().split()
|
|
|
130 |
async def extract_user(message):
|
131 |
return (await extract_user_and_reason(message))[0]
|
132 |
|
133 |
+
@Client.on_message(
|
134 |
+
~filters.scheduled & filters.command(["reload"]) & ~filters.forwarded
|
135 |
+
)
|
136 |
+
async def arz_reload(client: Client, message: Message):
|
137 |
+
if not message.from_user:
|
138 |
+
return
|
139 |
+
|
140 |
+
bot_permissions = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
|
141 |
+
if not bot_permissions.can_restrict_members:
|
142 |
+
return await message.reply_text("β I need admin permissions to restrict members")
|
143 |
+
|
144 |
+
admins = await arz_update_admin_cache(client, message.chat.id)
|
145 |
+
await db.alldl_bot.update_one(
|
146 |
+
{"bot_id": client.me.id},
|
147 |
+
{
|
148 |
+
"$addToSet": {"chat_ids": message.chat.id},
|
149 |
+
"$set": {
|
150 |
+
"chat_admins": admins,
|
151 |
+
"last_updated": dt.now()
|
152 |
+
}
|
153 |
+
},
|
154 |
+
upsert=True
|
155 |
+
)
|
156 |
+
await message.reply_text(
|
157 |
+
"π Admin list reloaded successfully!",
|
158 |
+
)
|
159 |
|
160 |
@Client.on_message(
|
161 |
~filters.scheduled
|
|
|
262 |
if reason:
|
263 |
msg += f"**Reason:** {reason}"
|
264 |
await message.chat.ban_member(user_id)
|
|
|
|
|
|
|
|
|
|
|
265 |
await message.reply_text(
|
266 |
msg,
|
267 |
reply_markup=InlineKeyboardMarkup(
|
268 |
[
|
269 |
[
|
270 |
InlineKeyboardButton(
|
271 |
+
"β« Unban", callback_data=f"arzunban_{message.chat.id}_{user_id}"
|
272 |
)
|
273 |
]
|
274 |
]
|
|
|
319 |
[
|
320 |
[
|
321 |
InlineKeyboardButton(
|
322 |
+
"β« Unmute", callback_data=f"arzunmute_{message.chat.id}_{user_id}"
|
323 |
)
|
324 |
]
|
325 |
]
|
|
|
353 |
)
|
354 |
if reason:
|
355 |
msg += f"**Reason:** {reason}"
|
356 |
+
await message.chat.restrict_member(user_id, unmute_permissions)
|
357 |
await message.chat.unban_member(user_id)
|
358 |
await db.alldl_bot.update_one(
|
359 |
{"bot_id": client.me.id},
|