File size: 31,507 Bytes
21bc372
 
dc4a555
21bc372
 
dc4a555
21bc372
 
ecbc262
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecbc262
 
 
a4f0503
ecbc262
a4f0503
 
 
 
57ddd3f
 
ecbc262
 
 
a4f0503
 
ecbc262
 
 
a4f0503
ecbc262
 
a4f0503
ecbc262
a4f0503
ecbc262
 
 
 
 
 
1134589
 
4676c16
 
1134589
ecbc262
 
a4f0503
ecbc262
 
a4f0503
 
ecbc262
a4f0503
ecbc262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4f0503
 
 
 
 
 
dc4a555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4f0503
 
 
1134589
 
 
4676c16
 
 
 
 
 
 
 
 
 
 
 
 
1134589
 
4676c16
1134589
a4f0503
ecbc262
6769ec3
a4f0503
 
 
 
6769ec3
ecbc262
a4f0503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6769ec3
a4f0503
 
 
6769ec3
a4f0503
ecbc262
21bc372
 
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6769ec3
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6769ec3
21bc372
 
 
 
6769ec3
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6769ec3
21bc372
 
 
6769ec3
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
21bc372
 
 
 
 
6769ec3
21bc372
 
 
6769ec3
21bc372
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
 
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ddd3f
6769ec3
 
57ddd3f
21bc372
 
 
 
 
 
 
 
 
 
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
import time
from datetime import datetime as dt, timedelta
from pyrogram import Client as ren
from pyrogram import *
from pyrogram.types import *
from pyrogram.errors import *
from akn.utils.database import db as db_client
from akn.utils.logger import LOGS
from akn.manage.new_start_funcs import initial_client_bots, initial_client_user
from config import *

storage_running = {}
active_bots = {}

@ren.on_callback_query(filters.regex(r"^stopcts_(\d+)$"))
async def stopv_client(bot: Client, cb: CallbackQuery):
    user_id = int(cb.matches[0].group(1))
    if user_id not in storage_running:
        await cb.answer("No active client found for this user.", show_alert=True)
        return
    user_bots = storage_running[user_id]
    if not user_bots:
        await cb.answer("No active client found for this user.", show_alert=True)
        return
    if not user_bots.is_connected:
        await cb.answer("Client is not connected, cannot stop.", show_alert=True)
        return
    try:
        await user_bots.stop()
        del storage_running[user_id]
        await cb.answer("Client stopped successfully.", show_alert=True)
    except AttributeError:
        await cb.answer("Client object does not have 'stop' method.", show_alert=True)
        return
    except Exception as e:
        await cb.answer(f"Error stopping client: {type(e).__name__}: {str(e)}", show_alert=True)
        return

@ren.on_callback_query(filters.regex(r"^(rejected_ub|pending_ub|approved_ub)_(\d+)$"))
async def ubadmin_action(client: Client, callback: CallbackQuery):
    global storage_running
    
    try:
        action, user_id = callback.matches[0].groups()
        action_type = action.split('_')[0]
        admin_id = callback.from_user.id
        admin_mention = callback.from_user.mention
        if admin_id != 6477856957:
            return await callback.answer("❌ Only Developer", show_alert=True)
        request = await db_client.session.find_one({"user_id": int(user_id)})
        if not request:
            await callback.answer("❌ User request not found!", show_alert=True)
            await callback.message.edit_text(f"{callback.message.text}\n\n⚠️ Failed: Request not found")
            return

        update_data = {
            "user_client.$.status": action_type,
            "last_updated": dt.now().isoformat(),
            "user_client.$.admin_action": {
                "by": admin_id,
                "at": dt.now().isoformat(),
                "username": callback.from_user.username
            }
        }

        if action_type == "rejected":
            update_data["user_client.$.admin_action"]["reason"] = "No reason provided"

        update_result = await db_client.session.update_one(
            {
                "_id": request["_id"],
                "user_client.status": "pending",
                "user_client.user_id": int(user_id)
            },
            {"$set": update_data}
        )

        if not update_result.modified_count:
            await callback.answer("❌ Update failed!", show_alert=True)
            return

        if action_type == "approved":
            await handle_approvalub(client, callback, request, user_id, admin_id, admin_mention)

        status_icon = {
            "approved": "βœ…",
            "rejected": "❌",
            "pending": "πŸ•’"
        }.get(action_type, "ℹ️")

        await callback.message.edit_text(
            f"{callback.message.text}\n\n"
            f"{status_icon} Status: {action_type.capitalize()}ed by {admin_mention}\n"
            f"⏰ {dt.now().strftime('%Y-%m-%d %H:%M:%S')}",
            reply_markup=None
        )
        await callback.answer(f"Request {action_type}d successfully!")

    except Exception as e:
        LOGS.error(f"Admin action error: {str(e)}")
        await handle_errorub(client, callback, e, action, admin_mention)

