File size: 40,974 Bytes
3a3b605 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | """الإدارة المتقدمة والمدراء والمنشئين والمالكين والمطورين:
- دعم الرد و @المعرف في أوامر العقوبات والكشف
- رفع الادمنيه / مسح الادمنيه بالعدد الدقيق
- المالك (بالصورة والبايو وزر البروفايل) + ارفعني مالك + رفع المالك
- لوحة تحكم العضو (تحكم) بالأزرار
- تغيير رد الرتب + ضع رتبه + صلاحياتي/صلاحياته/صلاحيات المجموعه/صلاحيات المشرفين
- إضافة وبيع ومسح النقاط/الرسائل/السحكات (بيع نقطة = 50 رسالة)
- القبول التلقائي / رفض طلبات الانضمام + حظر قناة + صنع كود + كتم/حظر عام + مطورين + نسخة احتياطية."""
import io
import json
import secrets
import time
from telegram import ChatPermissions, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ChatMemberStatus
from telegram.ext import CallbackQueryHandler, ChatJoinRequestHandler
from core.kb import btn
from core.router import exact, prefix, norm
from core import ranks as R
from core import content
from core.store import (
settings, ranks_db, stats, users_db,
find_user_by_username, get_counter, bump, clear_counter, activity_label,
)
from modules import admin as admin_mod
from modules import services as srv_mod
from modules.toggles import tg_on
from strings_ar import S, RANK_NAMES, frame
import config
FULL = ChatPermissions(can_send_messages=True, can_send_other_messages=True,
can_send_polls=True, can_add_web_page_previews=True)
NONE = ChatPermissions(can_send_messages=False)
def is_gmuted(uid):
return str(uid) in settings.get("global", "gmuted", {})
def get_bot_name():
return settings.get("global", "bot_name", "") or config.BOT_NAME
async def _need(update, lvl_name):
if await R.effective_level(update) < R.level(lvl_name):
await update.message.reply_text(S["need_rank"])
return False
return True
async def _need_dev(update):
if not R.is_dev(update.effective_user.id):
await update.message.reply_text("✧︙الأمر ده للمطور بس.")
return False
return True
def _resolve_target(update, arg=""):
"""يرجع (user_id, display_name, username) سواء بالرد أو بـ @المعرف أو بالايدي."""
r = update.message.reply_to_message if update.message else None
if r and r.from_user:
u = r.from_user
return u.id, u.first_name, (u.username or "")
raw = (arg or "").strip()
if raw:
tok = raw.split()[0]
if tok.isdigit():
return int(tok), tok, ""
info = find_user_by_username(update.effective_chat.id, tok)
if info:
return info["id"], info.get("first") or info.get("name") or tok, info.get("user", "")
return None, None, ""
# ---------- المالك بالصورة والبايو وزر البروفايل ----------
@exact("المالك")
async def show_owner(update, ctx, arg=""):
chat = update.effective_chat
try:
adms = await chat.get_administrators()
owner = next((a.user for a in adms if a.status == ChatMemberStatus.OWNER), None)
except Exception:
owner = None
if not owner:
await update.message.reply_text("✧︙لم يتم العثور على مالك المجموعه.")
return
try:
c = await ctx.bot.get_chat(owner.id)
bio = c.bio or "لا يوجد"
except Exception:
bio = "لا يوجد"
url = f"https://t.me/{owner.username}" if owner.username else f"tg://user?id={owner.id}"
kb = InlineKeyboardMarkup([[InlineKeyboardButton(owner.first_name or "المالك", url=url)]])
cap = f"• USE ↦ {owner.first_name}\n\n• bio ↦ {bio}"
try:
ph = await ctx.bot.get_user_profile_photos(owner.id, limit=1)
if ph.total_count:
await update.message.reply_photo(ph.photos[0][-1].file_id, caption=cap, reply_markup=kb)
return
except Exception:
pass
await update.message.reply_text(cap, reply_markup=kb)
# ---------- رفع الادمنيه / مسح الادمنيه / رفع المالك / ارفعني مالك ----------
@exact("رفع الادمنيه")
async def sync_admins(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
chat = update.effective_chat
try:
adms = await chat.get_administrators()
except Exception:
await update.message.reply_text("✧︙تعذّر جلب قائمة المشرفين.")
return
cnt = 0
for a in adms:
if a.user.is_bot:
continue
if a.status == ChatMemberStatus.OWNER:
R.set_rank(chat.id, a.user.id, "مالك")
else:
R.set_rank(chat.id, a.user.id, "ادمن")
cnt += 1
await update.message.reply_text(f"- تم رفع المالك و ↫ {cnt} ادمن ✅")
@exact("رفع المالك", "ارفعني مالك")
async def promote_owner_self(update, ctx, arg=""):
chat = update.effective_chat
u = update.effective_user
try:
m = await chat.get_member(u.id)
if m.status == ChatMemberStatus.OWNER or (m.status == ChatMemberStatus.ADMINISTRATOR and getattr(m, "can_promote_members", False)):
R.set_rank(chat.id, u.id, "مالك")
await update.message.reply_text(f"👑 تم رفع {u.first_name} مالك المجموعه بنجاح ✅")
return
except Exception:
pass
await update.message.reply_text("✧︙الأمر ده متاح لمالك الجروب أو المشرف بصلاحيات كاملة فقط.")
# ---------- مسح القوائم بالعدد الدقيق ----------
CLEAR_RANK_MAP = {
"مسح الادمنيه": ("ادمن", "الادمنيه"),
"مسح المدراء": ("مدير", "المدراء"),
"مسح المميزين": ("مميز", "المميزين"),
"مسح المنشئين": ("منشئ", "المنشئين"),
"مسح المنشئين الاساسيين": ("منشئ اساسي", "المنشئين الاساسيين"),
"مسح المالكين": ("مالك", "المالكين"),
}
def _mk_rank_clear(rk, lbl):
async def h(update, ctx, arg=""):
if not await _need(update, "منشئ"):
return
chat = update.effective_chat.id
d = ranks_db.get(chat, "r", {})
removed = sum(1 for r in d.values() if r == rk)
new_d = {u: r for u, r in d.items() if r != rk}
ranks_db.set(chat, "r", new_d)
await update.message.reply_text(f"- تم مسح {removed} من {lbl} ✅")
return h
for _cmd, (_rk, _lbl) in CLEAR_RANK_MAP.items():
exact(_cmd)(_mk_rank_clear(_rk, _lbl))
@exact("مسح المحظورين", "مسح المطرودين")
async def clear_banned(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
d = settings.get(update.effective_chat.id, "banned", {})
n = len(d)
settings.set(update.effective_chat.id, "banned", {})
await update.message.reply_text(f"- تم مسح {n} من المحظورين ✅")
@exact("مسح المكتومين", "مسح المقيدين")
async def clear_muted(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
d = settings.get(update.effective_chat.id, "muted", {})
n = len(d)
settings.set(update.effective_chat.id, "muted", {})
await update.message.reply_text(f"- تم مسح {n} من المكتومين ✅")
@exact("مسح القوائم", "تنزيل جميع الرتب")
async def clear_all_lists(update, ctx, arg=""):
if not await _need(update, "مالك"):
return
chat = update.effective_chat.id
ranks_db.set(chat, "r", {})
await update.message.reply_text("✧︙تم تنزيل ومسح جميع الرتب في المجموعه ✅")
@exact("تنزيل الكل")
async def demote_user_all(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
R.set_rank(update.effective_chat.id, uid, "عضو")
d = ranks_db.get(update.effective_chat.id, "f", {})
d.pop(str(uid), None)
ranks_db.set(update.effective_chat.id, "f", d)
await update.message.reply_text(f"✧︙تم تنزيل {name} من جميع الرتب ✅")
@prefix("تنزيل الكل")
async def demote_user_all_p(update, ctx, arg):
await demote_user_all(update, ctx, arg)
# ---------- أوامر العقوبات والكشف بالرد أو @المعرف ----------
@prefix("حظر")
async def ban_p(update, ctx, arg):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
try:
await update.effective_chat.ban_member(uid)
d = settings.get(update.effective_chat.id, "banned", {})
d[str(uid)] = name
settings.set(update.effective_chat.id, "banned", d)
await update.message.reply_text(f"🚫 تم حظر {name} ✅")
except Exception:
await update.message.reply_text("✧︙تعذّر الحظر، تأكد من صلاحيات البوت.")
@prefix("الغاء الحظر", "الغاء حظر")
async def unban_p(update, ctx, arg):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
try:
await update.effective_chat.unban_member(uid, only_if_banned=True)
d = settings.get(update.effective_chat.id, "banned", {})
d.pop(str(uid), None)
settings.set(update.effective_chat.id, "banned", d)
await update.message.reply_text(f"✅ تم إلغاء حظر {name}")
except Exception:
await update.message.reply_text("✧︙تعذّر إلغاء الحظر.")
@prefix("كتم", "تقييد")
async def mute_p(update, ctx, arg):
if not await _need(update, "ادمن"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
try:
await update.effective_chat.restrict_member(uid, NONE)
d = settings.get(update.effective_chat.id, "muted", {})
d[str(uid)] = name
settings.set(update.effective_chat.id, "muted", d)
await update.message.reply_text(S["muted"].format(name=name))
except Exception:
await update.message.reply_text("✧︙تعذّر الكتم.")
@prefix("الغاء كتم", "الغاء تقييد", "فك التقييد", "فك تقييد")
async def unmute_p(update, ctx, arg):
if not await _need(update, "ادمن"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
try:
await update.effective_chat.restrict_member(uid, FULL)
d = settings.get(update.effective_chat.id, "muted", {})
d.pop(str(uid), None)
settings.set(update.effective_chat.id, "muted", d)
await update.message.reply_text(S["unmuted"].format(name=name))
except Exception:
await update.message.reply_text("✧︙تعذّر إلغاء الكتم.")
@exact("تقييد")
async def restrict_e(update, ctx, arg=""):
await admin_mod.mute(update, ctx, arg)
@exact("فك التقييد", "فك تقييد", "الغاء تقييد", "رفع القيود")
async def unrestrict_e(update, ctx, arg=""):
await admin_mod.unmute(update, ctx, arg)
@prefix("طرد")
async def kick_p(update, ctx, arg):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
try:
await update.effective_chat.ban_member(uid)
await update.effective_chat.unban_member(uid)
await update.message.reply_text(S["kicked"].format(name=name))
except Exception:
await update.message.reply_text("✧︙تعذّر الطرد.")
@prefix("انذار", "تحذير")
async def warn_p(update, ctx, arg):
if not await _need(update, "ادمن"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
chat = update.effective_chat.id
w = settings.get(chat, "warns", {})
n = w.get(str(uid), 0) + 1
if n >= 3:
w.pop(str(uid), None)
settings.set(chat, "warns", w)
try:
await update.effective_chat.restrict_member(uid, NONE, until_date=int(time.time()) + 3600)
except Exception:
pass
await update.message.reply_text(S["warn_muted"].format(name=name))
else:
w[str(uid)] = n
settings.set(chat, "warns", w)
await update.message.reply_text(S["warn_got"].format(name=name, n=n))
@prefix("كشف")
async def kashf_p(update, ctx, arg):
uid, name, uname = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
chat = update.effective_chat.id
msgs = get_counter(chat, uid, "msgs")
await update.message.reply_text(S["kashf_fmt"].format(
name=name, id=uid, user=("@" + uname) if uname else "-",
rank=R.get_custom_rank_label(chat, uid), msgs=msgs,
))
@prefix("الرتبه")
async def his_rank_p(update, ctx, arg):
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
await update.message.reply_text(S["rank_is"].format(name=name, rank=R.get_custom_rank_label(update.effective_chat.id, uid)))
# ---------- لوحة تحكم العضو (تحكم) بالأزرار ----------
@exact("تحكم")
async def control_e(update, ctx, arg=""):
await control_p(update, ctx, "")
@prefix("تحكم")
async def control_p(update, ctx, arg):
if not await _need(update, "ادمن"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text("✧︙رد على العضو أو اكتب: تحكم @المعرف")
return
kb = InlineKeyboardMarkup([
[btn("🔇 كتم", f"ctl:mute:{uid}", style="danger"), btn("🔊 فك كتم", f"ctl:unmute:{uid}", style="success")],
[btn("🚫 حظر", f"ctl:ban:{uid}", style="danger"), btn("👢 طرد", f"ctl:kick:{uid}", style="danger")],
[btn("⚠️ إنذار", f"ctl:warn:{uid}", style="primary"), btn("⭐ رفع مميز", f"ctl:vip:{uid}", style="success")],
[btn("- اخفاء -", "ctl:hide:0", style="danger")],
])
await update.message.reply_text(f"⚙️ لوحة التحكم السريع للعضو: {name} (`{uid}`)", parse_mode="Markdown", reply_markup=kb)
async def control_cb(update, ctx):
q = update.callback_query
_, act, uid_s = q.data.split(":")
if act == "hide":
await q.answer()
try:
await q.delete_message()
except Exception:
pass
return
if await R.effective_level(update, q.from_user) < R.level("ادمن"):
await q.answer(S["need_admin"], show_alert=True)
return
uid = int(uid_s)
chat = q.message.chat
try:
if act == "mute":
await chat.restrict_member(uid, NONE)
await q.answer("تم الكتم ✅", show_alert=True)
elif act == "unmute":
await chat.restrict_member(uid, FULL)
await q.answer("تم فك الكتم ✅", show_alert=True)
elif act == "ban":
await chat.ban_member(uid)
await q.answer("تم الحظر ✅", show_alert=True)
elif act == "kick":
await chat.ban_member(uid)
await chat.unban_member(uid)
await q.answer("تم الطرد ✅", show_alert=True)
elif act == "warn":
w = settings.get(chat.id, "warns", {})
n = w.get(str(uid), 0) + 1
w[str(uid)] = n
settings.set(chat.id, "warns", w)
await q.answer(f"تم إضافة إنذار ({n}/3) ⚠️", show_alert=True)
elif act == "vip":
R.set_rank(chat.id, uid, "مميز")
await q.answer("تم رفعه مميز ⭐", show_alert=True)
except Exception:
await q.answer("تعذّر تنفيذ الإجراء، تأكد من صلاحيات البوت.", show_alert=True)
# ---------- تغيير رد الرتب + ضع رتبه / مسح رتبه ----------
@prefix("تغيير رد")
async def change_rank_reply(update, ctx, arg):
if not await _need(update, "مدير"):
return
parts = arg.strip().split(maxsplit=1)
if len(parts) < 2:
await update.message.reply_text("✧︙الصيغة: تغيير رد <اسم الرتبة> <النص الجديد>\nمثال: تغيير رد الادمن حارس الجروب 🛡️")
return
rk, txt = norm(parts[0]), parts[1].strip()
d = settings.get(update.effective_chat.id, "rank_replies", {})
d[rk] = txt
settings.set(update.effective_chat.id, "rank_replies", d)
await update.message.reply_text(f"✧︙تم تغيير رد رتبة ({parts[0]}) إلى: {txt} ✅")
@prefix("مسح رد الرتبه", "مسح رد رتبه")
async def del_rank_reply(update, ctx, arg):
if not await _need(update, "مدير"):
return
rk = norm(arg.strip())
d = settings.get(update.effective_chat.id, "rank_replies", {})
d.pop(rk, None)
settings.set(update.effective_chat.id, "rank_replies", d)
await update.message.reply_text("✧︙تم مسح رد الرتبة المخصص ✅")
@prefix("ضع رتبه")
async def set_custom_badge(update, ctx, arg):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, "")
if not uid:
await update.message.reply_text("✧︙رد على العضو واكتب: ضع رتبه + اسم الرتبة")
return
badge = arg.strip()
if not badge:
await update.message.reply_text("✧︙اكتب اسم الرتبة بعد الأمر.")
return
d = ranks_db.get(update.effective_chat.id, "custom_badge", {})
d[str(uid)] = badge
ranks_db.set(update.effective_chat.id, "custom_badge", d)
await update.message.reply_text(f"✧︙تم وضع رتبة ({badge}) للعضو {name} ✅")
@exact("مسح رتبه")
async def del_custom_badge(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
d = ranks_db.get(update.effective_chat.id, "custom_badge", {})
d.pop(str(uid), None)
ranks_db.set(update.effective_chat.id, "custom_badge", d)
await update.message.reply_text(f"✧︙تم مسح الرتبة المخصصة عن {name} ✅")
# ---------- صلاحياتي / صلاحياته / صلاحيات المجموعه / صلاحيات المشرفين ----------
async def _fmt_perms(chat, uid, name):
try:
m = await chat.get_member(uid)
st = m.status
if st == ChatMemberStatus.OWNER:
return f"👑 {name}: مالك المجموعه (كل الصلاحيات)."
if st == ChatMemberStatus.ADMINISTRATOR:
items = [
("حذف الرسائل", getattr(m, "can_delete_messages", False)),
("تقييد الأعضاء", getattr(m, "can_restrict_members", False)),
("تثبيت الرسائل", getattr(m, "can_pin_messages", False)),
("دعوة الأعضاء", getattr(m, "can_invite_users", False)),
("إضافة مشرفين", getattr(m, "can_promote_members", False)),
("تغيير معلومات الجروب", getattr(m, "can_change_info", False)),
]
lines = [f"🛡️ صلاحيات {name}:"] + [f"• {k}: {'✓' if v else '✗'}" for k, v in items]
return "\n".join(lines)
return f"👤 {name}: عضو عادي بدون صلاحيات إشراف."
except Exception:
return "✧︙تعذّر قراءة الصلاحيات."
@exact("صلاحياتي")
async def my_perms(update, ctx, arg=""):
u = update.effective_user
await update.message.reply_text(await _fmt_perms(update.effective_chat, u.id, u.first_name))
@exact("صلاحياته")
async def his_perms_e(update, ctx, arg=""):
await his_perms_p(update, ctx, "")
@prefix("صلاحياته")
async def his_perms_p(update, ctx, arg):
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
await update.message.reply_text(await _fmt_perms(update.effective_chat, uid, name))
@exact("صلاحيات المجموعه")
async def group_perms(update, ctx, arg=""):
c = await ctx.bot.get_chat(update.effective_chat.id)
p = c.permissions
if not p:
await update.message.reply_text("✧︙تعذّر قراءة صلاحيات المجموعه.")
return
items = [
("إرسال رسائل", p.can_send_messages),
("إرسال استفتاءات", p.can_send_polls),
("إرسال وسائط أخرى", p.can_send_other_messages),
("معاينة الروابط", p.can_add_web_page_previews),
("دعوة أعضاء", p.can_invite_users),
]
await update.message.reply_text("⚙️ صلاحيات أعضاء المجموعه:\n" + "\n".join(f"• {k}: {'✓' if v else '✗'}" for k, v in items))
@exact("صلاحيات المشرفين", "المشرفين", "الاداريين", "الادارين")
async def admins_perms(update, ctx, arg=""):
try:
adms = await update.effective_chat.get_administrators()
lines = [f"🛡️ مشرفي المجموعه ({len(adms)}):"]
for a in adms:
icon = "👑" if a.status == ChatMemberStatus.OWNER else "•"
lines.append(f"{icon} {a.user.first_name}")
await update.message.reply_text("\n".join(lines))
except Exception:
await update.message.reply_text("✧︙تعذّر جلب المشرفين.")
# ---------- إضافة / بيع / مسح النقاط والرسائل والسحكات ----------
@prefix("اضف رسائل")
async def add_msgs(update, ctx, arg):
if not await _need(update, "مدير") or not tg_on(update.effective_chat.id, "extras_add"):
return
uid, name, _ = _resolve_target(update, "")
if not uid or not arg.strip().isdigit():
await update.message.reply_text("✧︙رد على العضو واكتب: اضف رسائل + العدد")
return
tot = bump(update.effective_chat.id, uid, "msgs", int(arg.strip()))
await update.message.reply_text(f"✧︙تمت إضافة {arg.strip()} رسالة لـ {name} (الإجمالي: {tot}) ✅")
@prefix("اضف نقاط")
async def add_pts(update, ctx, arg):
if not await _need(update, "مدير") or not tg_on(update.effective_chat.id, "extras_add"):
return
uid, name, _ = _resolve_target(update, "")
if not uid or not arg.strip().isdigit():
await update.message.reply_text("✧︙رد على العضو واكتب: اضف نقاط + العدد")
return
tot = bump(update.effective_chat.id, uid, "pts", int(arg.strip()))
await update.message.reply_text(f"✧︙تمت إضافة {arg.strip()} نقطة لـ {name} (الإجمالي: {tot}) ✅")
@prefix("اضف سحكات")
async def add_del(update, ctx, arg):
if not await _need(update, "مدير") or not tg_on(update.effective_chat.id, "extras_add"):
return
uid, name, _ = _resolve_target(update, "")
if not uid or not arg.strip().isdigit():
await update.message.reply_text("✧︙رد على العضو واكتب: اضف سحكات + العدد")
return
tot = bump(update.effective_chat.id, uid, "del", int(arg.strip()))
await update.message.reply_text(f"✧︙تمت إضافة {arg.strip()} سحكة لـ {name} (الإجمالي: {tot}) ✅")
@prefix("بيع نقاطي")
async def sell_my_pts(update, ctx, arg):
if not arg.strip().isdigit():
await update.message.reply_text("✧︙اكتب: بيع نقاطي + العدد (كل نقطة = 50 رسالة)")
return
n = int(arg.strip())
chat, uid = update.effective_chat.id, update.effective_user.id
cur = get_counter(chat, uid, "pts")
if n <= 0 or n > cur:
await update.message.reply_text(f"✧︙نقاطك الحالية ({cur}) لا تكفي.")
return
bump(chat, uid, "pts", -n)
msgs_gained = n * 50
tot_m = bump(chat, uid, "msgs", msgs_gained)
await update.message.reply_text(f"💱 تم بيع {n} نقطة مقابل {msgs_gained} رسالة! رسائلك الآن: {tot_m} ✅")
@exact("مسح نقاطي")
async def clear_my_pts(update, ctx, arg=""):
clear_counter(update.effective_chat.id, update.effective_user.id, "pts")
await update.message.reply_text("✧︙تم مسح نقاطك ✅")
@exact("مسح نقاطه")
async def clear_his_pts(update, ctx, arg=""):
if not await _need(update, "منشئ اساسي"):
return
uid, name, _ = _resolve_target(update, "")
if not uid:
await update.message.reply_text(S["need_reply"])
return
clear_counter(update.effective_chat.id, uid, "pts")
await update.message.reply_text(f"✧︙تم مسح نقاط {name} ✅")
@exact("مسح رسائله")
async def clear_his_msgs(update, ctx, arg=""):
if not await _need(update, "منشئ اساسي"):
return
uid, name, _ = _resolve_target(update, "")
if not uid:
await update.message.reply_text(S["need_reply"])
return
clear_counter(update.effective_chat.id, uid, "msgs")
await update.message.reply_text(f"✧︙تم مسح رسائل {name} ✅")
# ---------- أوامر المجموعه الإضافية (تثبيت، مسح بالعدد، كود تمويل، حظر قناة، إلخ) ----------
@exact("الغاء التثبيت الكل", "الغاء تثبيت الكل", "مسح التثبيتات")
async def unpin_all(update, ctx, arg=""):
if not await _need(update, "ادمن"):
return
try:
await update.effective_chat.unpin_all_messages()
await update.message.reply_text("✧︙تم إلغاء تثبيت جميع الرسائل ✅")
except Exception:
await update.message.reply_text("✧︙تعذّر إلغاء التثبيت.")
@prefix("مسح")
async def bulk_delete(update, ctx, arg):
if not await _need(update, "ادمن"):
return
raw = arg.strip()
if not raw.isdigit():
return
n = min(max(int(raw), 1), 100)
chat_id, mid = update.effective_chat.id, update.message.message_id
deleted = 0
for i in range(mid, max(mid - n - 1, 0), -1):
try:
await ctx.bot.delete_message(chat_id, i)
deleted += 1
except Exception:
pass
try:
await ctx.bot.send_message(chat_id, f"🧹 تم مسح {deleted} رسالة ✅")
except Exception:
pass
@exact("تفعيل الكل")
async def enable_all_basic(update, ctx, arg=""):
if not await _need(update, "منشئ"):
return
chat = update.effective_chat.id
for k in ("welcome", "link", "id", "idphoto", "replies", "games", "fun", "bank"):
settings.set(chat, "tg_" + k, True)
await update.message.reply_text("✧︙تم تفعيل جميع الأوامر الأساسية في المجموعه ✅")
@exact("ترتيب الاوامر")
async def order_cmds_help(update, ctx, arg=""):
await update.message.reply_text(S["order_help"])
@exact("استعاده الاوامر", "مسح الاوامر", "مسح الاوامر المضافه")
async def restore_cmds(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
settings.set(update.effective_chat.id, "aliases", {})
await update.message.reply_text("✧︙تمت استعادة الأوامر الافتراضية ومسح كل الأوامر البديلة ✅")
@exact("الاوامر المضافه", "قائمه الاوامر")
async def list_aliases(update, ctx, arg=""):
al = settings.get(update.effective_chat.id, "aliases", {})
if not al:
await update.message.reply_text("✧︙لا توجد أوامر بديلة مضافة حالياً.")
return
await update.message.reply_text("⌯ ═══ ❨ الأوامر المضافة ❩ ═══ ⌯\n" + "\n".join(f"• {k} ← {v}" for k, v in al.items()))
@exact("مسح قائمه المنع")
async def clear_blocked(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
settings.set(update.effective_chat.id, "blocked", [])
await update.message.reply_text("✧︙تم مسح قائمة الكلمات الممنوعة ✅")
@exact("مسح الوصف")
async def clear_desc(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
try:
await update.effective_chat.set_description("")
await update.message.reply_text("✧︙تم مسح وصف المجموعه ✅")
except Exception:
await update.message.reply_text("✧︙تعذّر مسح الوصف.")
@exact("مسح الترحيب")
async def clear_welcome(update, ctx, arg=""):
if not await _need(update, "مدير"):
return
settings.set(update.effective_chat.id, "welcome", "")
await update.message.reply_text("✧︙تم مسح الترحيب المخصص ✅")
@exact("تصفير الترند")
async def reset_trend(update, ctx, arg=""):
if not await _need(update, "منشئ"):
return
stats.set(update.effective_chat.id, "msgs", {})
await update.message.reply_text("✧︙تم تصفير عداد الترند والمتفاعلين ✅")
@exact("صنع كود")
async def make_code(update, ctx, arg=""):
if not await _need(update, "منشئ اساسي"):
return
code = "VIP-" + secrets.token_hex(3).upper()
codes = settings.get(update.effective_chat.id, "promo_codes", {})
codes[code] = {"pts": 10, "used": False}
settings.set(update.effective_chat.id, "promo_codes", codes)
await update.message.reply_text(f"🎟️ تم صنع كود تمويل جديد: `{code}`\n✧︙يمنح +10 نقاط لأول عضو يكتب: تفعيل كود {code}", parse_mode="Markdown")
@prefix("تفعيل كود")
async def redeem_code(update, ctx, arg):
code = arg.strip().upper()
chat = update.effective_chat.id
codes = settings.get(chat, "promo_codes", {})
c = codes.get(code)
if not c or c.get("used"):
await update.message.reply_text("❌ الكود غير صالح أو مستخدم بالفعل.")
return
c["used"] = True
settings.set(chat, "promo_codes", codes)
pts = bump(chat, update.effective_user.id, "pts", c["pts"])
await update.message.reply_text(f"🎉 مبروك! تم تفعيل الكود وحصلت على +{c['pts']} نقاط (إجمالي نقاطك: {pts}) ✅")
@exact("حظر قناة", "حظر قناه")
async def ban_channel(update, ctx, arg=""):
if not await _need(update, "منشئ"):
return
r = update.message.reply_to_message
sc = getattr(r, "sender_chat", None) if r else None
if not sc:
await update.message.reply_text("✧︙رد على رسالة مرسلة باسم قناة واكتب: حظر قناة")
return
try:
await update.effective_chat.ban_sender_chat(sc.id)
await update.message.reply_text(f"🚫 تم حظر القناة ({sc.title}) من الإرسال في المجموعه ✅")
except Exception:
await update.message.reply_text("✧︙تعذّر حظر القناة.")
# ---------- طلبات الانضمام (القبول التلقائي / رفض الطلبات) ----------
async def on_join_request(update, ctx):
req = update.chat_join_request
if not req:
return
cid = req.chat.id
try:
if tg_on(cid, "auto_accept"):
await req.approve()
elif tg_on(cid, "auto_reject"):
await req.decline()
except Exception:
pass
# ---------- أوامر المطورين والنسخ الاحتياطي ----------
@exact("كتم عام")
async def gmute(update, ctx, arg=""):
if not await _need_dev(update):
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
d = settings.get("global", "gmuted", {})
d[str(uid)] = name
settings.set("global", "gmuted", d)
await update.message.reply_text(S["global_mute_done"].format(name=name))
@exact("الغاء كتم عام")
async def ungmute(update, ctx, arg=""):
if not await _need_dev(update):
return
uid, _, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
d = settings.get("global", "gmuted", {})
d.pop(str(uid), None)
settings.set("global", "gmuted", d)
await update.message.reply_text(S["done"])
@exact("المكتومين عام")
async def gmuted_list(update, ctx, arg=""):
if not await _need_dev(update):
return
d = settings.get("global", "gmuted", {})
await update.message.reply_text("🔇 المكتومين عام:\n" + ("\n".join(f"• {n} ({u})" for u, n in d.items()) or "• لا يوجد"))
@exact("المحظورين عام", "المحضورين عام", "قائمه العام")
async def gbanned_list(update, ctx, arg=""):
if not await _need_dev(update):
return
gb = settings.get("global", "gbanned", {})
gm = settings.get("global", "gmuted", {})
lines = ["⌯ ═══ ❨ قائمة العام ❩ ═══ ⌯", f"🚫 المحظورين عام ({len(gb)}):"]
lines += [f"• {n} ({u})" for u, n in gb.items()] or ["• لا يوجد"]
lines.append(f"🔇 المكتومين عام ({len(gm)}):")
lines += [f"• {n} ({u})" for u, n in gm.items()] or ["• لا يوجد"]
await update.message.reply_text("\n".join(lines))
@exact("رفع مطور")
async def add_dev(update, ctx, arg=""):
if not R.is_owner(update.effective_user.id):
await update.message.reply_text("✧︙الأمر ده لصاحب البوت الأساسي بس.")
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
d = settings.get("global", "devs", {})
d[str(uid)] = name
settings.set("global", "devs", d)
await update.message.reply_text(f"✧︙تم رفع {name} مطور في البوت ✅")
@exact("تنزيل مطور")
async def rem_dev(update, ctx, arg=""):
if not R.is_owner(update.effective_user.id):
await update.message.reply_text("✧︙الأمر ده لصاحب البوت الأساسي بس.")
return
uid, name, _ = _resolve_target(update, arg)
if not uid:
await update.message.reply_text(S["need_reply"])
return
d = settings.get("global", "devs", {})
d.pop(str(uid), None)
settings.set("global", "devs", d)
await update.message.reply_text(f"✧︙تم تنزيل {name} من المطورين ✅")
@exact("المطورين")
async def list_devs(update, ctx, arg=""):
d = settings.get("global", "devs", {})
lines = ["👨💻 مطوري البوت:"]
if config.OWNER_ID:
lines.append(f"👑 المطور الأساسي: {config.DEV_NAME or config.OWNER_ID}")
for u, n in d.items():
lines.append(f"• {n} ({u})")
await update.message.reply_text("\n".join(lines))
@prefix("ضع كليشه المطور", "ضع كليشة المطور")
async def set_dev_tpl(update, ctx, arg):
if not await _need_dev(update):
return
settings.set("global", "dev_tpl", arg.strip())
await update.message.reply_text("✧︙تم حفظ كليشة المطور ✅")
@exact("مسح كليشه المطور", "مسح كليشة المطور")
async def del_dev_tpl(update, ctx, arg=""):
if not await _need_dev(update):
return
settings.set("global", "dev_tpl", "")
await update.message.reply_text("✧︙تم مسح كليشة المطور ✅")
@prefix("تعيين كليشه الستارت", "تعيين كليشة الستارت")
async def set_start_tpl(update, ctx, arg):
if not await _need_dev(update):
return
settings.set("global", "start_tpl", arg.strip())
await update.message.reply_text("✧︙تم حفظ رسالة الترحيب الرئيسية ✅")
@exact("مسح كليشه الستارت", "مسح كليشة الستارت")
async def del_start_tpl(update, ctx, arg=""):
if not await _need_dev(update):
return
settings.set("global", "start_tpl", "")
await update.message.reply_text("✧︙تمت استعادة رسالة الترحيب الافتراضية ✅")
@prefix("ضع اسم للبوت")
async def set_bot_name(update, ctx, arg):
if not await _need_dev(update):
return
if arg.strip():
settings.set("global", "bot_name", arg.strip())
await update.message.reply_text(f"✧︙تم تغيير اسم البوت إلى: {arg.strip()} ✅")
@exact("المجموعات", "قائمه المجموعات", "الاحصائيات")
async def bot_stats(update, ctx, arg=""):
if not await _need_dev(update):
return
groups = [k for k, v in settings.d.items() if k != "global" and v.get("active")]
tot_msgs = sum(sum(v.get("msgs", {}).values()) for v in stats.d.values())
await update.message.reply_text(frame(
"احصائيات البوت 📊",
f"اسم البوت: {get_bot_name()}",
f"المجموعات المفعلة: {len(groups)}",
f"إجمالي الرسايل: {tot_msgs:,}",
))
@exact("نسخه احتياطيه", "نسخه احتياطيه للمجموعات")
async def backup_cmd(update, ctx, arg=""):
if not R.is_owner(update.effective_user.id):
await update.message.reply_text("✧︙النسخة الاحتياطية لصاحب البوت الأساسي بس.")
return
payload = {"settings": settings.d, "ranks": ranks_db.d, "stats": stats.d}
buf = io.BytesIO(json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8"))
buf.name = "bot_backup.json"
await update.message.reply_document(document=buf, caption="💾 نسخة احتياطية كاملة لإعدادات ورتب وإحصائيات البوت ✅")
@exact("تحديث الملفات")
async def reload_files(update, ctx, arg=""):
if not await _need_dev(update):
return
content.clear_cache()
await update.message.reply_text("🔄 تم تحديث ذاكرة المحتوى بنجاح ✅")
@exact("فحص", "فحص البوت", "تيست")
async def health_check(update, ctx, arg=""):
await update.message.reply_text(f"🚀 {get_bot_name()} شغال بكامل طاقته ⚡")
@exact("كشف القيود")
async def check_restrictions(update, ctx, arg=""):
uid, name, _ = _resolve_target(update, arg)
if not uid:
uid, name = update.effective_user.id, update.effective_user.first_name
try:
m = await update.effective_chat.get_member(uid)
st = {
"creator": "مالك المجموعه 👑", "administrator": "مشرف 🛡️",
"member": "عضو عادي (بدون قيود) ✅", "restricted": "مقيد / مكتوم 🔇",
"left": "غادر المجموعه", "kicked": "محظور 🚫",
}.get(str(m.status).split(".")[-1].lower(), str(m.status))
await update.message.reply_text(f"✧︙حالة {name}: {st}")
except Exception:
await update.message.reply_text("✧︙تعذّر فحص حالة العضو.")
@exact("ايدي المجموعه")
async def group_id(update, ctx, arg=""):
await update.message.reply_text(f"🆔 ايدي المجموعه: `{update.effective_chat.id}`", parse_mode="Markdown")
@exact("ادفرني")
async def adforni(update, ctx, arg=""):
await admin_mod.kickme(update, ctx, arg)
@exact("ترند", "النتفاعلين")
async def trend_alias(update, ctx, arg=""):
await srv_mod.top(update, ctx, arg)
HANDLERS = [
CallbackQueryHandler(control_cb, pattern=r"^ctl:"),
ChatJoinRequestHandler(on_join_request),
]
|