magic-system-bot / main.py
omarantermohammed's picture
Update main.py
08b0f04 verified
Raw History Blame
11.7 kB
# ============================================================
# تثبيت المتطلبات لو مش موجودة
# ============================================================
import sys, os, subprocess
try:
import discord
except ImportError:
print("[*] جاري تثبيت المتطلبات...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-U",
"discord.py-self==2.1.0",
"aiohttp>=3.9.0",
"colorama>=0.4.6",
"audioop-lts"])
import discord
import asyncio# ============================================================
# تثبيت المتطلبات لو مش موجودة
# ============================================================
import sys, os, subprocess
try:
import discord
except ImportError:
print("[*] جاري تثبيت المتطلبات...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-U",
"discord.py-self==2.1.0",
"aiohttp>=3.9.0",
"colorama>=0.4.6",
"audioop-lts"])
import discord
import asyncio
import re
import traceback
import time
# ============================================================
# حط التوكين هنا فقط
# ============================================================
TOKEN = "MTQxODM2MTIwNTE1NTY5MjY2Nw.GDbNu4.zmdHwdbkD0M85uk-YDDwOCuZcrr4pkg7fOMVMU"
GUILD_ID = 1439271484127318221 # ID السيرفر
CHANNEL_ID = 1527544123890864319 # الروم الصوتي الهدف
# ============================================================
# تعديل bug مكتبة discord.py-self
# ============================================================
try:
state_path = os.path.join(os.path.dirname(discord.__file__), "state.py")
if os.path.exists(state_path):
with open(state_path, "r", encoding="utf-8") as f:
content = f.read()
content = re.sub(
r"for p in data\.get\('pending_payments',\s*\[\]\)",
"for p in (data.get('pending_payments') or [])",
content
)
with open(state_path, "w", encoding="utf-8") as f:
f.write(content)
print("[✓] تم تعديل bug discord.py-self")
except Exception as e:
print(f"[!] تعديل الـ bug: {e}")
def global_excepthook(exc_type, exc_value, exc_tb):
print("!!! خطأ غير متوقع:")
traceback.print_exception(exc_type, exc_value, exc_tb)
sys.excepthook = global_excepthook
print("=" * 40)
print(" 🎯 VC — يدخل الفويس بس لو مش موجود")
print("=" * 40)
client = discord.Client(max_messages=None)
# عداد الطرد المتكرر + آخر مرة دخلنا
kick_count = 0
last_join_time = 0
async def is_in_any_voice(guild):
"""يرجع True لو الأكاونت موجود في أي فويس جوه السيرفر"""
try:
member = guild.get_member(client.user.id)
if member is None:
member = await guild.fetch_member(client.user.id)
return member is not None and member.voice is not None
except Exception as e:
print(f"[✗] فحص الفويس فشل: {e}")
return False
async def enter_target_voice():
"""يدخل الروم المحدد فقط لو مش موجود في فويس"""
global kick_count, last_join_time
try:
guild = client.get_guild(GUILD_ID)
if guild is None:
print("[!] السيرفر مش محمّل")
return
if await is_in_any_voice(guild):
print("[*] موجود في فويس بالفعل — مش هيتحرك")
return
channel = client.get_channel(CHANNEL_ID)
if channel is None:
print("[!] الروم مش محمّل")
return
await guild.change_voice_state(channel=channel, self_mute=False, self_deaf=False)
last_join_time = time.time()
kick_count = 0 # نجحنا ندخل → نصفر العداد
print("[✓] دخلت الروم المحدد")
except Exception as e:
print(f"[✗] خطأ في الدخول: {e}")
@client.event
async def on_ready():
try:
print(f"[+] {client.user.name} متصل ✅")
await enter_target_voice()
except Exception as e:
print(f"[✗] on_ready error: {e}")
@client.event
async def on_voice_state_update(member, before, after):
global kick_count
try:
if member.id != client.user.id:
return
# خرج من فويس خالص
if before.channel is not None and after.channel is None:
# نتحقق إنه فعلًا مش في فويس (ممكن يكون اتنقل مش خرج)
await asyncio.sleep(2)
guild = client.get_guild(GUILD_ID)
if guild and await is_in_any_voice(guild):
print("[*] اتضح إنه لسه في فويس — تجاهل")
return
kick_count += 1
if kick_count >= 3:
wait = 300 # اتطرد 3 مرات ورا بعض → استنى 5 دقايق
print(f"[!] اتطردت {kick_count} مرات ورا بعض — هرجع بعد {wait//60} دقايق")
await asyncio.sleep(wait)
kick_count = 0
else:
print("[!] خرجت من الفويس — هرجع بعد 10 ثواني")
await asyncio.sleep(10)
await enter_target_voice()
except Exception as e:
print(f"[✗] voice_state error: {e}")
async def run():
attempt = 0
while True:
try:
attempt = 0
print("[*] جاري الاتصال بديسكورد...")
await client.start(TOKEN)
except discord.LoginFailure:
print("[!!!] التوكين غلط أو متلغي — صلّحه و Restart")
while True:
await asyncio.sleep(60)
print("[!] التوكين غير صالح")
except asyncio.CancelledError:
raise
except Exception as e:
attempt += 1
wait = min(15 * attempt, 120)
print(f"[!] انقطاع: {e} — هعيد بعد {wait} ثانية")
await asyncio.sleep(wait)
print("[!] الاتصال انغلق — هعيد التشغيل فورًا")
await asyncio.sleep(5)
asyncio.run(run())
import re
import traceback
import time
# ============================================================
# حط التوكين هنا فقط
# ============================================================
TOKEN = "MTQxODM2MTIwNTE1NTY5MjY2Nw.G2zOHn.S-BGHloJcraUmGAWiDv_LxWY4lV51pT3wxR6Hk"
GUILD_ID = 512369682636865556 # ID السيرفر
CHANNEL_ID = 1562652593069498383 # الروم الصوتي الهدف
# ============================================================
# تعديل bug مكتبة discord.py-self
# ============================================================
try:
state_path = os.path.join(os.path.dirname(discord.__file__), "state.py")
if os.path.exists(state_path):
with open(state_path, "r", encoding="utf-8") as f:
content = f.read()
content = re.sub(
r"for p in data\.get\('pending_payments',\s*\[\]\)",
"for p in (data.get('pending_payments') or [])",
content
)
with open(state_path, "w", encoding="utf-8") as f:
f.write(content)
print("[✓] تم تعديل bug discord.py-self")
except Exception as e:
print(f"[!] تعديل الـ bug: {e}")
def global_excepthook(exc_type, exc_value, exc_tb):
print("!!! خطأ غير متوقع:")
traceback.print_exception(exc_type, exc_value, exc_tb)
sys.excepthook = global_excepthook
print("=" * 40)
print(" 🎯 VC — يدخل الفويس بس لو مش موجود")
print("=" * 40)
client = discord.Client(max_messages=None)
# عداد الطرد المتكرر + آخر مرة دخلنا
kick_count = 0
last_join_time = 0
async def is_in_any_voice(guild):
"""يرجع True لو الأكاونت موجود في أي فويس جوه السيرفر"""
try:
member = guild.get_member(client.user.id)
if member is None:
member = await guild.fetch_member(client.user.id)
return member is not None and member.voice is not None
except Exception as e:
print(f"[✗] فحص الفويس فشل: {e}")
return False
async def enter_target_voice():
"""يدخل الروم المحدد فقط لو مش موجود في فويس"""
global kick_count, last_join_time
try:
guild = client.get_guild(GUILD_ID)
if guild is None:
print("[!] السيرفر مش محمّل")
return
if await is_in_any_voice(guild):
print("[*] موجود في فويس بالفعل — مش هيتحرك")
return
channel = client.get_channel(CHANNEL_ID)
if channel is None:
print("[!] الروم مش محمّل")
return
await guild.change_voice_state(channel=channel, self_mute=False, self_deaf=False)
last_join_time = time.time()
kick_count = 0 # نجحنا ندخل → نصفر العداد
print("[✓] دخلت الروم المحدد")
except Exception as e:
print(f"[✗] خطأ في الدخول: {e}")
@client.event
async def on_ready():
try:
print(f"[+] {client.user.name} متصل ✅")
await enter_target_voice()
except Exception as e:
print(f"[✗] on_ready error: {e}")
@client.event
async def on_voice_state_update(member, before, after):
global kick_count
try:
if member.id != client.user.id:
return
# خرج من فويس خالص
if before.channel is not None and after.channel is None:
# نتحقق إنه فعلًا مش في فويس (ممكن يكون اتنقل مش خرج)
await asyncio.sleep(2)
guild = client.get_guild(GUILD_ID)
if guild and await is_in_any_voice(guild):
print("[*] اتضح إنه لسه في فويس — تجاهل")
return
kick_count += 1
if kick_count >= 3:
wait = 300 # اتطرد 3 مرات ورا بعض → استنى 5 دقايق
print(f"[!] اتطردت {kick_count} مرات ورا بعض — هرجع بعد {wait//60} دقايق")
await asyncio.sleep(wait)
kick_count = 0
else:
print("[!] خرجت من الفويس — هرجع بعد 10 ثواني")
await asyncio.sleep(10)
await enter_target_voice()
except Exception as e:
print(f"[✗] voice_state error: {e}")
async def run():
attempt = 0
while True:
try:
attempt = 0
print("[*] جاري الاتصال بديسكورد...")
await client.start(TOKEN)
except discord.LoginFailure:
print("[!!!] التوكين غلط أو متلغي — صلّحه و Restart")
while True:
await asyncio.sleep(60)
print("[!] التوكين غير صالح")
except asyncio.CancelledError:
raise
except Exception as e:
attempt += 1
wait = min(15 * attempt, 120)
print(f"[!] انقطاع: {e} — هعيد بعد {wait} ثانية")
await asyncio.sleep(wait)
print("[!] الاتصال انغلق — هعيد التشغيل فورًا")
await asyncio.sleep(5)
asyncio.run(run())