File size: 31,315 Bytes
3a3b605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
"""التسلية والتحشيش والخدمات الشاملة:
- 30+ لقب تحشيش وقوائمها ومسحها (التاج، الملوك، الملكات، الثولان، الجلاب، المطايه، الصخول، البقرات، الزواحف، اللوكيه، الاغبياء، الطليان، الطامسين، العسل، الكيك، قلبي، الهطوف، البثرين، الحمير، الكلاب، الكلبات، العتوين، العتويات، اللحوج، اللحجيات، الخرفان، الخفيفين، الخفيفات)
- شنو رايك بهذا/بهاي، انطي هديه، بوسه/بوسني، صيحه، رزله، حضن، كف، قول
- زوجني، تتزوجني، ثنائي اليوم، اسمي، معرفي، تفاعلي/تفاعله، جهاتي/جهاته، نبذه، الوقت، نداء، نزلني
- البوت السحري، معنى اسم، حساب العمر، قوقل، قصص/ثريد، مقالات، زخرفة (16 شكل)، ترجمة (عربي/انقليزي)، أبراج، غنيلي."""
import random
import hashlib
from datetime import datetime
from urllib.parse import quote_plus
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CallbackQueryHandler
from core.router import exact, prefix, norm
from core import content
from core import ranks as R
from core.store import (
    settings, ranks_db, stats, users_db,
    get_counter, activity_label, find_user_by_username,
)
from modules.toggles import tg_on
from strings_ar import S


def _name(u):
    return u.first_name if u else ""


def _fun_ok(update):
    return tg_on(update.effective_chat.id, "fun")


def _pct(update, what):
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user
    h = int(hashlib.md5(f"{what}{t.id}".encode()).hexdigest(), 16) % 101
    return t, h


def _mk_pct(what, emoji):
    async def h(update, ctx, arg=""):
        if not _fun_ok(update):
            await update.message.reply_text(S["feature_off"])
            return
        t, p = _pct(update, what)
        await update.message.reply_text(S["percent"].format(what=what, name=_name(t), pct=p, emoji=emoji))
    return h


for w, e in (
    ("نسبه الحب", "❤️"), ("نسبه الغباء", "🤪"), ("نسبه الانوثه", "💅"),
    ("نسبه الرجوله", "💪"), ("نسبه الذكاء", "🧠"), ("نسبه الكدب", "🤥"),
    ("نسبه الجمال", "🌟"), ("نسبه الحظ", "🍀"), ("نسبه الصدق", "😇"),
    ("نسبه الكره", "😤"), ("نسبه العصبيه", "🔥"),
):
    exact(w)(_mk_pct(w, e))

exact("نسبه الرجولة", "نسبه رجولته")(_mk_pct("نسبه الرجوله", "💪"))
exact("نسبه انوثتها")(_mk_pct("نسبه الانوثه", "💅"))


@exact("تحبه")
async def toheb(update, ctx, arg=""):
    if not _fun_ok(update):
        await update.message.reply_text(S["feature_off"])
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    a = update.effective_user
    pct = int(hashlib.md5(f"love{a.id}{t.id}".encode()).hexdigest(), 16) % 101
    await update.message.reply_text(S["toheb"].format(a=a.first_name, b=t.first_name, pct=pct))


