Spaces:
Running
Running
Update bot_core.py
Browse files- bot_core.py +263 -50
bot_core.py
CHANGED
|
@@ -1922,8 +1922,8 @@ async def show_public_sources_menu_from_message(message):
|
|
| 1922 |
text = f"**المصادر العامة ({len(srcs)}):**\n➕ إضافة مصدر/مصادر: يضيف قنوات عامة جديدة يراقبها البوت (رابط/يوزر/ID).\n🗑 حذف مصدر عام: يحذف مصدراً عاماً من المراقبة."
|
| 1923 |
text += "\n\n".join(entity_details_line(m, is_source=True) for m in meta_list) if srcs else "لا توجد."
|
| 1924 |
buttons = [
|
| 1925 |
-
[InlineKeyboardButton("➕ إضافة مصدر/مصادر", callback_data="add_public_src")],
|
| 1926 |
-
[InlineKeyboardButton("🗑 حذف مصدر عام", callback_data="del_public_src")],
|
| 1927 |
nav_row("main_menu"),
|
| 1928 |
]
|
| 1929 |
await message.reply(text, reply_markup=InlineKeyboardMarkup(buttons))
|
|
@@ -1972,27 +1972,181 @@ def format_bulk_report(title, results):
|
|
| 1972 |
lines.extend([f"• {raw}: {err}" for _, raw, err in failed[:20]])
|
| 1973 |
return "\n".join(lines)
|
| 1974 |
|
| 1975 |
-
|
| 1976 |
-
|
| 1977 |
-
|
| 1978 |
-
|
| 1979 |
-
|
| 1980 |
-
|
| 1981 |
-
|
| 1982 |
-
|
| 1983 |
-
|
| 1984 |
-
|
| 1985 |
-
|
| 1986 |
-
|
| 1987 |
-
|
| 1988 |
-
|
| 1989 |
-
|
| 1990 |
-
|
| 1991 |
-
|
| 1992 |
-
|
| 1993 |
-
|
| 1994 |
-
|
| 1995 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1996 |
|
| 1997 |
|
| 1998 |
async def section_menu(client, callback):
|
|
@@ -2073,7 +2227,7 @@ async def start(client, message):
|
|
| 2073 |
await message.reply(f"❌ غير مصرح. معرفك: `{user_id}`")
|
| 2074 |
return
|
| 2075 |
|
| 2076 |
-
await message.reply("أهلاً بك في لوحة تحكم البوت:", reply_markup=
|
| 2077 |
|
| 2078 |
async def export_callback(client, callback):
|
| 2079 |
try:
|
|
@@ -2251,9 +2405,9 @@ async def confirm_purge_published(client, callback):
|
|
| 2251 |
|
| 2252 |
def channel_buttons(ch_id):
|
| 2253 |
buttons = [
|
| 2254 |
-
InlineKeyboardButton("📰 إعدادات المنشورات", callback_data=f"postset_{ch_id}"),
|
| 2255 |
-
InlineKeyboardButton("📡 المصادر", callback_data=f"srcset_{ch_id}"),
|
| 2256 |
-
InlineKeyboardButton("⚙️ الإعدادات العامة", callback_data=f"genset_{ch_id}"),
|
| 2257 |
]
|
| 2258 |
rows = grid_buttons(buttons, 2)
|
| 2259 |
rows.append([InlineKeyboardButton("🔙 رجوع", callback_data="menu_channels"), InlineKeyboardButton("🏠 القائمة الرئيسية", callback_data="main_menu")])
|
|
@@ -2282,16 +2436,16 @@ async def post_settings_menu(client, callback):
|
|
| 2282 |
f"📝 النصوص القصيرة: {'✅ تشغيل' if ignore_short else '❌ إيقاف'}",
|
| 2283 |
callback_data=f"toggle_short_posts|{ch_id}",
|
| 2284 |
),
|
| 2285 |
-
InlineKeyboardButton(
|
| 2286 |
InlineKeyboardButton(f"💬 الاقتباس ({quote_count}/6)", callback_data=f"quotemenu_{ch_id}"),
|
| 2287 |
-
InlineKeyboardButton(
|
| 2288 |
-
InlineKeyboardButton(
|
| 2289 |
-
InlineKeyboardButton(
|
| 2290 |
-
InlineKeyboardButton(
|
| 2291 |
-
InlineKeyboardButton(
|
| 2292 |
-
InlineKeyboardButton(
|
| 2293 |
InlineKeyboardButton(f"{'✅' if not disable_preview else '❌'} معاينة الروابط", callback_data=f"ch_preview_{ch_id}"),
|
| 2294 |
-
InlineKeyboardButton("🧪 اختبار القناة", callback_data=f"testset_{ch_id}"),
|
| 2295 |
]
|
| 2296 |
rows = grid_buttons(buttons, 2)
|
| 2297 |
rows.append(nav_row(f"ch_{ch_id}"))
|
|
@@ -2513,7 +2667,7 @@ async def menu_channels(client, callback):
|
|
| 2513 |
if not channels:
|
| 2514 |
text = "لا توجد قنوات منشورة بعد. اضغط ➕ لإضافتها."
|
| 2515 |
rows = [
|
| 2516 |
-
[InlineKeyboardButton("➕ إضافة قناة/قنوات", callback_data="add_channel")],
|
| 2517 |
nav_row("main_menu")
|
| 2518 |
]
|
| 2519 |
else:
|
|
@@ -2527,7 +2681,7 @@ async def menu_channels(client, callback):
|
|
| 2527 |
text += f"\n✅ {name}{paused}\n {username_txt}\n ID: `{ch['id']}`\n"
|
| 2528 |
btns.append(InlineKeyboardButton(f"⚙️ {name}", callback_data=f"ch_{ch['id']}"))
|
| 2529 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2530 |
-
rows.append([InlineKeyboardButton("➕ إضافة قناة/قنوات", callback_data="add_channel")])
|
| 2531 |
rows.append(nav_row("main_menu"))
|
| 2532 |
await safe_edit(callback, text, InlineKeyboardMarkup(rows))
|
| 2533 |
|
|
@@ -2536,7 +2690,7 @@ async def show_channels_menu_from_message(message):
|
|
| 2536 |
if not channels:
|
| 2537 |
text = "لا توجد قنوات منشورة بعد. اضغط ➕ لإضافتها."
|
| 2538 |
rows = [
|
| 2539 |
-
[InlineKeyboardButton("➕ إضافة قناة/قنوات", callback_data="add_channel")],
|
| 2540 |
nav_row("main_menu")
|
| 2541 |
]
|
| 2542 |
else:
|
|
@@ -2550,7 +2704,7 @@ async def show_channels_menu_from_message(message):
|
|
| 2550 |
text += f"\n✅ {name}{paused}\n {username_txt}\n ID: `{ch['id']}`\n"
|
| 2551 |
btns.append(InlineKeyboardButton(f"⚙️ {name}", callback_data=f"ch_{ch['id']}"))
|
| 2552 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2553 |
-
rows.append([InlineKeyboardButton("➕ إضافة قناة/قنوات", callback_data="add_channel")])
|
| 2554 |
rows.append(nav_row("main_menu"))
|
| 2555 |
await message.reply(text, reply_markup=InlineKeyboardMarkup(rows))
|
| 2556 |
|
|
@@ -2667,7 +2821,7 @@ async def menu_public_sources(client, callback):
|
|
| 2667 |
paused = " ⏸️" if is_source_paused(sid) else ""
|
| 2668 |
btns.append(InlineKeyboardButton(f"⚙️ {entity_name(meta)}{paused}", callback_data=f"srcset|{sid}|menu_public_src"))
|
| 2669 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2670 |
-
rows.append([InlineKeyboardButton("➕ إضافة مصدر/مصادر", callback_data="add_public_src"), InlineKeyboardButton("🗑 حذف مصدر عام", callback_data="del_public_src")])
|
| 2671 |
rows.append(nav_row("main_menu"))
|
| 2672 |
await safe_edit(callback, text, InlineKeyboardMarkup(rows))
|
| 2673 |
|
|
@@ -3314,11 +3468,11 @@ async def bulk_paste_source_prompt(client, callback):
|
|
| 3314 |
async def system_menu(client, callback):
|
| 3315 |
"""القائمة الرئيسية لقسم النظام (خارج القنوات)."""
|
| 3316 |
buttons = [
|
| 3317 |
-
InlineKeyboardButton("🧪 الفحص الشامل", callback_data="full_check"),
|
| 3318 |
-
InlineKeyboardButton("🟢 حالة النظام", callback_data="system_status"),
|
| 3319 |
-
InlineKeyboardButton("🛠 إدارة التشغيل", callback_data="ops_menu"),
|
| 3320 |
-
InlineKeyboardButton("📝 إدارة السجل", callback_data="log_menu"),
|
| 3321 |
-
InlineKeyboardButton("🔔 التنبيهات", callback_data="notifications_menu"),
|
| 3322 |
]
|
| 3323 |
rows = grid_buttons(buttons, 2)
|
| 3324 |
rows.append(nav_row("main_menu"))
|
|
@@ -3853,6 +4007,23 @@ async def handle_text_input(client, message):
|
|
| 3853 |
await handle_blogger_text_input(client, message)
|
| 3854 |
return
|
| 3855 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3856 |
try:
|
| 3857 |
if state == "waiting_channel_id":
|
| 3858 |
results = []
|
|
@@ -5052,9 +5223,9 @@ async def middle_channel_handler(client, message):
|
|
| 5052 |
async def secrets_menu(client, callback):
|
| 5053 |
text = "🔐 **الأسرار والإعدادات**\n\n📱 الجلسات: حسابات Telegram المستخدمة للقراءة.\n🤖 بوتات النشر: البوتات التي تنشر في القنوات.\n🧠 مفاتيح AI: مزودو الذكاء الاصطناعي ومفاتيحهم.\n🌐 مواقع الويب: مصادر الجلب عبر الروابط.\n🗑 سلة المحذوفات: استعادة أو حذف العناصر نهائياً."
|
| 5054 |
buttons = [
|
| 5055 |
-
[InlineKeyboardButton("📱 الجلسات", callback_data="sessions_list"), InlineKeyboardButton("🤖 بوتات النشر", callback_data="bots_list")],
|
| 5056 |
-
[InlineKeyboardButton("🧠 مفاتيح AI", callback_data="ai_list"), InlineKeyboardButton("🌐 مواقع الويب", callback_data="web_list")],
|
| 5057 |
-
[InlineKeyboardButton("🗑 سلة المحذوفات", callback_data="trash_menu")],
|
| 5058 |
nav_row("main_menu"),
|
| 5059 |
]
|
| 5060 |
await safe_edit(callback, text, InlineKeyboardMarkup(buttons))
|
|
@@ -5792,7 +5963,7 @@ async def system_channel_menu(client, callback):
|
|
| 5792 |
await callback.answer("القناة غير موجودة.")
|
| 5793 |
return
|
| 5794 |
buttons = [
|
| 5795 |
-
InlineKeyboardButton("🧪 اختبار القناة", callback_data=f"testset_{ch_id}"),
|
| 5796 |
InlineKeyboardButton("🔍 الفحص الشامل", callback_data=f"full_check|{ch_id}"),
|
| 5797 |
InlineKeyboardButton("📊 حالة النظام", callback_data=f"system_status|{ch_id}"),
|
| 5798 |
InlineKeyboardButton("▶️ إدارة التشغيل", callback_data=f"ops_menu|{ch_id}"),
|
|
@@ -6467,8 +6638,46 @@ def register_bot_handlers(app: Client):
|
|
| 6467 |
if data.startswith(("news:", "sports:", "blogger:")):
|
| 6468 |
await section_control_callback(client, callback)
|
| 6469 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6470 |
if data == "main_menu":
|
| 6471 |
-
await safe_edit(callback, "القائمة الرئيسية:",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6472 |
elif data == "back_stack":
|
| 6473 |
previous = _back_step(callback)
|
| 6474 |
if previous is None:
|
|
@@ -6486,12 +6695,16 @@ def register_bot_handlers(app: Client):
|
|
| 6486 |
_push_back(callback)
|
| 6487 |
if data.startswith("ui_info|"):
|
| 6488 |
await ui_setting_info_menu(client, callback)
|
|
|
|
| 6489 |
elif data.startswith("ui_set|"):
|
| 6490 |
await ui_setting_set(client, callback)
|
|
|
|
| 6491 |
elif data.startswith("ui_action_exec|"):
|
| 6492 |
await action_execute_menu(client, callback)
|
|
|
|
| 6493 |
elif data.startswith("ui_action|"):
|
| 6494 |
await action_info_menu(client, callback)
|
|
|
|
| 6495 |
elif data in BLOGGER_CALLBACKS:
|
| 6496 |
await BLOGGER_CALLBACKS[data](client, callback)
|
| 6497 |
return
|
|
|
|
| 1922 |
text = f"**المصادر العامة ({len(srcs)}):**\n➕ إضافة مصدر/مصادر: يضيف قنوات عامة جديدة يراقبها البوت (رابط/يوزر/ID).\n🗑 حذف مصدر عام: يحذف مصدراً عاماً من المراقبة."
|
| 1923 |
text += "\n\n".join(entity_details_line(m, is_source=True) for m in meta_list) if srcs else "لا توجد."
|
| 1924 |
buttons = [
|
| 1925 |
+
[InlineKeyboardButton(lbl("add_public_src", "➕ إضافة مصدر/مصادر"), callback_data="add_public_src")],
|
| 1926 |
+
[InlineKeyboardButton(lbl("del_public_src", "🗑 حذف مصدر عام"), callback_data="del_public_src")],
|
| 1927 |
nav_row("main_menu"),
|
| 1928 |
]
|
| 1929 |
await message.reply(text, reply_markup=InlineKeyboardMarkup(buttons))
|
|
|
|
| 1972 |
lines.extend([f"• {raw}: {err}" for _, raw, err in failed[:20]])
|
| 1973 |
return "\n".join(lines)
|
| 1974 |
|
| 1975 |
+
|
| 1976 |
+
# ============================================================
|
| 1977 |
+
# ✏️ نظام تخصيص أسماء القوائم والأزرار (حفظ دائم في /data)
|
| 1978 |
+
# ============================================================
|
| 1979 |
+
import json as _cl_json
|
| 1980 |
+
|
| 1981 |
+
_CUSTOM_LABELS_DIR = "/data" if os.path.isdir("/data") and "SPACE_ID" in os.environ else os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
|
| 1982 |
+
_CUSTOM_LABELS_FILE = os.path.join(_CUSTOM_LABELS_DIR, "custom_labels.json")
|
| 1983 |
+
|
| 1984 |
+
MENU_LABEL_CATALOG = {
|
| 1985 |
+
"main": ("🏠 القائمة الرئيسية", {
|
| 1986 |
+
"menu_channels": "📢 إدارة قنوات النشر",
|
| 1987 |
+
"menu_public_src": "🌐 إدارة المصادر العامة",
|
| 1988 |
+
"backup_menu": "💾 الاستيراد / التصدير",
|
| 1989 |
+
"stats": "📊 الإحصائيات",
|
| 1990 |
+
"system_menu": "🖥️ النظام",
|
| 1991 |
+
"secrets_menu": "🔐 الأسرار",
|
| 1992 |
+
"section_menu|news": "📰 الأخبار",
|
| 1993 |
+
"section_menu|sports": "⚽ الرياضة",
|
| 1994 |
+
"section_menu|blogger": "🌐 Blogger Publisher",
|
| 1995 |
+
}),
|
| 1996 |
+
"channels": ("📢 قوائم القنوات والمنشورات", {
|
| 1997 |
+
"add_channel": "➕ إضافة قناة/قنوات",
|
| 1998 |
+
"postset_": "📰 إعدادات المنشورات",
|
| 1999 |
+
"srcset_": "📡 المصادر",
|
| 2000 |
+
"genset_": "⚙️ الإعدادات العامة",
|
| 2001 |
+
"tails_": "✍️ التوقيع",
|
| 2002 |
+
"quotemenu_": "💬 الاقتباس",
|
| 2003 |
+
"hashtags_": "#️⃣ الهاشتاكات",
|
| 2004 |
+
"speedmenu_": "⏱ سرعة النشر",
|
| 2005 |
+
"purgepage_": "🗑 حذف المنشورات",
|
| 2006 |
+
"chwords|": "🚫 الكلمات المحظورة",
|
| 2007 |
+
"chdelterms|": "✂️ الكلمات المحذوفة",
|
| 2008 |
+
"chlinks|": "🔗 إدارة الروابط",
|
| 2009 |
+
"testset_": "🧪 اختبار القناة",
|
| 2010 |
+
}),
|
| 2011 |
+
"sources": ("🌐 قوائم المصادر والحماية", {
|
| 2012 |
+
"add_public_src": "➕ إضافة مصدر/مصادر",
|
| 2013 |
+
"del_public_src": "🗑 حذف مصدر عام",
|
| 2014 |
+
"menu_blocked": "🚫 الكلمات المحظورة",
|
| 2015 |
+
"global_clean": "🧹 قائمة الحذف العامة",
|
| 2016 |
+
}),
|
| 2017 |
+
"system": ("🖥️ النظام والأسرار", {
|
| 2018 |
+
"full_check": "🧪 الفحص الشامل",
|
| 2019 |
+
"system_status": "🟢 حالة النظام",
|
| 2020 |
+
"ops_menu": "🛠 إدارة التشغيل",
|
| 2021 |
+
"log_menu": "📝 إدارة السجل",
|
| 2022 |
+
"notifications_menu": "🔔 التنبيهات",
|
| 2023 |
+
"sessions_list": "📱 الجلسات",
|
| 2024 |
+
"bots_list": "🤖 بوتات النشر",
|
| 2025 |
+
"ai_list": "🧠 مفاتيح AI",
|
| 2026 |
+
"web_list": "🌐 مواقع الويب",
|
| 2027 |
+
"trash_menu": "🗑 سلة المحذوفات",
|
| 2028 |
+
}),
|
| 2029 |
+
"blogger": ("🌐 قوائم Blogger Publisher", {
|
| 2030 |
+
"blogger_articles": "📚 المقالات",
|
| 2031 |
+
"blogger_settings": "📝 إعدادات النشر",
|
| 2032 |
+
"blogger_sections_main": "📂 إدارة الأقسام",
|
| 2033 |
+
"blogger_channels": "📺 إدارة القنوات",
|
| 2034 |
+
"blogger_schedule_info": "🕒 جدولة النشر",
|
| 2035 |
+
"blogger_preview_last": "👁 معاينة آخر مقال",
|
| 2036 |
+
"blogger_set_default_image": "🖼 إعدادات الصورة",
|
| 2037 |
+
"blogger_stats": "📊 الإحصائيات",
|
| 2038 |
+
"blogger_advanced": "⚙️ الإعدادات المتقدمة",
|
| 2039 |
+
"blogger_run_cycle_now": "🔄 سحب ومعالجة الآن",
|
| 2040 |
+
}),
|
| 2041 |
+
}
|
| 2042 |
+
|
| 2043 |
+
|
| 2044 |
+
def get_all_custom_labels() -> dict:
|
| 2045 |
+
try:
|
| 2046 |
+
if os.path.isfile(_CUSTOM_LABELS_FILE):
|
| 2047 |
+
with open(_CUSTOM_LABELS_FILE, "r", encoding="utf-8") as f:
|
| 2048 |
+
data = _cl_json.load(f)
|
| 2049 |
+
if isinstance(data, dict):
|
| 2050 |
+
return {str(k): str(v) for k, v in data.items() if v}
|
| 2051 |
+
except Exception as e:
|
| 2052 |
+
logger.warning(f"Failed to read custom labels: {e}")
|
| 2053 |
+
return {}
|
| 2054 |
+
|
| 2055 |
+
|
| 2056 |
+
def set_custom_label(key: str, label: str):
|
| 2057 |
+
os.makedirs(os.path.dirname(_CUSTOM_LABELS_FILE), exist_ok=True)
|
| 2058 |
+
data = get_all_custom_labels()
|
| 2059 |
+
data[str(key)] = str(label).strip()
|
| 2060 |
+
tmp = _CUSTOM_LABELS_FILE + ".tmp"
|
| 2061 |
+
with open(tmp, "w", encoding="utf-8") as f:
|
| 2062 |
+
_cl_json.dump(data, f, ensure_ascii=False, indent=2)
|
| 2063 |
+
os.replace(tmp, _CUSTOM_LABELS_FILE)
|
| 2064 |
+
|
| 2065 |
+
|
| 2066 |
+
def reset_custom_label(key: str = None):
|
| 2067 |
+
if key is None:
|
| 2068 |
+
try:
|
| 2069 |
+
if os.path.isfile(_CUSTOM_LABELS_FILE):
|
| 2070 |
+
os.remove(_CUSTOM_LABELS_FILE)
|
| 2071 |
+
except Exception:
|
| 2072 |
+
pass
|
| 2073 |
+
return
|
| 2074 |
+
data = get_all_custom_labels()
|
| 2075 |
+
if str(key) in data:
|
| 2076 |
+
data.pop(str(key), None)
|
| 2077 |
+
os.makedirs(os.path.dirname(_CUSTOM_LABELS_FILE), exist_ok=True)
|
| 2078 |
+
tmp = _CUSTOM_LABELS_FILE + ".tmp"
|
| 2079 |
+
with open(tmp, "w", encoding="utf-8") as f:
|
| 2080 |
+
_cl_json.dump(data, f, ensure_ascii=False, indent=2)
|
| 2081 |
+
os.replace(tmp, _CUSTOM_LABELS_FILE)
|
| 2082 |
+
|
| 2083 |
+
|
| 2084 |
+
def lbl(key: str, default_text: str) -> str:
|
| 2085 |
+
custom = get_all_custom_labels()
|
| 2086 |
+
if key in custom:
|
| 2087 |
+
return custom[key]
|
| 2088 |
+
for k, v in custom.items():
|
| 2089 |
+
if k.endswith(("_", "|")) and str(key).startswith(k):
|
| 2090 |
+
return v
|
| 2091 |
+
return default_text
|
| 2092 |
+
|
| 2093 |
+
|
| 2094 |
+
def build_main_keyboard():
|
| 2095 |
+
return InlineKeyboardMarkup([
|
| 2096 |
+
[
|
| 2097 |
+
InlineKeyboardButton(lbl("menu_channels", "📢 إدارة قنوات النشر"), callback_data="menu_channels"),
|
| 2098 |
+
InlineKeyboardButton(lbl("menu_public_src", "🌐 إدارة المصادر العامة"), callback_data="menu_public_src")
|
| 2099 |
+
],
|
| 2100 |
+
[
|
| 2101 |
+
InlineKeyboardButton(lbl("backup_menu", "💾 الاستيراد / التصدير"), callback_data="backup_menu"),
|
| 2102 |
+
InlineKeyboardButton(lbl("stats", "📊 الإحصائيات"), callback_data="stats")
|
| 2103 |
+
],
|
| 2104 |
+
[
|
| 2105 |
+
InlineKeyboardButton(lbl("system_menu", "🖥️ النظام"), callback_data="system_menu"),
|
| 2106 |
+
InlineKeyboardButton(lbl("secrets_menu", "🔐 الأسرار"), callback_data="secrets_menu")
|
| 2107 |
+
],
|
| 2108 |
+
[
|
| 2109 |
+
InlineKeyboardButton(lbl("section_menu|news", "📰 الأخبار"), callback_data="section_menu|news"),
|
| 2110 |
+
InlineKeyboardButton(lbl("section_menu|sports", "⚽ الرياضة"), callback_data="section_menu|sports"),
|
| 2111 |
+
],
|
| 2112 |
+
[
|
| 2113 |
+
InlineKeyboardButton(lbl("section_menu|blogger", "🌐 Blogger Publisher"), callback_data="section_menu|blogger")
|
| 2114 |
+
],
|
| 2115 |
+
[
|
| 2116 |
+
InlineKeyboardButton("✏️ تعديل أسماء القوائم", callback_data="cl_categories")
|
| 2117 |
+
]
|
| 2118 |
+
])
|
| 2119 |
+
|
| 2120 |
+
|
| 2121 |
+
async def custom_labels_categories_menu(client, callback):
|
| 2122 |
+
rows = []
|
| 2123 |
+
for cat_key, (cat_title, _) in MENU_LABEL_CATALOG.items():
|
| 2124 |
+
rows.append([InlineKeyboardButton(cat_title, callback_data=f"cl_cat|{cat_key}")])
|
| 2125 |
+
rows.append([InlineKeyboardButton("🔄 استعادة كل الأسماء الافتراضية", callback_data="cl_reset_all")])
|
| 2126 |
+
rows.append([InlineKeyboardButton("🏠 القائمة الرئيسية", callback_data="main_menu")])
|
| 2127 |
+
await safe_edit(callback, "✏️ **تعديل أسماء القوائم والأزرار**\n\nاختر القسم الذي تريد تعديل أسماء أزراره:", InlineKeyboardMarkup(rows))
|
| 2128 |
+
|
| 2129 |
+
|
| 2130 |
+
async def custom_labels_items_menu(client, callback):
|
| 2131 |
+
cat_key = callback.data.split("|", 1)[1]
|
| 2132 |
+
cat = MENU_LABEL_CATALOG.get(cat_key)
|
| 2133 |
+
if not cat:
|
| 2134 |
+
await callback.answer("القسم غير موجود.")
|
| 2135 |
+
return
|
| 2136 |
+
cat_title, items = cat
|
| 2137 |
+
custom = get_all_custom_labels()
|
| 2138 |
+
rows = []
|
| 2139 |
+
for item_key, default_txt in items.items():
|
| 2140 |
+
cur = custom.get(item_key, default_txt)
|
| 2141 |
+
mark = "✏️" if item_key in custom else "▫️"
|
| 2142 |
+
rows.append([InlineKeyboardButton(f"{mark} {cur}", callback_data=f"cl_edit|{cat_key}|{item_key}")])
|
| 2143 |
+
rows.append([
|
| 2144 |
+
InlineKeyboardButton("🔙 رجوع", callback_data="cl_categories"),
|
| 2145 |
+
InlineKeyboardButton("🏠 القائمة الرئيسية", callback_data="main_menu"),
|
| 2146 |
+
])
|
| 2147 |
+
await safe_edit(callback, f"{cat_title}\n\nاختر الزر الذي تريد تغيير اسمه:", InlineKeyboardMarkup(rows))
|
| 2148 |
+
|
| 2149 |
+
main_keyboard = build_main_keyboard()
|
| 2150 |
|
| 2151 |
|
| 2152 |
async def section_menu(client, callback):
|
|
|
|
| 2227 |
await message.reply(f"❌ غير مصرح. معرفك: `{user_id}`")
|
| 2228 |
return
|
| 2229 |
|
| 2230 |
+
await message.reply("أهلاً بك في لوحة تحكم البوت:", reply_markup=build_main_keyboard())
|
| 2231 |
|
| 2232 |
async def export_callback(client, callback):
|
| 2233 |
try:
|
|
|
|
| 2405 |
|
| 2406 |
def channel_buttons(ch_id):
|
| 2407 |
buttons = [
|
| 2408 |
+
InlineKeyboardButton(lbl("postset_", "📰 إعدادات المنشورات"), callback_data=f"postset_{ch_id}"),
|
| 2409 |
+
InlineKeyboardButton(lbl("srcset_", "📡 المصادر"), callback_data=f"srcset_{ch_id}"),
|
| 2410 |
+
InlineKeyboardButton(lbl("genset_", "⚙️ الإعدادات العامة"), callback_data=f"genset_{ch_id}"),
|
| 2411 |
]
|
| 2412 |
rows = grid_buttons(buttons, 2)
|
| 2413 |
rows.append([InlineKeyboardButton("🔙 رجوع", callback_data="menu_channels"), InlineKeyboardButton("🏠 القائمة الرئيسية", callback_data="main_menu")])
|
|
|
|
| 2436 |
f"📝 النصوص القصيرة: {'✅ تشغيل' if ignore_short else '❌ إيقاف'}",
|
| 2437 |
callback_data=f"toggle_short_posts|{ch_id}",
|
| 2438 |
),
|
| 2439 |
+
InlineKeyboardButton(lbl("tails_", "✍️ التوقيع"), callback_data=f"tails_{ch_id}"),
|
| 2440 |
InlineKeyboardButton(f"💬 الاقتباس ({quote_count}/6)", callback_data=f"quotemenu_{ch_id}"),
|
| 2441 |
+
InlineKeyboardButton(lbl("hashtags_", "#️⃣ الهاشتاكات"), callback_data=f"hashtags_{ch_id}"),
|
| 2442 |
+
InlineKeyboardButton(lbl("speedmenu_", "⏱ سرعة النشر"), callback_data=f"speedmenu_{ch_id}"),
|
| 2443 |
+
InlineKeyboardButton(lbl("purgepage_", "🗑 حذف المنشورات"), callback_data=f"purgepage_{ch_id}"),
|
| 2444 |
+
InlineKeyboardButton(lbl("chwords|", "🚫 الكلمات المحظورة"), callback_data=f"chwords|{ch_id}"),
|
| 2445 |
+
InlineKeyboardButton(lbl("chdelterms|", "✂️ الكلمات المحذوفة"), callback_data=f"chdelterms|{ch_id}"),
|
| 2446 |
+
InlineKeyboardButton(lbl("chlinks|", "🔗 إدارة الروابط"), callback_data=f"chlinks|{ch_id}"),
|
| 2447 |
InlineKeyboardButton(f"{'✅' if not disable_preview else '❌'} معاينة الروابط", callback_data=f"ch_preview_{ch_id}"),
|
| 2448 |
+
InlineKeyboardButton(lbl("testset_", "🧪 اختبار القناة"), callback_data=f"testset_{ch_id}"),
|
| 2449 |
]
|
| 2450 |
rows = grid_buttons(buttons, 2)
|
| 2451 |
rows.append(nav_row(f"ch_{ch_id}"))
|
|
|
|
| 2667 |
if not channels:
|
| 2668 |
text = "لا توجد قنوات منشورة بعد. اضغط ➕ لإضافتها."
|
| 2669 |
rows = [
|
| 2670 |
+
[InlineKeyboardButton(lbl("add_channel", "➕ إضافة قناة/قنوات"), callback_data="add_channel")],
|
| 2671 |
nav_row("main_menu")
|
| 2672 |
]
|
| 2673 |
else:
|
|
|
|
| 2681 |
text += f"\n✅ {name}{paused}\n {username_txt}\n ID: `{ch['id']}`\n"
|
| 2682 |
btns.append(InlineKeyboardButton(f"⚙️ {name}", callback_data=f"ch_{ch['id']}"))
|
| 2683 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2684 |
+
rows.append([InlineKeyboardButton(lbl("add_channel", "➕ إضافة قناة/قنوات"), callback_data="add_channel")])
|
| 2685 |
rows.append(nav_row("main_menu"))
|
| 2686 |
await safe_edit(callback, text, InlineKeyboardMarkup(rows))
|
| 2687 |
|
|
|
|
| 2690 |
if not channels:
|
| 2691 |
text = "لا توجد قنوات منشورة بعد. اضغط ➕ لإضافتها."
|
| 2692 |
rows = [
|
| 2693 |
+
[InlineKeyboardButton(lbl("add_channel", "➕ إضافة قناة/قنوات"), callback_data="add_channel")],
|
| 2694 |
nav_row("main_menu")
|
| 2695 |
]
|
| 2696 |
else:
|
|
|
|
| 2704 |
text += f"\n✅ {name}{paused}\n {username_txt}\n ID: `{ch['id']}`\n"
|
| 2705 |
btns.append(InlineKeyboardButton(f"⚙️ {name}", callback_data=f"ch_{ch['id']}"))
|
| 2706 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2707 |
+
rows.append([InlineKeyboardButton(lbl("add_channel", "➕ إضافة قناة/قنوات"), callback_data="add_channel")])
|
| 2708 |
rows.append(nav_row("main_menu"))
|
| 2709 |
await message.reply(text, reply_markup=InlineKeyboardMarkup(rows))
|
| 2710 |
|
|
|
|
| 2821 |
paused = " ⏸️" if is_source_paused(sid) else ""
|
| 2822 |
btns.append(InlineKeyboardButton(f"⚙️ {entity_name(meta)}{paused}", callback_data=f"srcset|{sid}|menu_public_src"))
|
| 2823 |
rows = grid_buttons(btns, 2 if len(btns) <= 8 else 3)
|
| 2824 |
+
rows.append([InlineKeyboardButton(lbl("add_public_src", "➕ إضافة مصدر/مصادر"), callback_data="add_public_src"), InlineKeyboardButton(lbl("del_public_src", "🗑 حذف مصدر عام"), callback_data="del_public_src")])
|
| 2825 |
rows.append(nav_row("main_menu"))
|
| 2826 |
await safe_edit(callback, text, InlineKeyboardMarkup(rows))
|
| 2827 |
|
|
|
|
| 3468 |
async def system_menu(client, callback):
|
| 3469 |
"""القائمة الرئيسية لقسم النظام (خارج القنوات)."""
|
| 3470 |
buttons = [
|
| 3471 |
+
InlineKeyboardButton(lbl("full_check", "🧪 الفحص الشامل"), callback_data="full_check"),
|
| 3472 |
+
InlineKeyboardButton(lbl("system_status", "🟢 حالة النظام"), callback_data="system_status"),
|
| 3473 |
+
InlineKeyboardButton(lbl("ops_menu", "🛠 إدارة التشغيل"), callback_data="ops_menu"),
|
| 3474 |
+
InlineKeyboardButton(lbl("log_menu", "📝 إدارة السجل"), callback_data="log_menu"),
|
| 3475 |
+
InlineKeyboardButton(lbl("notifications_menu", "🔔 التنبيهات"), callback_data="notifications_menu"),
|
| 3476 |
]
|
| 3477 |
rows = grid_buttons(buttons, 2)
|
| 3478 |
rows.append(nav_row("main_menu"))
|
|
|
|
| 4007 |
await handle_blogger_text_input(client, message)
|
| 4008 |
return
|
| 4009 |
|
| 4010 |
+
if state == "waiting_custom_label_input":
|
| 4011 |
+
item_key = user_states[uid].get("item_key", "")
|
| 4012 |
+
cat_key = user_states[uid].get("cat_key", "main")
|
| 4013 |
+
if item_key and text:
|
| 4014 |
+
set_custom_label(item_key, text)
|
| 4015 |
+
user_states.pop(uid, None)
|
| 4016 |
+
await message.reply(
|
| 4017 |
+
f"✅ تم تغيير الاسم بنجاح إلى: **{text}**",
|
| 4018 |
+
reply_markup=InlineKeyboardMarkup([
|
| 4019 |
+
[InlineKeyboardButton("🔙 رجوع للقائمة", callback_data=f"cl_cat|{cat_key}")],
|
| 4020 |
+
[InlineKeyboardButton("🏠 القائمة الرئيسية", callback_data="main_menu")],
|
| 4021 |
+
])
|
| 4022 |
+
)
|
| 4023 |
+
else:
|
| 4024 |
+
await message.reply("❌ الاسم لا يمكن أن يكون فارغاً.")
|
| 4025 |
+
return
|
| 4026 |
+
|
| 4027 |
try:
|
| 4028 |
if state == "waiting_channel_id":
|
| 4029 |
results = []
|
|
|
|
| 5223 |
async def secrets_menu(client, callback):
|
| 5224 |
text = "🔐 **الأسرار والإعدادات**\n\n📱 الجلسات: حسابات Telegram المستخدمة للقراءة.\n🤖 بوتات النشر: البوتات التي تنشر في القنوات.\n🧠 مفاتيح AI: مزودو الذكاء الاصطناعي ومفاتيحهم.\n🌐 مواقع الويب: مصادر الجلب عبر الروابط.\n🗑 سلة المحذوفات: استعادة أو حذف العناصر نهائياً."
|
| 5225 |
buttons = [
|
| 5226 |
+
[InlineKeyboardButton(lbl("sessions_list", "📱 الجلسات"), callback_data="sessions_list"), InlineKeyboardButton(lbl("bots_list", "🤖 بوتات النشر"), callback_data="bots_list")],
|
| 5227 |
+
[InlineKeyboardButton(lbl("ai_list", "🧠 مفاتيح AI"), callback_data="ai_list"), InlineKeyboardButton(lbl("web_list", "🌐 مواقع الويب"), callback_data="web_list")],
|
| 5228 |
+
[InlineKeyboardButton(lbl("trash_menu", "🗑 سلة المحذوفات"), callback_data="trash_menu")],
|
| 5229 |
nav_row("main_menu"),
|
| 5230 |
]
|
| 5231 |
await safe_edit(callback, text, InlineKeyboardMarkup(buttons))
|
|
|
|
| 5963 |
await callback.answer("القناة غير موجودة.")
|
| 5964 |
return
|
| 5965 |
buttons = [
|
| 5966 |
+
InlineKeyboardButton(lbl("testset_", "🧪 اختبار القناة"), callback_data=f"testset_{ch_id}"),
|
| 5967 |
InlineKeyboardButton("🔍 الفحص الشامل", callback_data=f"full_check|{ch_id}"),
|
| 5968 |
InlineKeyboardButton("📊 حالة النظام", callback_data=f"system_status|{ch_id}"),
|
| 5969 |
InlineKeyboardButton("▶️ إدارة التشغيل", callback_data=f"ops_menu|{ch_id}"),
|
|
|
|
| 6638 |
if data.startswith(("news:", "sports:", "blogger:")):
|
| 6639 |
await section_control_callback(client, callback)
|
| 6640 |
return
|
| 6641 |
+
if "~" in str(data) and not str(data).startswith(("ui_info|", "ui_set|", "ui_action|", "ui_action_exec|")):
|
| 6642 |
+
data = str(data).replace("~", "|")
|
| 6643 |
+
callback.data = data
|
| 6644 |
+
|
| 6645 |
if data == "main_menu":
|
| 6646 |
+
await safe_edit(callback, "القائمة الرئيسية:", build_main_keyboard())
|
| 6647 |
+
return
|
| 6648 |
+
if data == "cl_categories":
|
| 6649 |
+
await custom_labels_categories_menu(client, callback)
|
| 6650 |
+
return
|
| 6651 |
+
if data.startswith("cl_cat|"):
|
| 6652 |
+
await custom_labels_items_menu(client, callback)
|
| 6653 |
+
return
|
| 6654 |
+
if data.startswith("cl_edit|"):
|
| 6655 |
+
_, cat_key, item_key = data.split("|", 2)
|
| 6656 |
+
uid = callback.from_user.id
|
| 6657 |
+
user_states[uid] = {"state": "waiting_custom_label_input", "cat_key": cat_key, "item_key": item_key}
|
| 6658 |
+
default_txt = MENU_LABEL_CATALOG.get(cat_key, ("", {}))[1].get(item_key, item_key)
|
| 6659 |
+
cur_txt = get_all_custom_labels().get(item_key, default_txt)
|
| 6660 |
+
await safe_edit(
|
| 6661 |
+
callback,
|
| 6662 |
+
f"✏️ **تعديل اسم الزر**\n\nالاسم الحالي: **{cur_txt}**\nالاسم الافتراضي: `{default_txt}`\n\nأرسل الاسم الجديد الآن (مع الإيموجي إذا رغبت):",
|
| 6663 |
+
InlineKeyboardMarkup([
|
| 6664 |
+
[InlineKeyboardButton("🔄 استعادة الافتراضي لهذا الزر", callback_data=f"cl_reset_one|{cat_key}|{item_key}")],
|
| 6665 |
+
[InlineKeyboardButton("🔙 رجوع", callback_data=f"cl_cat|{cat_key}")],
|
| 6666 |
+
])
|
| 6667 |
+
)
|
| 6668 |
+
return
|
| 6669 |
+
if data.startswith("cl_reset_one|"):
|
| 6670 |
+
_, cat_key, item_key = data.split("|", 2)
|
| 6671 |
+
reset_custom_label(item_key)
|
| 6672 |
+
await callback.answer("✅ تمت استعادة الاسم الافتراضي.")
|
| 6673 |
+
callback.data = f"cl_cat|{cat_key}"
|
| 6674 |
+
await custom_labels_items_menu(client, callback)
|
| 6675 |
+
return
|
| 6676 |
+
if data == "cl_reset_all":
|
| 6677 |
+
reset_custom_label(None)
|
| 6678 |
+
await callback.answer("✅ تمت استعادة جميع الأسماء الافتراضية.")
|
| 6679 |
+
await safe_edit(callback, "القائمة الرئيسية:", build_main_keyboard())
|
| 6680 |
+
return
|
| 6681 |
elif data == "back_stack":
|
| 6682 |
previous = _back_step(callback)
|
| 6683 |
if previous is None:
|
|
|
|
| 6695 |
_push_back(callback)
|
| 6696 |
if data.startswith("ui_info|"):
|
| 6697 |
await ui_setting_info_menu(client, callback)
|
| 6698 |
+
return
|
| 6699 |
elif data.startswith("ui_set|"):
|
| 6700 |
await ui_setting_set(client, callback)
|
| 6701 |
+
return
|
| 6702 |
elif data.startswith("ui_action_exec|"):
|
| 6703 |
await action_execute_menu(client, callback)
|
| 6704 |
+
return
|
| 6705 |
elif data.startswith("ui_action|"):
|
| 6706 |
await action_info_menu(client, callback)
|
| 6707 |
+
return
|
| 6708 |
elif data in BLOGGER_CALLBACKS:
|
| 6709 |
await BLOGGER_CALLBACKS[data](client, callback)
|
| 6710 |
return
|