async def handle_approvalub(client, callback, request, user_id, admin_id, admin_mention):
    try:
        string_session = request["user_client"][0]["session_string"]
        user_bots = initial_client_user(string_session)
        try:
            await user_bots.start()
            bot_user = await user_bots.get_me()
        except AuthKeyUnregistered as e:
            await client.send_message(
                -1002407639480,
                f"Error reason: AuthKeyUnregistered `{user_id}`"
            )
            await client.send_message(user_id, "Error reason: AuthKeyUnregistered")
            return
        except Exception as e:
            LOGS.error(f"Error handle_approvalub: {str(e)}")
            await client.send_message(
                user_id,
                "⚠️ Userbot approval failed due to technical reasons.\n"
                "Our team has been notified. Please try again later."
            )
            return

        global storage_running
        storage_running[user_id] = user_bots

        await db_client.session.update_one(
            {
                "_id": request["_id"],
                "user_client.status": "pending",
                "user_client.user_id": int(user_id)
            },
            {
                "$set": {
                    "user_client.$.user_id": bot_user.id,
                    "user_client.$.status": "approved",
                    "user_client.$.is_active": True,
                    "user_client.$.username": bot_user.username or "N/A",
                    "user_client.$.started_at": dt.now().isoformat(),
                    "user_client.$.admin_action": {
                        "by": admin_id,
                        "at": dt.now().isoformat()
                    }
                }
            }
        )
        await notify_userub(client, user_id, bot_user)
        await client.send_message(
            -1002407639480,
            f"βœ… Userbot Approved Successfully\n\n"
            f"πŸ‘€ User: {request.get('username', 'N/A')} ({user_id})\n"
            f"⭐ Username: {bot_user.username}\n"
            f"πŸ›  Approved by: {admin_mention}\n"
            f"⏰ Time: {dt.now().strftime('%Y-%m-%d %H:%M:%S')}"
        )
    except Exception as e:
        LOGS.error(f"Approval error: {str(e)}")

async def notify_userub(client, user_id, bot_user):
    caption = (
        "πŸŽ‰ **Your Userbot Has Been Approved!**\n\n"
        f"πŸ”± Name: {bot_user.first_name}\n"
        f"βœ” Username: @{bot_user.username or 'N/A'}\n"
        f"πŸ†” User ID: `{bot_user.id}`\n\n"
        "You can now userbot try `.ping`\n\n"
        "Akeno Userbot By akn-dev"
    )
    await client.send_photo(
        user_id,
        photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
        caption=caption,
        reply_markup=InlineKeyboardMarkup([
            [InlineKeyboardButton("Channel", url="https://t.me/RendyProjects")]
        ])
    )

async def handle_errorub(client, callback, error, action, admin_mention):
    await callback.answer("⚠️ Error", show_alert=True)
    await callback.message.edit_text(
        f"{callback.message.text}\n\n❌ Error: {str(error)}"
    )
    await client.send_message(
        -1002407639480,
        f"🚨 Admin Action Error\n\n"
        f"Action: {action}\n"
        f"Admin: {admin_mention}\n"
        f"Error: {str(error)}"
    )