# ---------- قوائم رتب التحشيش ومسحها ----------
FUN_PLURALS = {
    "قائمه التاج": ("تاج", "التاج 👑"),
    "الملوك": ("ملك", "الملوك 👑"),
    "الملكات": ("ملكه", "الملكات 👸"),
    "الطامسين": ("طامس", "الطامسين 🫥"),
    "الثولان": ("اثول", "الثولان 🤪"),
    "الجلاب": ("جلب", "الجلاب 🐕"),
    "المطايه": ("مطي", "المطايه 🐴"),
    "الصخول": ("صخل", "الصخول 🐐"),
    "البقرات": ("بقره", "البقرات 🐄"),
    "الزواحف": ("زاحف", "الزواحف 🦎"),
    "اللوكيه": ("لوكي", "اللوكيه 😅"),
    "الاغبياء": ("غبي", "الاغبياء 🤡"),
    "العسل": ("عسل", "العسل 🍯"),
    "الكيك": ("كيك", "الكيك 🍰"),
    "الطليان": ("طلي", "الطليان 🐑"),
    "قائمه كلبي": ("بكلبي", "القلوب ❤️"),
    "قائمه القلوب": ("قلبي", "القلوب ❤️"),
    "قائمه ازواجي": ("زوجي", "الأزواج 💍"),
    "قائمه زوجاتي": ("زوجتي", "الزوجات 💍"),
    "قائمه الوتك": ("وتكه", "الوتك ✨"),
    "قائمه القرده": ("قرد", "القردة 🐒"),
    "الهطوف": ("هطف", "الهطوف 😹"),
    "البثرين": ("بثر", "البثرين 😂"),
    "الحمير": ("حمار", "الحمير 🐴"),
    "الكلاب": ("كلب", "الكلاب 🐕"),
    "الكلبات": ("كلبه", "الكلبات 🐕"),
    "العتوين": ("عتوي", "العتوين 🐈"),
    "العتويات": ("عتويه", "العتويات 🐈"),
    "اللحوج": ("لحجي", "اللحوج 🤠"),
    "اللحجيات": ("لحجيه", "اللحجيات 🤠"),
    "الخرفان": ("خروف", "الخرفان 🐑"),
    "الخفيفين": ("خفيف", "الخفيفين 🪶"),
    "الخفيفات": ("خفيفه", "الخفيفات 🪶"),
}


def _mk_fun_list(rk, title):
    async def h(update, ctx, arg=""):
        chat = update.effective_chat
        fun = ranks_db.get(chat.id, "f", {})
        uids = [int(u) for u, r in fun.items() if norm(r) == norm(rk)]
        if not uids:
            await update.message.reply_text(f"✧︙لا يوجد أحد في قائمة {title} حالياً.")
            return
        names = []
        for i in uids:
            try:
                m = await chat.get_member(i)
                names.append(m.user.first_name)
            except Exception:
                names.append(str(i))
        await update.message.reply_text(f"✧︙قائمة {title} ({len(names)}):\n" + "\n".join("• " + n for n in names))
    return h


def _mk_fun_clear(rk, title):
    async def h(update, ctx, arg=""):
        if await R.effective_level(update) < R.level("مدير"):
            await update.message.reply_text(S["need_rank"])
            return
        chat = update.effective_chat.id
        fun = ranks_db.get(chat, "f", {})
        new_fun = {u: r for u, r in fun.items() if norm(r) != norm(rk)}
        ranks_db.set(chat, "f", new_fun)
        await update.message.reply_text(f"✧︙تم مسح قائمة {title} ✅")
    return h


for _pl_cmd, (_rk, _title) in FUN_PLURALS.items():
    exact(_pl_cmd)(_mk_fun_list(_rk, _title))
    exact("مسح " + _pl_cmd)(_mk_fun_clear(_rk, _title))


@exact("رتب التسليه")
async def fun_ranks_all(update, ctx, arg=""):
    fun = ranks_db.get(update.effective_chat.id, "f", {})
    if not fun:
        await update.message.reply_text("✧︙لا توجد رتب تسلية مسجلة حالياً.")
        return
    lines = ["🎭 رتب التسلية في المجموعه:"]
    for u, r in list(fun.items())[:30]:
        lines.append(f"• `{u}` ← {r}")
    await update.message.reply_text("\n".join(lines), parse_mode="Markdown")


@exact("مسح رتب التسليه")
async def clear_all_fun_ranks(update, ctx, arg=""):
    if await R.effective_level(update) < R.level("مدير"):
        await update.message.reply_text(S["need_rank"])
        return
    ranks_db.set(update.effective_chat.id, "f", {})
    await update.message.reply_text("✧︙تم مسح جميع رتب التسلية ✅")


@exact("رفع بقلبي", "رفع بكلبي")
async def lift_in_heart(update, ctx, arg=""):
    r = update.message.reply_to_message
    if not r or not r.from_user:
        await update.message.reply_text(S["need_reply"])
        return
    d = ranks_db.get(update.effective_chat.id, "f", {})
    d[str(r.from_user.id)] = "بكلبي"
    ranks_db.set(update.effective_chat.id, "f", d)
    await update.message.reply_text(f"❤️ تم رفع {r.from_user.first_name} بقلبك!")


