Update bot.py
Browse files
bot.py
CHANGED
|
@@ -3,13 +3,12 @@ import os
|
|
| 3 |
import logging
|
| 4 |
import random
|
| 5 |
import sys
|
| 6 |
-
from telethon import TelegramClient
|
| 7 |
from telethon.sessions import StringSession
|
| 8 |
from telethon.tl.functions.channels import InviteToChannelRequest
|
| 9 |
-
from telethon.tl.types import InputPeerUser
|
| 10 |
from telethon.errors import (
|
| 11 |
-
FloodWaitError, UserPrivacyRestrictedError, PeerFloodError,
|
| 12 |
-
UserChannelsTooMuchError, UserAlreadyParticipantError
|
| 13 |
)
|
| 14 |
|
| 15 |
# إعداد اللوق
|
|
@@ -22,77 +21,66 @@ API_HASH = os.getenv("API_HASH", "")
|
|
| 22 |
SESSION_STRING = os.getenv("SESSION_STRING") or os.getenv("STRING_SESSION") or ""
|
| 23 |
SOURCE_CHANNEL = os.getenv("SOURCE_CHANNEL", "")
|
| 24 |
TARGET_CHANNEL = os.getenv("TARGET_CHANNEL", "")
|
| 25 |
-
|
| 26 |
-
BASE_DELAY = int(os.getenv("DELAY_SECONDS", "300"))
|
| 27 |
|
| 28 |
async def start_transfer():
|
| 29 |
-
logger.info("🚀 بدأت المحاولة باستخدام الكود المحدث (تخطي الحظر والانتظار الطويل)...")
|
| 30 |
-
|
| 31 |
client = TelegramClient(StringSession(SESSION_STRING.strip()), API_ID, API_HASH)
|
| 32 |
-
|
| 33 |
try:
|
| 34 |
await client.connect()
|
| 35 |
if not await client.is_user_authorized():
|
| 36 |
logger.error("❌ الجلسة غير صالحة!")
|
| 37 |
return
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
source = await client.get_entity(SOURCE_CHANNEL)
|
| 40 |
target = await client.get_entity(TARGET_CHANNEL)
|
| 41 |
|
| 42 |
-
# جلب الأعضاء
|
| 43 |
participants = await client.get_participants(source, limit=500)
|
| 44 |
random.shuffle(participants)
|
| 45 |
|
| 46 |
-
success
|
| 47 |
-
|
| 48 |
for member in participants:
|
| 49 |
-
if
|
| 50 |
if member.bot or member.deleted: continue
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
try:
|
| 57 |
# محاولة الإضافة
|
| 58 |
await client(InviteToChannelRequest(target, [InputPeerUser(member.id, member.access_hash or 0)]))
|
| 59 |
success += 1
|
| 60 |
-
logger.info(f"✅
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
except PeerFloodError:
|
| 64 |
-
logger.warning(f"🚨 تيليجرام رفض إضافة {name} (Flood). سأتخطاه وأجرب العضو التالي بعد 30 ثانية...")
|
| 65 |
-
await asyncio.sleep(30)
|
| 66 |
-
continue
|
| 67 |
|
| 68 |
except UserAlreadyParticipantError:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
logger.warning(f"⏳ تيليجرام طلب انتظار {e.seconds} ثانية!")
|
| 74 |
-
if e.seconds > 120:
|
| 75 |
-
logger.warning("⚠️ هذا وقت طويل جداً! سأتخطى هذا العضو وأنتظر 2 دقائق فقط (120 ثانية) وأكمل...")
|
| 76 |
-
await asyncio.sleep(120)
|
| 77 |
-
else:
|
| 78 |
-
await asyncio.sleep(e.seconds + 2)
|
| 79 |
-
|
| 80 |
-
except UserPrivacyRestrictedError:
|
| 81 |
-
logger.info(f"🔒 خصوصية {name} تمنع الإضافة.")
|
| 82 |
except Exception as e:
|
| 83 |
-
logger.info(f"❌ فشل مع {
|
|
|
|
| 84 |
|
| 85 |
-
logger.info(f"🏁 انتهت الدورة. تم إضافة {success}
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
logger.error(f"❌ خطأ نظام: {e}")
|
| 89 |
finally:
|
|
|
|
| 90 |
await client.disconnect()
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
-
# تشغيل مستمر
|
| 94 |
while True:
|
| 95 |
asyncio.run(start_transfer())
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
import time
|
| 98 |
-
time.sleep(
|
|
|
|
| 3 |
import logging
|
| 4 |
import random
|
| 5 |
import sys
|
| 6 |
+
from telethon import TelegramClient, functions
|
| 7 |
from telethon.sessions import StringSession
|
| 8 |
from telethon.tl.functions.channels import InviteToChannelRequest
|
| 9 |
+
from telethon.tl.types import InputPeerUser, UserStatusRecently, UserStatusOnline
|
| 10 |
from telethon.errors import (
|
| 11 |
+
FloodWaitError, UserPrivacyRestrictedError, PeerFloodError, UserAlreadyParticipantError
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
# إعداد اللوق
|
|
|
|
| 21 |
SESSION_STRING = os.getenv("SESSION_STRING") or os.getenv("STRING_SESSION") or ""
|
| 22 |
SOURCE_CHANNEL = os.getenv("SOURCE_CHANNEL", "")
|
| 23 |
TARGET_CHANNEL = os.getenv("TARGET_CHANNEL", "")
|
| 24 |
+
LIMIT_PER_CYCLE = 2 # إضافة عضوين في كل دورة
|
|
|
|
| 25 |
|
| 26 |
async def start_transfer():
|
|
|
|
|
|
|
| 27 |
client = TelegramClient(StringSession(SESSION_STRING.strip()), API_ID, API_HASH)
|
|
|
|
| 28 |
try:
|
| 29 |
await client.connect()
|
| 30 |
if not await client.is_user_authorized():
|
| 31 |
logger.error("❌ الجلسة غير صالحة!")
|
| 32 |
return
|
| 33 |
|
| 34 |
+
# ✅ إظهار الحساب "متصل الآن"
|
| 35 |
+
await client(functions.account.UpdateStatusRequest(offline=False))
|
| 36 |
+
logger.info("🟢 متصل الآن (Online)")
|
| 37 |
+
|
| 38 |
source = await client.get_entity(SOURCE_CHANNEL)
|
| 39 |
target = await client.get_entity(TARGET_CHANNEL)
|
| 40 |
|
| 41 |
+
# جلب الأعضاء النشطين فقط لضمان جودة النقل
|
| 42 |
participants = await client.get_participants(source, limit=500)
|
| 43 |
random.shuffle(participants)
|
| 44 |
|
| 45 |
+
success = 0
|
|
|
|
| 46 |
for member in participants:
|
| 47 |
+
if success >= LIMIT_PER_CYCLE: break
|
| 48 |
if member.bot or member.deleted: continue
|
| 49 |
+
|
| 50 |
+
# تخطي غير النشطين لتقليل فرص الحظر
|
| 51 |
+
if not isinstance(member.status, (UserStatusOnline, UserStatusRecently)):
|
| 52 |
+
continue
|
| 53 |
|
| 54 |
try:
|
| 55 |
# محاولة الإضافة
|
| 56 |
await client(InviteToChannelRequest(target, [InputPeerUser(member.id, member.access_hash or 0)]))
|
| 57 |
success += 1
|
| 58 |
+
logger.info(f"✅ تمت إضافة {member.first_name}")
|
| 59 |
+
# انتظار قصير جداً بين العضوين داخل الدورة
|
| 60 |
+
await asyncio.sleep(random.randint(5, 10))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
except UserAlreadyParticipantError:
|
| 63 |
+
continue
|
| 64 |
+
except PeerFloodError:
|
| 65 |
+
logger.warning("🚨 تقييد PeerFlood! سنرتاح في الدورة القادمة.")
|
| 66 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
+
logger.info(f"❌ فشل مع {member.first_name}: {type(e).__name__}")
|
| 69 |
+
continue
|
| 70 |
|
| 71 |
+
logger.info(f"🏁 انتهت الدورة. تم إضافة {success} عضو.")
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
logger.error(f"❌ خطأ نظام: {e}")
|
| 75 |
finally:
|
| 76 |
+
# ✅ الخروج لكي يظهر الح��اب أوف لاين أثناء فترة الراحة
|
| 77 |
await client.disconnect()
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
|
|
|
| 80 |
while True:
|
| 81 |
asyncio.run(start_transfer())
|
| 82 |
+
# ✅ الانتظار لمدة 5 دقائق (300 ثانية) كما طلبت
|
| 83 |
+
wait_time = 300
|
| 84 |
+
logger.info(f"💤 تسجيل خروج والراحة لمدة {wait_time//60} دقائق...")
|
| 85 |
import time
|
| 86 |
+
time.sleep(wait_time)
|