@ren.on_callback_query(filters.regex(r"^(rejected_alldl|pending_alldl|approved_alldl)_(\d+)_(\w+)$"))
async def handle_admin_action(client: Client, callback: CallbackQuery):
    global storage_running

    action, user_id, uuid = callback.matches[0].groups()
    action_type = action.split('_')[0]
    admin_id = callback.from_user.id
    admin_mention = callback.from_user.mention
    if admin_id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    try:
        request = await db_client.alldl_bot.find_one({"user_id": int(user_id)})
        if not request:
            await callback.answer("❌ User request not found!", show_alert=True)
            return await callback.message.edit_text(
                f"{callback.message.text}\n\n⚠️ Failed: Request not found in database"
            )

        target_bot = None
        for bot in request.get("bots", []):
            if bot.get("uuid") == uuid:
                target_bot = bot
                break

        if not target_bot:
            await callback.answer("❌ No matching bot found!", show_alert=True)
            return await callback.message.edit_text(
                f"{callback.message.text}\n\n⚠️ Failed: No matching bot found"
            )

        bot_token = target_bot["bot_token"]

        update_data = {
            "bots.$.status": action_type,
            "bots.$.admin_action": {
                "by": admin_id,
                "at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
                "username": callback.from_user.username
            },
            "last_updated": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }

        if action_type == "rejected":
            update_data["bots.$.status"] = "rejected"
            update_data["bots.$.admin_action"]["reason"] = "No reason provided"

        update_result = await db_client.alldl_bot.update_one(
            {
                "user_id": int(user_id),
                "bots.uuid": uuid
            },
            {"$set": update_data}
        )

        if not update_result.modified_count:
            await callback.answer("❌ Update failed!", show_alert=True)
            return await callback.message.edit_text(
                f"{callback.message.text}\n\n⚠️ Failed: update unsuccessful"
            )

        if action_type == "approved":
            try:
                user_bots = initial_client_bots(bot_token)
                await user_bots.start()

                storage_running[user_id] = user_bots
                bot_user = await user_bots.get_me()
                bot_username = f"@{bot_user.username}"
                link_start = f"https://t.me/{bot_user.username}?start=start"

                await db_client.alldl_bot.update_one(
                    {
                        "user_id": int(user_id),
                        "bots.uuid": uuid
                    },
                    {
                        "$set": {
                            "bots.$.bot_id": bot_user.id,
                            "bots.$.status": "approved",
                            "bots.$.is_active": True,
                            "bots.$.created_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
                            "bots.$.start_time": dt.now(),
                            "bots.$.bot_username": f"@{bot_user.username}",
                            "bots.$.bot_id": bot_user.id,
                            "bots.$.started_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
                            "bots.$.admin_action": {
                                "by": admin_id,
                                "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
                            }
                        },
                        "$inc": {"deployed_bots": 1}
                    }
                )

                caption = (
                    "πŸŽ‰ **Your Azrea Bot Has Been Approved!**\n\n"
                    f"πŸ€– Bot Name: {bot_user.first_name}\n"
                    f"πŸ”— Username: {bot_username}\n"
                    f"πŸ†” Bot ID: `{bot_user.id}`\n\n"
                    "You can now start using your bot!\n\n"
                    "All Downloader Bot By akn-dev"
                )

                keyboard_start_now = InlineKeyboardMarkup([
                    [InlineKeyboardButton("πŸš€ Start Using Bot", url=link_start)],
                    [InlineKeyboardButton("πŸ“Š Manage Bots", callback_data="my_bots")]
                ])

                await client.send_photo(
                    user_id,
                    photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                    caption=caption,
                    reply_markup=keyboard_start_now
                )

                await client.send_message(
                    -1002407639480,
                    f"βœ… Bot Approved Successfully\n\n"
                    f"πŸ‘€ User: {request.get('username', 'N/A')} ({user_id})\n"
                    f"πŸ€– Bot: {bot_username}\n"
                    f"πŸ›  Approved by: {admin_mention}\n"
                    f"⏰ Time: {dt.now().strftime('%Y-%m-%d %H:%M:%S')}"
                )

            except Exception as e:
                LOGS.error(f"Bot approval error: {str(e)}")
                await db_client.alldl_bot.update_one(
                    {
                        "user_id": int(user_id),
                        "bots.uuid": uuid
                    },
                    {
                        "$set": {
                            "bots.$.is_active": False,
                            "bots.$.error": str(e),
                            "bots.$.status": "error"
                        }
                    }
                )
                await client.send_message(
                    -1002407639480,
                    f"❌ Bot Approval Failed\n\n"
                    f"User ID: {user_id}\n"
                    f"Error: {str(e)}\n"
                    f"UUID: `{uuid}`"
                )
                await client.send_message(
                    user_id,
                    "⚠️ Bot approval failed due to technical reasons.\n"
                    "Our team has been notified. Please try again later."
                )
                return

        status_icon = {
            "approved": "βœ…",
            "rejected": "❌",
            "pending": "πŸ•’"
        }.get(action_type, "ℹ️")

        await callback.message.edit_text(
            f"{callback.message.text}\n\n"
            f"{status_icon} Status: {action_type.capitalize()}ed by {admin_mention}\n"
            f"⏰ {dt.now().strftime('%Y-%m-%d %H:%M:%S')}",
            reply_markup=None
        )
        await callback.answer(f"Request {action_type}d successfully!")

    except Exception as e:
        LOGS.error(f"Admin action error: {str(e)}")
        await callback.answer("⚠️ error!", show_alert=True)
        await callback.message.edit_text(
            f"{callback.message.text}\n\n"
            f"❌ Error: {str(e)}"
        )
        await client.send_message(
            -1002407639480,
            f"🚨 Admin Action Error\n\n"
            f"Action: {action}\n"
            f"Admin: {admin_mention}\n"
            f"Error: {str(e)}"
        )

