import re

with open('bot.php', 'r', encoding='utf-8') as f:
    code = f.read()

lines = code.split('\n')
cleaned = []
in_comment = False

for line in lines:
    s = line.strip()
    if '/*' in s and '*/' in s: continue
    if '/*' in s: in_comment = True; continue
    if '*/' in s: in_comment = False; continue
    if in_comment or not s or s.startswith('//') or s.startswith('#'): continue
    cleaned.append(line)

code = '\n'.join(cleaned)

# حذف فاصله‌های اضافی
code = re.sub(r' +', ' ', code)
code = re.sub(r' \{', '{', code)
code = re.sub(r'\} ', '}', code)

with open('bot_optimized.php', 'w', encoding='utf-8') as f:
    f.write(code)

print("فایل با موفقیت سبک شد!")