randydev commited on
Commit
40a765d
·
verified ·
1 Parent(s): 04ad76b
Files changed (1) hide show
  1. akn/clientmulti_bot.py +71 -56
akn/clientmulti_bot.py CHANGED
@@ -14,63 +14,78 @@ from akn import ids, gemini_bot_id
14
  from pyrogram import __version__ as pyrogram_version
15
  from box import Box
16
 
17
- async def start_user() -> None:
18
- sessions = await db.session.find({
19
- "user_client": {
20
- "$elemMatch": {
21
- "is_active": True,
22
- "status": "approved"
 
 
23
  }
24
- }
25
- }).to_list(length=None)
26
- if not sessions:
27
- return
28
- active_clients = []
29
- for i, session_data in enumerate(sessions, 1):
30
- user_client = session_data.get("user_client", [])
31
- for user in user_client:
32
- if not (user.get("status") == "approved" and user.get("is_active")):
33
- continue
34
- session_str = user.get("session_string")
35
- user_id = user.get("user_id")
36
- if not (session_str and user_id):
37
- continue
38
- try:
39
- client = Client(
40
- name=f"UserBot_{i}_{user_id}",
41
- api_id=API_ID,
42
- api_hash=API_HASH,
43
- session_string=session_str,
44
- plugins=dict(root="akn.Akeno"),
45
- workdir="/tmp/akn_userbot",
46
- app_version="UserBot/latest",
47
- device_model="Anonymous",
48
- system_version="Linux/Kernel-6.5",
49
- sleep_threshold=30
50
- )
51
- await client.start()
52
- me = await client.get_me()
53
- if me.id != user_id:
54
- raise ValueError(f"Session user_id mismatch (expected {user_id}, got {me.id})")
55
- ids.append(user_id)
56
- LOGS.info(f"✅ Started User #{i}: Name: {me.first_name}")
57
- active_clients.append(client)
58
- asyncio.create_task(
59
- _check_session_health(client, user_id),
60
- name=f"health_monitor_{user_id}"
61
- )
62
- except (
63
- UserDeactivatedBan,
64
- AuthKeyDuplicated,
65
- UserDeactivated,
66
- AuthKeyUnregistered,
67
- SessionRevoked
68
- ) as e:
69
- await _handle_dead_session(user_id, e)
70
- continue
71
- except Exception as e:
72
- LOGS.error(f"⚠️ User #{i} failed: {type(e).__name__}: {str(e)}")
73
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  async def start_magic_bot() -> None:
76
  sessions = await db.get_all_magic_bot()
 
14
  from pyrogram import __version__ as pyrogram_version
15
  from box import Box
16
 
17
+ async def start_user():
18
+ try:
19
+ sessions = await db.session.find({
20
+ "user_client": {
21
+ "$elemMatch": {
22
+ "is_active": True,
23
+ "status": "approved"
24
+ }
25
  }
26
+ }).to_list(length=None)
27
+
28
+ if not sessions:
29
+ LOGS.warning("No approved and active user sessions found.")
30
+ return
31
+
32
+ active_clients = []
33
+
34
+ for i, session_data in enumerate(sessions, 1):
35
+ user_client = session_data.get("user_client", [])
36
+ for user in user_client:
37
+ if not (user.get("status") == "approved" and user.get("is_active")):
38
+ continue
39
+
40
+ session_str = user.get("session_string")
41
+ user_id = user.get("user_id")
42
+
43
+ if not (session_str and user_id):
44
+ continue
45
+
46
+ try:
47
+ client = Client(
48
+ name=f"UserBot_{i}_{user_id}",
49
+ api_id=API_ID,
50
+ api_hash=API_HASH,
51
+ session_string=session_str,
52
+ plugins=dict(root="akn.Akeno"),
53
+ workdir="/tmp/akn_userbot",
54
+ app_version="UserBot/latest",
55
+ device_model="Anonymous",
56
+ system_version="Linux/Kernel-6.5",
57
+ sleep_threshold=30
58
+ )
59
+ await client.start()
60
+ me = await client.get_me()
61
+ if me.id != user_id:
62
+ raise ValueError(f"Session user_id mismatch (expected {user_id}, got {me.id})")
63
+
64
+ ids.append(user_id)
65
+ LOGS.info(f"✅ Started User #{i}: Name: {me.first_name}")
66
+ active_clients.append(client)
67
+
68
+ asyncio.create_task(
69
+ _check_session_health(client, user_id),
70
+ name=f"health_monitor_{user_id}"
71
+ )
72
+
73
+ except (
74
+ UserDeactivatedBan,
75
+ AuthKeyDuplicated,
76
+ UserDeactivated,
77
+ AuthKeyUnregistered,
78
+ SessionRevoked
79
+ ) as e:
80
+ await _handle_dead_session(user_id, e)
81
+ continue
82
+
83
+ except Exception as e:
84
+ LOGS.error(f"⚠️ User #{i} failed: {type(e).__name__}: {str(e)}")
85
+ continue
86
+
87
+ except Exception as err:
88
+ LOGS.error(f"start_user() crashed: {type(err).__name__}: {err}")
89
 
90
  async def start_magic_bot() -> None:
91
  sessions = await db.get_all_magic_bot()