@exact("تنزيل من قلبي", "تنزيل من كلبي")
async def drop_from_heart(update, ctx, arg=""):
    r = update.message.reply_to_message
    if not r or not r.from_user:
        await update.message.reply_text(S["need_reply"])
        return
    d = ranks_db.get(update.effective_chat.id, "f", {})
    d.pop(str(r.from_user.id), None)
    ranks_db.set(update.effective_chat.id, "f", d)
    await update.message.reply_text(f"💔 تم تنزيل {r.from_user.first_name} من قلبك!")


# ---------- أوامر التحشيش بالرد ----------
OPINIONS = [
    "🔥 شخص فخم وذوقه عالي جداً!",
    "😂 طيب ودمه خفيف ومنوّر الجروب!",
    "👑 شخصية هيبة وكل الجروب بيحبه!",
    "✨ رايق وهادي وملوش في المشاكل!",
    "⚡ مجنون شوية بس عسل الصراحة!",
]


@exact("شنو رايك بهذا", "شنو رايك بهاي", "رايك فيه", "رايك فيها")
async def opinion_cmd(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user
    await update.message.reply_text(f"💬 رأيي في {t.first_name}: {random.choice(OPINIONS)}")


@exact("انطي هديه", "اهديه")
async def ahdiya(update, ctx, arg=""):
    if not _fun_ok(update):
        await update.message.reply_text(S["feature_off"])
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    l = content.lines("ahdiya.txt")
    gift = random.choice(l) if l else "وردة 🌹"
    to = f" إلى {_name(t)}" if t else ""
    await update.message.reply_text(f"🎁 {update.effective_user.first_name} أهدى{to}: {gift}")


@prefix("بوس", "بوسه")
async def boss_p(update, ctx, arg):
    if _fun_ok(update):
        await update.message.reply_text(f"😘 {update.effective_user.first_name} بعت بوسة لـ {arg} 💋")


@exact("بوس", "بوسه", "بوسني")
async def boss_e(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user
    await update.message.reply_text(f"😘 {update.effective_user.first_name} بعت بوسة لـ {t.first_name} 💋")


@exact("حضن")
async def hug(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    await update.message.reply_text(f"🫂 {update.effective_user.first_name} حضن {t.first_name} بقوة ❤️")


@exact("كف", "صفع")
async def slap(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    await update.message.reply_text(f"👋 {update.effective_user.first_name} ادّى {t.first_name} كف طيّر نضارته 😂")


@exact("صيحه")
async def call_out(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    await update.message.reply_text(f"📢 يا {t.first_name}!! {update.effective_user.first_name} بينادي عليك تعال بسرعة!")


@exact("رزله")
async def roast_light(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    await update.message.reply_text(f"😂 يا {t.first_name} اهدى شوية وخليك عاقل عشان محدش يزعلك!")


@prefix("قول", "قل", "كول")
async def say_cmd(update, ctx, arg):
    if _fun_ok(update) and arg:
        await update.message.reply_text(arg)


# ---------- زوجني / تتزوجني / ثنائي اليوم / اسمي / معرفي / تفاعلي / نبذه / نداء / نزلني ----------
@exact("زوجني", "تتزوجني")
async def marry_random(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "marryme"):
        await update.message.reply_text(S["feature_off"])
        return
    u_map = users_db.get(update.effective_chat.id, "u", {})
    others = [v for k, v in u_map.items() if int(k) != update.effective_user.id]
    if not others:
        await update.message.reply_text("💍 مفيش أعضاء متفاعلين كفاية نختارلك منهم حالياً 😅")
        return
    pick = random.choice(others)
    await update.message.reply_text(f"💍 مبروك! تم اختيار {pick.get('first') or pick.get('name')} شريك حياتك اليوم 😂❤️")


@exact("ثنائي اليوم")
async def couple_today(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "couple"):
        await update.message.reply_text(S["feature_off"])
        return
    u_map = list(users_db.get(update.effective_chat.id, "u", {}).values())
    if len(u_map) < 2:
        await update.message.reply_text("💑 محتاجين عضوين متفاعلين على الأقل!")
        return
    a, b = random.sample(u_map, 2)
    pct = random.randint(65, 100)
    await update.message.reply_text(f"💑 ثنائي اليوم في المجموعه:\n❤️ {a.get('first')} + {b.get('first')}\n💘 نسبة الانسجام: {pct}%")


@exact("اسمي")
async def my_name(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "myname"):
        return
    await update.message.reply_text(f"✧︙اسمك: {update.effective_user.full_name}")


@exact("معرفي")
async def my_user(update, ctx, arg=""):
    u = update.effective_user
    await update.message.reply_text(f"✧︙معرفك: @{u.username}" if u.username else "✧︙ليس لديك معرف (username).")


@exact("تفاعلي")
async def my_act(update, ctx, arg=""):
    n = get_counter(update.effective_chat.id, update.effective_user.id, "msgs")
    await update.message.reply_text(f"🔥 تفاعلك: {activity_label(n)} ({n} رسالة)")


@exact("تفاعله")
async def his_act_e(update, ctx, arg=""):
    await his_act_p(update, ctx, "")


@prefix("تفاعله")
async def his_act_p(update, ctx, arg):
    r = update.message.reply_to_message
    if r and r.from_user:
        uid, nm = r.from_user.id, r.from_user.first_name
    else:
        info = find_user_by_username(update.effective_chat.id, arg)
        if not info:
            await update.message.reply_text(S["need_reply"])
            return
        uid, nm = info["id"], info.get("first") or info.get("name")
    n = get_counter(update.effective_chat.id, uid, "msgs")
    await update.message.reply_text(f"🔥 تفاعل {nm}: {activity_label(n)} ({n} رسالة)")


@exact("جهاتي")
async def my_invites(update, ctx, arg=""):
    n = get_counter(update.effective_chat.id, update.effective_user.id, "invites")
    await update.message.reply_text(f"👥 عدد الأعضاء الذين أضفتهم: {n}")


@exact("جهاته")
async def his_invites(update, ctx, arg=""):
    r = update.message.reply_to_message
    if not r or not r.from_user:
        await update.message.reply_text(S["need_reply"])
        return
    n = get_counter(update.effective_chat.id, r.from_user.id, "invites")
    await update.message.reply_text(f"👥 عدد إضافات {r.from_user.first_name}: {n}")


@exact("نبذه", "نبذة")
async def about_me(update, ctx, arg=""):
    u = update.effective_user
    chat = update.effective_chat.id
    msgs = get_counter(chat, u.id, "msgs")
    pts = get_counter(chat, u.id, "pts")
    await update.message.reply_text(
        f"📋 نبذة عن {u.first_name}:\n"
        f"✧︙الرتبة: {R.get_custom_rank_label(chat, u.id)}\n"
        f"✧︙الرسائل: {msgs} | النقاط: {pts}\n"
        f"✧︙التفاعل: {activity_label(msgs)}"
    )


@exact("انا مين", "مين انا")
async def who_am_i(update, ctx, arg=""):
    await about_me(update, ctx, arg)


@exact("موقعي")
async def my_pos(update, ctx, arg=""):
    d = stats.get(update.effective_chat.id, "msgs", {})
    if not d:
        await update.message.reply_text(S["top_empty"])
        return
    ordered = sorted(d.items(), key=lambda x: -x[1])
    uid = str(update.effective_user.id)
    for idx, (k, v) in enumerate(ordered, 1):
        if k == uid:
            await update.message.reply_text(f"📍 موقعك في المتفاعلين: المركز #{idx} من {len(ordered)} ({v} رسالة) 🔥")
            return
    await update.message.reply_text("📍 لم تُسجّل لك رسائل بعد.")


@exact("نداء")
async def nida_cmd(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "mention"):
        await update.message.reply_text(S["feature_off"])
        return
    u_map = list(users_db.get(update.effective_chat.id, "u", {}).values())
    if not u_map:
        await update.message.reply_text("📢 لا يوجد أعضاء مسجلون حالياً.")
        return
    pick = random.choice(u_map)
    uname = ("@" + pick["user"]) if pick.get("user") else pick.get("first", "عضو")
    await update.message.reply_text(f"📢 نداء عشوائي إلى: {uname} — تعال شاركنا في الدردشة! ✨")


@exact("نزلني")
async def demote_me(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "demoteme"):
        await update.message.reply_text(S["feature_off"])
        return
    R.set_rank(update.effective_chat.id, update.effective_user.id, "عضو")
    await update.message.reply_text("✧︙تم تنزيل رتبتك في البوت إلى (عضو) ✅")


@exact("الوقت")
async def time_alias(update, ctx, arg=""):
    await update.message.reply_text("🕒 الوقت الآن: " + datetime.now().strftime("%I:%M %p"))


@exact("رابط الحذف", "اريد رابط الحذف", "اريد رابط حذف", "رابط حذف")
async def del_acc_link(update, ctx, arg=""):
    await update.message.reply_text("⚠️ رابط حذف حساب تليجرام الرسمي:\nhttps://my.telegram.org/auth?to=delete")


@exact("افتاره", "صورته")
async def his_avatar(update, ctx, arg=""):
    r = update.message.reply_to_message
    if not r or not r.from_user:
        await update.message.reply_text(S["need_reply"])
        return
    ph = await ctx.bot.get_user_profile_photos(r.from_user.id, limit=1)
    if ph.total_count:
        await update.message.reply_photo(ph.photos[0][-1].file_id)
    else:
        await update.message.reply_text("✧︙لا توجد صورة بروفايل.")


@exact("لقبه")
async def his_title(update, ctx, arg=""):
    r = update.message.reply_to_message
    if not r or not r.from_user:
        await update.message.reply_text(S["need_reply"])
        return
    fun = ranks_db.get(update.effective_chat.id, "f", {}).get(str(r.from_user.id))
    await update.message.reply_text(f"✧︙لقب {r.from_user.first_name}: {fun or 'لا يوجد لقب'}")


# ---------- البوت السحري + معنى اسم + العمر + قوقل + قصص/ثريد/مقالات ----------
MAGIC_ANS = [
    "🔮 أكيد طبعاً وبنسبة 100% ✅", "🔮 كل المؤشرات بتقول أيوه ✨",
    "🔮 غالباً أيوه، توكل على الله 👍", "🔮 اسألني تاني بعد شوية ⏳",
    "🔮 مش واضح دلوقتي، استنى وشوف 🤔", "🔮 مظنش الصراحة 😅",
    "🔮 لأ خالص، شوف غيرها ❌", "🔮 ممكن جداً لو اجتهدت 💪",
]


@prefix("البوت السحري")
async def magic_p(update, ctx, arg):
    if _fun_ok(update):
        await update.message.reply_text(random.choice(MAGIC_ANS))


@exact("البوت السحري")
async def magic_e(update, ctx, arg=""):
    if _fun_ok(update):
        await update.message.reply_text("🔮 اسألني سؤال! مثال: البوت السحري هنجح السنة دي؟")


@prefix("معنى", "معني")
async def name_meaning(update, ctx, arg):
    q = norm(arg.strip())
    if not q:
        await update.message.reply_text("✧︙اكتب: معنى + الاسم")
        return
    for line in content.lines("meanings.txt"):
        if ":" in line:
            k, v = line.split(":", 1)
            if norm(k.strip()) == q:
                await update.message.reply_text(f"✨ معنى اسم ({k.strip()}):\n{v.strip()}")
                return
    await update.message.reply_text(f"✧︙الاسم ({arg.strip()}) غير مسجل في القاموس حالياً.")


@prefix("العمر", "عمري")
async def calc_age(update, ctx, arg):
    try:
        val = int(arg.strip())
    except Exception:
        await update.message.reply_text("✧︙اكتب سنة ميلادك أو عمرك، مثال: العمر 2002")
        return
    now_year = datetime.now().year
    if 1920 <= val <= now_year:
        age, birth = now_year - val, val
    elif 1 <= val <= 110:
        age, birth = val, now_year - val
    else:
        await update.message.reply_text("✧︙اكتب سنة ميلاد صحيحة.")
        return
    await update.message.reply_text(f"🎂 سنة الميلاد: {birth}\n✧︙العمر: {age} سنة (~{age*12:,} شهر / ~{age*365:,} يوم)")


@prefix("قوقل", "جوجل")
async def google_link(update, ctx, arg):
    if not arg.strip():
        return
    url = f"https://www.google.com/search?q={quote_plus(arg.strip())}"
    kb = InlineKeyboardMarkup([[InlineKeyboardButton(f"🔍 بحث: {arg.strip()[:30]}", url=url)]])
    await update.message.reply_text(f"🌐 رابط البحث في جوجل:", reply_markup=kb)


@exact("شرايك في افتاري", "رايك في افتاري")
async def rate_avatar(update, ctx, arg=""):
    if _fun_ok(update):
        await update.message.reply_text(random.choice(["🔥 أفتارك فخم 10/10!", "😍 ذوقك عالي 9/10!", "👑 هيبة وفخامة 10/10!", "🌟 أطلق صورة في الجروب!"]))


@exact("شبيهي", "شبيهتي")
async def shabih(update, ctx, arg=""):
    if _fun_ok(update):
        l = content.lines("shabih.txt")
        await update.message.reply_text(f"شبيهك: {random.choice(l)}" if l else S["no_content"])


@exact("توافق")
async def tawafuq(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else None
    if not t:
        await update.message.reply_text(S["need_reply"])
        return
    a = update.effective_user
    pct = int(hashlib.md5(f"tawafuq{min(a.id, t.id)}{max(a.id, t.id)}".encode()).hexdigest(), 16) % 101
    await update.message.reply_text(S["tawafuq"].format(a=a.first_name, b=t.first_name, pct=pct))


@exact("عقوبه", "عقوبة")
async def oqoba(update, ctx, arg=""):
    if _fun_ok(update):
        t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user
        l = content.lines("oqobat.txt")
        await update.message.reply_text(S["oqoba"].format(name=t.first_name, o=random.choice(l)) if l else S["no_content"])


@exact("بايوات", "بايو عشوائي")
async def bios(update, ctx, arg=""):
    l = content.lines("bios.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("نكته", "نكتة")
async def joke(update, ctx, arg=""):
    l = content.lines("jokes.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("حكمه", "حكمة")
async def wisdom(update, ctx, arg=""):
    l = content.lines("hekma.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("دعاء", "ادعيه")
async def dua(update, ctx, arg=""):
    l = content.lines("adiya.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("اذكار")
async def azkar(update, ctx, arg=""):
    l = content.lines("azkar.txt")
    await update.message.reply_text(random.choice(l) if l else S["azkar_none"])


@exact("شعر", "قصائد", "اقتباسات")
async def poems(update, ctx, arg=""):
    l = content.lines("quotes.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("قصص", "ثريد", "كتب")
async def stories(update, ctx, arg=""):
    l = content.lines("stories.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("مقالات")
async def maqalat(update, ctx, arg=""):
    l = content.lines("maqalat.txt")
    await update.message.reply_text(random.choice(l) if l else S["no_content"])


@exact("غنيلي", "اطربني", "اغاني", "اغنيه")
async def ghanili(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "ghanili"):
        await update.message.reply_text(S["feature_off"])
        return
    l = content.lines("ghanili.txt")
    await update.message.reply_text("🎶 " + random.choice(l) if l else S["no_content"])


# ---------- الأبراج ----------
BRAJ = ["الحمل", "الثور", "الجوزاء", "السرطان", "الأسد", "العذراء", "الميزان", "العقرب", "القوس", "الجدي", "الدلو", "الحوت"]


@exact("ابراج", "الابراج")
async def abraj(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "abraj"):
        await update.message.reply_text(S["feature_off"])
        return
    rows = [[InlineKeyboardButton(b, callback_data=f"brj:{i}", style="primary") for i, b in enumerate(BRAJ[r:r + 3], r)] for r in range(0, 12, 3)]
    await update.message.reply_text("✧︙اختار برجك:", reply_markup=InlineKeyboardMarkup(rows))


# دعم كتابة اسم البرج مباشرة (مثل: الحمل، الأسد، العقرب...)
for _bi, _bname in enumerate(BRAJ):
    def _mk_brj(idx, nm):
        async def _h(update, ctx, arg=""):
            if not tg_on(update.effective_chat.id, "abraj"):
                return
            lines = content.lines("abraj.txt")
            txt = lines[idx] if idx < len(lines) else "يومك حلو إن شاء الله ✨"
            await update.message.reply_text(f"♈︙برج {nm}:\n{txt}")
        return _h
    exact(_bname, "برج " + _bname)(_mk_brj(_bi, _bname))


async def brj_cb(update, ctx):
    q = update.callback_query
    await q.answer()
    i = int(q.data.split(":")[1])
    lines = content.lines("abraj.txt")
    text = lines[i] if i < len(lines) else "يومك حلو إن شاء الله ✨"
    await q.edit_message_text(f"♈︙ برج {BRAJ[i]}:\n{text}")


@exact("حظر محدود")
async def fakeban(update, ctx, arg=""):
    if not tg_on(update.effective_chat.id, "fakeban"):
        await update.message.reply_text(S["feature_off"])
        return
    t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user
    await update.message.reply_text(S["fakeban"].format(name=_name(t)))


# ---------- زخرفة + ترجمة ----------
DECOR = {"ا": "آ", "ب": "بـ", "ت": "تـ", "ن": "نـ", "ي": "يـ", "م": "مـ", "ك": "كـ", "ل": "لـ", "س": "سـ", "ع": "عـ"}


def _zhrf_styles(t):
    spaced = " ".join(t)
    return [
        "".join(DECOR.get(c, c) for c in t), "༺ " + t + " ༻", "『 " + spaced + " 』",
        "۝ " + t + " ۝", "⌁ " + t + " ⌁", "ـ".join(t), "⋆ " + spaced + " ⋆",
        "✧︙" + t + "︙✧", "⌁〔 " + t + " 〕⌁", "◈ " + " ◈ ".join(t.split()) + " ◈",
        "⟬ " + t + " ⟭", "•°• " + spaced + " •°•", "⪼ " + t + " ⪻",
        "✦。 " + t + " 。✦", "╰─ " + t + " ─╯", "꧁ " + t + " ꧂",
    ]


@prefix("زخرف", "زخرفه")
async def zakhraf(update, ctx, arg):
    if not arg:
        await update.message.reply_text(S["zakhraf_usage"])
        return
    await update.message.reply_text("\n\n".join(f"{i+1}- {s}" for i, s in enumerate(_zhrf_styles(arg))))


async def _do_translate(update, text, target=None):
    if not text:
        await update.message.reply_text("✧︙اكتب النص بعد أمر الترجمة أو رد على رسالة.")
        return
    try:
        from deep_translator import GoogleTranslator
        if not target:
            ar = any("؀" <= c <= "ۿ" for c in text)
            target = "en" if ar else "ar"
        out = GoogleTranslator(source="auto", target=target).translate(text)
        await update.message.reply_text(out)
    except Exception:
        await update.message.reply_text("✧︙تعذّرت الترجمة حالياً.")


@prefix("ترجم عربي")
async def tr_ar(update, ctx, arg):
    await _do_translate(update, arg or (update.message.reply_to_message.text if update.message.reply_to_message else ""), "ar")


@prefix("ترجم انقليزي", "ترجم انجليزي")
async def tr_en(update, ctx, arg):
    await _do_translate(update, arg or (update.message.reply_to_message.text if update.message.reply_to_message else ""), "en")


@prefix("ترجم")
async def translate(update, ctx, arg):
    await _do_translate(update, arg or (update.message.reply_to_message.text if update.message.reply_to_message else ""), None)


# ---------- زواج ----------
@exact("زواج")
async def marry(update, ctx, arg=""):
    if not _fun_ok(update):
        return
    chat, r, a = update.effective_chat.id, update.message.reply_to_message, update.effective_user
    mar = settings.get(chat, "marry", {})
    if not r or r.from_user.id == a.id or str(a.id) in mar or str(r.from_user.id) in mar:
        await update.message.reply_text(S["marry_no"])
        return
    b = r.from_user
    mar[str(a.id)] = {"p": b.id, "n": b.first_name}
    mar[str(b.id)] = {"p": a.id, "n": a.first_name}
    settings.set(chat, "marry", mar)
    await update.message.reply_text(S["marry_ok"].format(a=a.first_name, b=b.first_name))


@exact("طلاق")
async def divorce(update, ctx, arg=""):
    chat, a = update.effective_chat.id, update.effective_user
    mar = settings.get(chat, "marry", {})
    me = mar.pop(str(a.id), None)
    if not me:
        await update.message.reply_text(S["no_partner"])
        return
    mar.pop(str(me["p"]), None)
    settings.set(chat, "marry", mar)
    await update.message.reply_text(S["divorce_ok"].format(a=a.first_name, b=me["n"]))


@exact("زوجي", "زوجتي")
async def partner(update, ctx, arg=""):
    me = settings.get(update.effective_chat.id, "marry", {}).get(str(update.effective_user.id))
    await update.message.reply_text(S["partner_is"].format(role="شريكك", name=me["n"]) if me else S["no_partner"])


HANDLERS = [CallbackQueryHandler(brj_cb, pattern=r"^brj:")]