@ren.on_callback_query(filters.regex(r"^(approve_capt|reject_capt)_(\d+)$"))
async def handle_captbot_action(client, callback: CallbackQuery):
    global storage_running
    action, user_id = callback.matches[0].groups()
    action_type = action.replace("_capt", "")
    if callback.from_user.id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    update_data = {
        "status": "approved" if action_type == "approve" else "rejected",
        "admin_action": {
            "by": 6477856957,
            "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    }
    
    if action == "reject_capt":
        update_data["admin_action"]["reason"] = "No reason provided"

    await db_client.captcha_bot.update_one(
        {"user_id": int(user_id)},
        {"$set": update_data},
        upsert=True
    )
    
    if action == "approve_capt":
        request = await db_client.captcha_bot.find_one({"user_id": int(user_id)})
        bot_token = request["bot_token"]
        try:
            user_bots = initial_client_bots(bot_token, "ApproveBot")
            await user_bots.start()
            storage_running[user_id] = user_bots
        except Exception as e:
            await client.send_message(user_id, "Sorry Try Again")
            await client.send_message(
                -1002407639480,
                f"Error captcha {str(e)}"
            )
            return
            
        try:
            bot_user = await user_bots.get_me()
            bot_username = "@" + bot_user.username
            bot_first_name = bot_user.first_name
            link_start = "https://t.me/{}?start=start".format(bot_user.username)
            caption = ""
            caption += "Bot Name : {}\n".format(bot_first_name)
            caption += "Bot Username : {}\n".format(bot_username)
            caption += "Bot ID : <code>{}</code>\n".format(bot_user.id)
            caption += "Captcha Bot By akn-dev\n"
            
            keyboard_start_now = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="Check Start Bot",
                            url=link_start
                        ),
                        InlineKeyboardButton(
                            text="Stop Client",
                            callback_data=f"stopcts_{user_id}"
                        )
                    ],
                ]
            )
            
            await client.send_photo(
                user_id,
                photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                caption=caption,
                reply_markup=keyboard_start_now
            )
            await db_client.captcha_bot.update_one(
                {"user_id": user_id},
                {"$set": {"status": "approved"}},
                upsert=True
            )
        except Exception as e:
            await client.send_message(
                -1002407639480,
                f"Error captcha {str(e)}"
            )
            await client.send_message(user_id, "Sorry Try Again")
            return
    
    status_icon = "βœ…" if action_type == "approve" else "❌"
    await callback.message.edit_text(
        f"{callback.message.text}\n\n"
        f"Status: {status_icon} {action_type.capitalize()}ed by admin",
        reply_markup=None
    )
    await callback.answer(f"Request {action_type}ed!")

