"""الإدارة المتقدمة والمدراء والمنشئين والمالكين والمطورين: - دعم الرد و @المعرف في أوامر العقوبات والكشف - رفع الادمنيه / مسح الادمنيه بالعدد الدقيق - المالك (بالصورة والبايو وزر البروفايل) + ارفعني مالك + رفع المالك - لوحة تحكم العضو (تحكم) بالأزرار - تغيير رد الرتب + ضع رتبه + صلاحياتي/صلاحياته/صلاحيات المجموعه/صلاحيات المشرفين - إضافة وبيع ومسح النقاط/الرسائل/السحكات (بيع نقطة = 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), ]