File size: 20,248 Bytes
d889c50 45d8014 2b7f4fa 45d8014 3b5a9e0 45d8014 3b5a9e0 45d8014 3b5a9e0 45d8014 d889c50 7821c43 0ae53fc d889c50 3b5a9e0 8d06de0 3b5a9e0 d889c50 07fe3fe b409a1a 07fe3fe 3b5a9e0 d889c50 34af195 d889c50 3b5a9e0 d889c50 3b5a9e0 d889c50 7821c43 0ae53fc d889c50 3b5a9e0 8d06de0 3b5a9e0 d889c50 07fe3fe b409a1a 07fe3fe 3b5a9e0 d889c50 3b5a9e0 d889c50 3b5a9e0 d889c50 45d8014 d889c50 0ae53fc d889c50 45d8014 0ae53fc f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 07fe3fe 45d8014 34af195 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 d889c50 45d8014 0ae53fc f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 f90d21b 45d8014 2b7f4fa 45d8014 07fe3fe 45d8014 2b7f4fa 34af195 2b7f4fa f90d21b 2b7f4fa f90d21b 2b7f4fa f90d21b 2b7f4fa d889c50 2b7f4fa 34af195 2b7f4fa eefa5fd f32ead8 34af195 f90d21b eefa5fd f90d21b eefa5fd a835529 eefa5fd a835529 eefa5fd f32ead8 0ae53fc f90d21b eefa5fd f90d21b eefa5fd a835529 eefa5fd a835529 eefa5fd f90d21b f32ead8 0ae53fc f90d21b 07fe3fe f90d21b 13a9f4f f32ead8 13a9f4f f90d21b 07fe3fe f90d21b 6dca01c f90d21b 13a9f4f 07fe3fe 13a9f4f 580f74f 13a9f4f 07fe3fe 13a9f4f f90d21b 13a9f4f f90d21b 2b7f4fa 62a8111 3170917 6dca01c 2b7f4fa 5eaaf71 2b7f4fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
from datetime import datetime as dt
from pyrogram import *
from pyrogram.types import *
from pyrogram.enums import *
from akn.utils.database import db
unmute_permissions = ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
can_send_polls=True,
can_send_other_messages=True,
can_add_web_page_previews=True,
can_change_info=False,
can_invite_users=True,
can_pin_messages=False
)
async def extract_userid(message, text: str):
def is_int(text: str):
try:
int(text)
except ValueError:
return False
return True
text = text.strip()
if is_int(text):
return int(text)
entities = message.entities
app = message._client
if len(entities) < 2:
return (await app.get_users(text)).id
entity = entities[1]
if entity.type == "mention":
return (await app.get_users(text)).id
if entity.type == "text_mention":
return entity.user.id
return None
cached_admins = {}
async def arz_update_admin_cache(client, chat_id):
admin_list = []
async for m in client.get_chat_members(chat_id, filter=ChatMembersFilter.ADMINISTRATORS):
if not m.user.is_bot and not m.user.is_deleted:
admin_list.append(m.user.id)
cached_admins[chat_id] = admin_list
return admin_list
@Client.on_callback_query(filters.regex(r"^arzunmuted_(\-?\d+)_(\d+)$"))
async def xarzunmute_cbok(client, callback):
chat_id = int(callback.matches[0].group(1))
user_id = int(callback.matches[0].group(2))
chat_member = await client.get_chat_member(chat_id, client.me.id)
if not chat_member.privileges or not chat_member.privileges.can_restrict_members:
await callback.answer("β οΈ Bot needs 'Restrict Members' permission!", show_alert=True)
try:
chat_data = await db.alldl_bot.find_one({"chat_ids": chat_id})
if not chat_data:
await callback.answer("β οΈ You can /reload again admins", show_alert=True)
return
admins = chat_data.get("chat_admins", []) if chat_data else []
if not admins:
await callback.answer("β οΈ You can /reload again admins", show_alert=True)
return
if callback.from_user.id not in admins:
await callback.answer("β οΈ Only admins can unmute!", show_alert=True)
return
user_mention = callback.from_user.mention
await client.restrict_chat_member(chat_id, user_id, unmute_permissions)
await db.alldl_bot.update_one(
{"bot_id": client.me.id},
{"$pull": {"mute_user": user_id}},
upsert=True
)
await callback.message.edit_text(
f"β
User {user_id} unmuted by {user_mention}",
reply_markup=None
)
except Exception as e:
LOGS.error(f"Error xarzunmute_cbok: {str(e)} ")
await callback.message.edit_text(f"β Failed: {str(e)}")
@Client.on_callback_query(filters.regex(r"^arzunband_(\-?\d+)_(\d+)$"))
async def xarzunban_cbok(client, callback):
chat_id = int(callback.matches[0].group(1))
user_id = int(callback.matches[0].group(2))
chat_member = await client.get_chat_member(chat_id, client.me.id)
if not chat_member.privileges or not chat_member.privileges.can_restrict_members:
await callback.answer("β οΈ Bot needs 'Restrict Members' permission!", show_alert=True)
try:
chat_data = await db.alldl_bot.find_one({"chat_ids": chat_id})
chat_data = await db.alldl_bot.find_one({"chat_ids": chat_id})
if not chat_data:
await callback.answer("β οΈ You can /reload again admins", show_alert=True)
return
admins = chat_data.get("chat_admins", []) if chat_data else []
if not admins:
await callback.answer("β οΈ You can /reload again admins", show_alert=True)
return
if callback.from_user.id not in admins:
await callback.answer("β οΈ Only admins can unmute!", show_alert=True)
return
user_mention = callback.from_user.mention
await client.unban_chat_member(chat_id, user_id)
await callback.message.edit_text(
f"β
User {user_id} unbanned by {user_mention}",
reply_markup=None
)
except Exception as e:
LOGS.error(f"Error xarzunban_cbok: {str(e)} ")
await callback.message.edit_text(f"β Failed: {str(e)}")
async def extract_user_and_reason(message, sender_chat=False):
args = message.text.strip().split()
text = message.text
user = None
reason = None
if message.reply_to_message:
reply = message.reply_to_message
if not reply.from_user:
if (
reply.sender_chat
and reply.sender_chat != message.chat.id
and sender_chat
):
id_ = reply.sender_chat.id
else:
return None, None
else:
id_ = reply.from_user.id
if len(args) < 2:
reason = None
else:
reason = text.split(None, 1)[1]
return id_, reason
if len(args) == 2:
user = text.split(None, 1)[1]
return await extract_userid(message, user), None
if len(args) > 2:
user, reason = text.split(None, 2)[1:]
return await extract_userid(message, user), reason
return user, reason
async def extract_user(message):
return (await extract_user_and_reason(message))[0]
@Client.on_message(
~filters.scheduled & filters.command(["reload"]) & ~filters.forwarded
)
async def arz_reload(client: Client, message: Message):
if not message.from_user:
return
bot_permissions = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot_permissions or not bot_permissions.can_restrict_members:
return await message.reply_text("β I need admin permissions to restrict members")
admins = await arz_update_admin_cache(client, message.chat.id)
await db.alldl_bot.update_one(
{"bot_id": client.me.id},
{
"$addToSet": {"chat_ids": message.chat.id},
"$set": {
"chat_admins": admins,
"last_updated": dt.now()
}
},
upsert=True
)
await message.reply_text(
"π Admin list reloaded successfully!",
)
@Client.on_message(
~filters.scheduled
& filters.command(["ban", "dban"])
& ~filters.forwarded
)
async def arz_ban_user(client: Client, message: Message):
user_id, reason = await extract_user_and_reason(message, sender_chat=True)
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't ban myself.")
if user_id == 1191668125:
return await message.reply_text("I can't ban my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Banned User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Banned By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if message.command[0][0] == "d":
await message.reply_to_message.delete()
if reason:
msg += f"**Reason:** {reason}"
await message.chat.ban_member(user_id)
await message.reply_text(
msg,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"β« Unban", callback_data=f"arzunband_{message.chat.id}_{user_id}"
)
]
]
)
)
@Client.on_message(
~filters.scheduled
& filters.command(["unban"])
& ~filters.forwarded
)
async def arz_unban_user(client: Client, message: Message):
user_id, reason = await extract_user_and_reason(message, sender_chat=True)
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't unban myself.")
if user_id == 1191668125:
return await message.reply_text("I can't unban my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Unbanned User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Unbanned By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if reason:
msg += f"**Reason:** {reason}"
await message.chat.unban_member(user_id)
await message.reply_text(msg)
@Client.on_message(
~filters.scheduled
& filters.command(["banme"])
& ~filters.forwarded
)
async def arz_ban_me(client: Client, message: Message):
user_id = message.from_user.id
reason = None
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't ban myself.")
if user_id == 1191668125:
return await message.reply_text("I can't ban my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Banned User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Banned By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if reason:
msg += f"**Reason:** {reason}"
await message.chat.ban_member(user_id)
await message.reply_text(
msg,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"β« Unban", callback_data=f"arzunban_{message.chat.id}_{user_id}"
)
]
]
)
)
@Client.on_message(
~filters.scheduled
& filters.command(["mute", "dmute"])
& ~filters.forwarded
)
async def arz_mute(client: Client, message: Message):
user_id, reason = await extract_user_and_reason(message, sender_chat=True)
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't mute myself.")
if user_id == 1191668125:
return await message.reply_text("I can't mute my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Muted User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Muted By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if message.command[0][0] == "d":
await message.reply_to_message.delete()
if reason:
msg += f"**Reason:** {reason}"
await message.chat.restrict_member(user_id, ChatPermissions())
await db.alldl_bot.update_one(
{"bot_id": client.me.id},
{"$addToSet": {"mute_user": user_id}},
upsert=True,
)
await message.reply_text(
msg,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"β« Unmute", callback_data=f"arzunmuted_{message.chat.id}_{user_id}"
)
]
]
)
)
@Client.on_message(
~filters.scheduled
& filters.command(["unmute"])
& ~filters.forwarded
)
async def arz_unmute(client: Client, message: Message):
user_id, reason = await extract_user_and_reason(message, sender_chat=True)
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't unmute myself.")
if user_id == 1191668125:
return await message.reply_text("I can't unmute my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Unmuted User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Unmuted By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if reason:
msg += f"**Reason:** {reason}"
await message.chat.restrict_member(user_id, unmute_permissions)
await message.chat.unban_member(user_id)
await db.alldl_bot.update_one(
{"bot_id": client.me.id},
{"$pull": {"mute_user": user_id}},
upsert=True
)
await message.reply_text(msg)
@Client.on_message(
~filters.scheduled
& filters.command(["muteall"])
& ~filters.forwarded
)
async def arz_mute_all(client: Client, message: Message):
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if message.chat.type == ChatType.PRIVATE:
return await message.reply_text("This command is not available in private chats.")
if message.chat.type == ChatType.SUPERGROUP:
try:
await client.set_chat_permissions(
message.chat.id,
permissions=ChatPermissions()
)
await message.reply_text("All members muted successfully.")
except Exception as e:
await message.reply_text(f"Failed to mute all members: {e}")
@Client.on_message(
~filters.scheduled
& filters.command(["unmuteall"])
& ~filters.forwarded
)
async def arz_unmute_all(client: Client, message: Message):
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
if message.chat.type == ChatType.PRIVATE:
return await message.reply_text("This command is not available in private chats.")
if message.chat.type == ChatType.SUPERGROUP:
try:
await client.set_chat_permissions(
message.chat.id,
permissions=unmute_permissions
)
await message.reply_text("All members unmuted successfully.")
except Exception as e:
await message.reply_text(f"Failed to unmute all members: {e}")
@Client.on_message(
~filters.scheduled
& filters.command(["muteme"])
& ~filters.forwarded
)
async def arz_mute_me(client: Client, message: Message):
user_id = message.from_user.id
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions")
reason = None
if not user_id:
return await message.reply_text("I can't find that user.")
if user_id == client.me.id:
return await message.reply_text("I can't mute myself.")
if user_id == 1191668125:
return await message.reply_text("I can't mute my developer!")
try:
mention = (await client.get_users(user_id)).mention
except IndexError:
mention = (
message.reply_to_message.sender_chat.title
if message.reply_to_message
else "Anon"
)
msg = (
f"**Muted User:** <a href='tg://user?id={user_id}'>{mention}</a>\n"
f"**Muted By:** [{message.from_user.mention}](tg://user?id={message.from_user.id if message.from_user else 0})\n"
)
if reason:
msg += f"**Reason:** {reason}"
await message.chat.restrict_member(user_id, ChatPermissions())
await db.alldl_bot.update_one(
{"bot_id": client.me.id},
{"$addToSet": {"mute_user": user_id}},
upsert=True,
)
await message.reply_text(
msg,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"β« Unmute", callback_data=f"arzunmuted_{user_id}"
)
]
]
)
)
@Client.on_message(
~filters.scheduled
& filters.command(["adminlist"])
& ~filters.forwarded
)
async def arz_admin_list(client: Client, message: Message):
if message.chat.type == ChatType.PRIVATE:
return await message.reply_text("This command is not available in private chats.")
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if not bot or not bot.can_restrict_members:
return await message.reply_text("I don't have enough permissions to list admins.")
try:
admin_listx = []
async for m in client.get_chat_members(message.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
if m.user.is_bot:
continue
if m.user.is_deleted:
continue
user = m.user
tag = f"[{user.first_name}](tg://user?id={user.id})"
role = "π Owner" if m.status.value == "owner" else "π§ Admin"
admin_listx.append(f"β£ {role}: {tag}")
if not admin_list:
return await message.reply_text("No admins found.")
text = "**π₯ Admin List:**\n\n" + "\n".join(admin_listx)
await message.reply_text(
text,
disable_web_page_preview=True
)
except Exception as e:
await message.reply_text(f"Failed to fetch admin list: `{e}`")
@Client.on_message(filters.incoming & filters.group, group=-1)
async def check_user_mute(client: Client, message: Message):
bot = await client.get_chat_member(message.chat.id, client.me.id)
if not bot.privileges or not bot.privileges.can_restrict_members:
return
if message.from_user and message.from_user.is_deleted:
return
if message.from_user and message.from_user.is_bot:
return
if message.chat.type == ChatType.PRIVATE:
return
user = message.from_user.id
muted_users = await db.alldl_bot.find_one({"bot_id": client.me.id})
if not muted_users or "mute_user" not in muted_users:
return
if muted_users and user in muted_users["mute_user"]:
await client.restrict_chat_member(
message.chat.id,
user,
permissions=ChatPermissions(
can_send_messages=False,
can_send_media_messages=False,
can_send_polls=False,
can_change_info=False,
can_invite_users=False,
can_pin_messages=False,
),
) |