@ren.on_callback_query(filters.regex(r"^(approve_sesibot|reject_sesibot)_(\d+)$"))
async def handle_sesibot_action(client, callback: CallbackQuery):
    global storage_running
    action, user_id = callback.matches[0].groups()
    action_type = action.replace("_sesibot", "")
    if callback.from_user.id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    update_data = {
        "status": "approved" if action_type == "approve" else "rejected",
        "admin_action": {
            "by": 6477856957,
            "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    }
    
    if action == "reject_sesibot":
        update_data["admin_action"]["reason"] = "No reason provided"

    await db_client.session_bot.update_one(
        {"user_id": int(user_id)},
        {"$set": update_data},
        upsert=True
    )
    
    if action == "approve_sesibot":
        request = await db_client.session_bot.find_one({"user_id": int(user_id)})
        bot_token = request["bot_token"]
        try:
            user_bots = initial_client_bots(bot_token, plugins="SessionBot")
            await user_bots.start()
            storage_running[user_id] = user_bots
        except Exception as e:
            await client.send_message(user_id, "Sorry Try Again")
            await client.send_message(
                -1002407639480,
                f"Error sesibot {str(e)}"
            )
            return
            
        try:
            bot_user = await user_bots.get_me()
            bot_username = "@" + bot_user.username
            bot_first_name = bot_user.first_name
            link_start = "https://t.me/{}?start=start".format(bot_user.username)
            caption = ""
            caption += "Bot Name : {}\n".format(bot_first_name)
            caption += "Bot Username : {}\n".format(bot_username)
            caption += "Bot ID : <code>{}</code>\n".format(bot_user.id)
            caption += "Session Bot By akn-dev\n"
            
            keyboard_start_now = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="Check Start Bot",
                            url=link_start
                        )
                    ],
                ]
            )
            
            await client.send_photo(
                user_id,
                photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                caption=caption,
                reply_markup=keyboard_start_now
            )
            await db_client.session_bot.update_one(
                {"user_id": user_id},
                {"$set": {"status": "approved"}},
                upsert=True
            )
        except Exception as e:
            await client.send_message(
                -1002407639480,
                f"Error sesibot {str(e)}"
            )
            await client.send_message(user_id, "Sorry Try Again")
            return
    
    status_icon = "βœ…" if action_type == "approve" else "❌"
    await callback.message.edit_text(
        f"{callback.message.text}\n\n"
        f"Status: {status_icon} {action_type.capitalize()}ed by admin",
        reply_markup=None
    )
    await callback.answer(f"Request {action_type}ed!")

@ren.on_callback_query(filters.regex(r"^(approve_magicbot|reject_magicbot)_(\d+)$"))
async def handle_magicbot_action(client, callback: CallbackQuery):
    global storage_running
    action, user_id = callback.matches[0].groups()
    action_type = action.replace("_magicbot", "")
    if callback.from_user.id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    update_data = {
        "status": "approved" if action_type == "approve" else "rejected",
        "admin_action": {
            "by": 6477856957,
            "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    }
    
    if action == "reject_magicbot":
        update_data["admin_action"]["reason"] = "No reason provided"

    await db_client.magic_bot.update_one(
        {"user_id": int(user_id)},
        {"$set": update_data},
        upsert=True
    )
    
    if action == "approve_magicbot":
        request = await db_client.magic_bot.find_one({"user_id": int(user_id)})
        bot_token = request["bot_token"]
        try:
            user_bots = initial_client_bots(bot_token, plugins="MagicFonts")
            await user_bots.start()
            storage_running[user_id] = user_bots
        except Exception as e:
            await client.send_message(user_id, "Sorry Try Again")
            await client.send_message(
                -1002407639480,
                f"Error magic {str(e)}"
            )
            return
            
        try:
            bot_user = await user_bots.get_me()
            bot_username = "@" + bot_user.username
            bot_first_name = bot_user.first_name
            link_start = "https://t.me/{}?start=start".format(bot_user.username)
            caption = ""
            caption += "Bot Name : {}\n".format(bot_first_name)
            caption += "Bot Username : {}\n".format(bot_username)
            caption += "Bot ID : <code>{}</code>\n".format(bot_user.id)
            caption += "Magic Fonts Bot By akn-dev\n"
            
            keyboard_start_now = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="Check Start Bot",
                            url=link_start
                        ),
                        InlineKeyboardButton(
                            text="Stop Client",
                            callback_data=f"stopcts_{user_id}"
                        )
                    ],
                ]
            )
            
            await client.send_photo(
                user_id,
                photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                caption=caption,
                reply_markup=keyboard_start_now
            )
            await db_client.magic_bot.update_one(
                {"user_id": user_id},
                {"$set": {"status": "approved"}},
                upsert=True
            )
        except Exception as e:
            await client.send_message(
                -1002407639480,
                f"Error Magic {str(e)}"
            )
            await client.send_message(user_id, "Sorry Try Again")
            return
    
    status_icon = "βœ…" if action_type == "approve" else "❌"
    await callback.message.edit_text(
        f"{callback.message.text}\n\n"
        f"Status: {status_icon} {action_type.capitalize()}ed by admin",
        reply_markup=None
    )
    await callback.answer(f"Request {action_type}ed!")

@ren.on_callback_query(filters.regex(r"^(approve_ytbot|reject_ytbot)_(\d+)$"))
async def handle_ytbot_action(client, callback: CallbackQuery):
    global storage_running
    action, user_id = callback.matches[0].groups()
    action_type = action.replace("_magicbot", "")
    if callback.from_user.id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    update_data = {
        "status": "approved" if action_type == "approve" else "rejected",
        "admin_action": {
            "by": 6477856957,
            "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    }
    
    if action == "reject_ytbot":
        update_data["admin_action"]["reason"] = "No reason provided"

    await db_client.youtube_bot.update_one(
        {"user_id": int(user_id)},
        {"$set": update_data},
        upsert=True
    )
    
    if action == "approve_ytbot":
        request = await db_client.youtube_bot.find_one({"user_id": int(user_id)})
        bot_token = request["bot_token"]
        try:
            user_bots = initial_client_bots(bot_token, plugins="Youtube")
            await user_bots.start()
        except Exception as e:
            await client.send_message(user_id, "Sorry Try Again")
            await client.send_message(
                -1002407639480,
                f"Error ytbot {str(e)}"
            )
            return
            
        try:
            bot_user = await user_bots.get_me()
            bot_username = "@" + bot_user.username
            bot_first_name = bot_user.first_name
            link_start = "https://t.me/{}?start=start".format(bot_user.username)
            caption = ""
            caption += "Bot Name : {}\n".format(bot_first_name)
            caption += "Bot Username : {}\n".format(bot_username)
            caption += "Bot ID : <code>{}</code>\n".format(bot_user.id)
            caption += "Youtube Bot By akn-dev\n"
            
            keyboard_start_now = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="Check Start Bot",
                            url=link_start
                        ),
                        InlineKeyboardButton(
                            text="Stop Client",
                            callback_data=f"stopcts_{user_id}"
                        )
                    ],
                ]
            )
            
            await client.send_photo(
                user_id,
                photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                caption=caption,
                reply_markup=keyboard_start_now
            )
            await db_client.youtube_bot.update_one(
                {"user_id": user_id},
                {"$set": {"status": "approved"}},
                upsert=True
            )
        except Exception as e:
            await client.send_message(
                -1002407639480,
                f"Error Ytbot {str(e)}"
            )
            await client.send_message(user_id, "Sorry Try Again")
            return
    
    status_icon = "βœ…" if action_type == "approve" else "❌"
    await callback.message.edit_text(
        f"{callback.message.text}\n\n"
        f"Status: {status_icon} {action_type.capitalize()}ed by admin",
        reply_markup=None
    )
    await callback.answer(f"Request {action_type}ed!")

@ren.on_callback_query(filters.regex(r"^(approve_geminibot|reject_geminibot)_(\d+)$"))
async def handle_geminibot_action(client, callback: CallbackQuery):
    global storage_running
    action, user_id = callback.matches[0].groups()
    action_type = action.replace("_geminibot", "")
    if callback.from_user.id != 6477856957:
        return await callback.answer("❌ Only Developer", show_alert=True)
    update_data = {
        "status": "approved" if action_type == "approve" else "rejected",
        "admin_action": {
            "by": 6477856957,
            "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    }
    
    if action == "reject_geminibot":
        update_data["admin_action"]["reason"] = "No reason provided"

    await db_client.gemini_bot.update_one(
        {"user_id": int(user_id)},
        {"$set": {"status": "approved"}},
        upsert=True
    )
    
    if action == "approve_geminibot":
        request = await db_client.gemini_bot.find_one({"user_id": int(user_id)})
        bot_token = request["bot_token"]
        try:
            user_bots = initial_client_bots(bot_token, plugins="Gemini")
            await user_bots.start()
            storage_running[user_id] = user_bots
        except Exception as e:
            await client.send_message(user_id, "Sorry Try Again")
            await client.send_message(PRIVATE_LOGS, f"Error {e}")
            return
            
        try:
            bot_user = await user_bots.get_me()
            bot_username = "@" + bot_user.username
            bot_first_name = bot_user.first_name
            link_start = "https://t.me/{}?start=start".format(bot_user.username)
            caption = ""
            caption += "Bot Name : {}\n".format(bot_first_name)
            caption += "Bot Username : {}\n".format(bot_username)
            caption += "Bot ID : <code>{}</code>\n".format(bot_user.id)
            caption += "Gemini Bot By akn-dev\n"
            
            keyboard_start_now = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="Check Start Bot",
                            url=link_start
                        ),
                        InlineKeyboardButton(
                            text="Stop Client",
                            callback_data=f"stopcts_{user_id}"
                        )
                    ],
                ]
            )
            
            await client.send_photo(
                user_id,
                photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
                caption=caption,
                reply_markup=keyboard_start_now
            )
            await db_client.gemini_bot.update_one(
                {"user_id": user_id},
                {"$set": {"status": "approved"}},
                upsert=True
            )
        except Exception as e:
            await client.send_message(
                -1002407639480,
                f"Error Gemini {str(e)}"
            )
            await client.send_message(user_id, "Sorry Try Again")
            return
    
    status_icon = "βœ…" if action_type == "approve" else "❌"
    await callback.message.edit_text(
        f"{callback.message.text}\n\n"
        f"Status: {status_icon} {action_type.capitalize()}ed by admin",
        reply_markup=None
    )
    await callback.answer(f"Request {action_type}ed!")