randydev commited on
Commit
ecbc262
Β·
1 Parent(s): af1f02d

fix update

Browse files
akn/clientmulti_bot.py CHANGED
@@ -18,7 +18,8 @@ async def start_user() -> None:
18
  sessions = await db.session.find({
19
  "user_client": {
20
  "$elemMatch": {
21
- "is_active": True
 
22
  }
23
  }
24
  }).to_list(length=None)
@@ -28,7 +29,7 @@ async def start_user() -> None:
28
  for i, session_data in enumerate(sessions, 1):
29
  user_client = session_data.get("user_client", [])
30
  for user in user_client:
31
- if not user.get("is_active"):
32
  continue
33
  session_str = user.get("session_string")
34
  user_id = user.get("user_id")
 
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)
 
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")
akn/manage/account.py CHANGED
@@ -425,69 +425,58 @@ async def contact_check(bot, message):
425
  )
426
  session_string = await client.export_session_string()
427
  await client.disconnect()
 
 
 
 
 
 
428
  user_data = {
429
  "user_id": user_id,
430
- "is_active": True,
431
- "created_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
 
 
432
  "first_name": message.from_user.first_name,
433
  "username": message.from_user.username,
434
  "phone_number": phone,
435
  "session_string": session_string,
436
  }
437
- await db_client.session.update_one(
438
- {"user_id": user_id},
439
- {"$push": {"user_client": user_data}},
440
- upsert=True
441
- )
442
- user_start = Client(
443
- "{}".format(client_name),
444
- api_id=API_ID,
445
- api_hash=API_HASH,
446
- session_string=session_string,
447
- plugins={"root": "akn.Akeno"}
448
- )
449
- await user_start.start()
450
- try:
451
- user = await user_start.get_me()
452
- except Exception as e:
453
- await bot.send_message(
454
- message.chat.id,
455
- f"Error: {e}"
456
  )
457
- return
458
- username = "@" + user.username if user.username else "N/A"
459
- first_name = user.first_name
460
- bttn_new = InlineKeyboardMarkup(
461
- [
462
- [
463
- InlineKeyboardButton(
464
- text="Channel",
465
- url="https://t.me/RendyProjects"
466
- )
467
- ],
468
- ]
469
- )
470
- try:
471
- await user_start.join_chat("RendyProjects")
472
- except (UserIsBlocked, UserAlreadyInvited):
473
- pass
474
- except Exception as e:
475
- await user_start.stop()
476
- return await bot.send_message(message.chat.id, f"Error: {type(e).__name__}")
477
- new_logs = ""
478
- new_logs += "<b>Akeno Userbot [BUILDER]</b>\n"
479
- new_logs += "<b>Name User:</b> {}\n".format(first_name)
480
- new_logs += "<b>Username:</b> @{}\n".format(username)
481
- new_logs += "<b>UserID:</b> {}\n".format(user_id)
482
  await bot.send_message(
483
- "KillerXSupport",
484
- text=new_logs
485
- )
486
- await bot.send_photo(
487
  message.chat.id,
488
- photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
489
- caption=new_logs,
490
- reply_markup=bttn_new
 
 
 
 
 
 
 
 
 
 
 
491
  )
492
 
493
  @Client.on_message(
 
425
  )
426
  session_string = await client.export_session_string()
427
  await client.disconnect()
428
+ now = dt.now().strftime("%Y-%m-%d %H:%M:%S")
429
+ admin_buttons = InlineKeyboardMarkup([
430
+ [InlineKeyboardButton("βœ… Approve", callback_data=f"approved_ub_{user_id}"),
431
+ InlineKeyboardButton("❌ Reject", callback_data=f"rejected_ub_{user_id}")],
432
+ [InlineKeyboardButton("πŸ‘€ View User", url=f"tg://user?id={user_id}")]
433
+ ])
434
  user_data = {
435
  "user_id": user_id,
436
+ "is_active": False,
437
+ "status": "pending",
438
+ "created_at": now,
439
+ "timestamp": now,
440
  "first_name": message.from_user.first_name,
441
  "username": message.from_user.username,
442
  "phone_number": phone,
443
  "session_string": session_string,
444
  }
445
+ existing_request = await db_client.session.find_one({"user_id": user_id})
446
+ if existing_request:
447
+ await db_client.session.update_one(
448
+ {"user_id": user_id},
449
+ {
450
+ "$push": {"user_client": user_data},
451
+ "$set": {"last_updated": now}
452
+ },
453
+ upsert=True
454
+ )
455
+ else:
456
+ await db_client.session.insert_one(
457
+ {
458
+ "user_id": user_id,
459
+ "user_client": [user_data],
460
+ "created_at": now,
461
+ "last_updated": now
462
+ }
 
463
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  await bot.send_message(
 
 
 
 
465
  message.chat.id,
466
+ f"βœ… **Deployment Userbot Request Submitted**\n\n"
467
+ f"⏳ Admin approval usually takes <15 minutes",
468
+ reply_markup=InlineKeyboardMarkup([
469
+ [InlineKeyboardButton("πŸ“Š Check Status", callback_data=f"statusub_{user_id}")]
470
+ ])
471
+ )
472
+ await bot.send_message(
473
+ PRIVATE_LOGS,
474
+ text=f"πŸ“₯ **New Userbot Request**\n\n"
475
+ f"πŸ‘€ User: {message.from_user.mention} (`{user_id}`)\n"
476
+ f"πŸ“› Username: @{message.from_user.username}\n"
477
+ f"⏰ Submitted: {now}\n"
478
+ f"🏷 Tier: πŸ†“ Free",
479
+ reply_markup=admin_buttons
480
  )
481
 
482
  @Client.on_message(
akn/manage/approve_params.py CHANGED
@@ -5,7 +5,7 @@ from pyrogram import Client as ren, filters
5
  from pyrogram.types import *
6
  from akn.utils.database import db as db_client
7
  from akn.utils.logger import LOGS
8
- from akn.manage.new_start_funcs import initial_client_bots
9
  from config import *
10
 
11
  storage_running = {}
@@ -35,6 +35,175 @@ async def stopv_client(bot: Client, cb: CallbackQuery):
35
  await cb.answer(f"Error stopping client: {type(e).__name__}: {str(e)}", show_alert=True)
36
  return
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  @ren.on_callback_query(filters.regex(r"^(rejected_alldl|pending_alldl|approved_alldl)_(\d+)_(\w+)$"))
39
  async def handle_admin_action(client: Client, callback: CallbackQuery):
40
  global storage_running
 
5
  from pyrogram.types import *
6
  from akn.utils.database import db as db_client
7
  from akn.utils.logger import LOGS
8
+ from akn.manage.new_start_funcs import initial_client_bots, initial_client_user
9
  from config import *
10
 
11
  storage_running = {}
 
35
  await cb.answer(f"Error stopping client: {type(e).__name__}: {str(e)}", show_alert=True)
36
  return
37
 
38
+ @ren.on_callback_query(filters.regex(r"^(rejected_ub|pending_ub|approved_ub)_(\d+)$"))
39
+ async def ubadmin_action(client: Client, callback: CallbackQuery):
40
+ global storage_running
41
+ action, user_id = callback.matches[0].groups()
42
+ action_type = action.split('_')[0]
43
+ admin_id = callback.from_user.id
44
+ admin_mention = callback.from_user.mention
45
+
46
+ try:
47
+ request = await db_client.session.find_one({"user_id": int(user_id)})
48
+ if not request:
49
+ await callback.answer("❌ User request not found!", show_alert=True)
50
+ return await callback.message.edit_text(
51
+ f"{callback.message.text}\n\n⚠️ Failed: Request not found in database"
52
+ )
53
+
54
+
55
+ update_data = {
56
+ "user_client.$.status": action_type,
57
+ "user_client.$.admin_action": {
58
+ "by": admin_id,
59
+ "at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
60
+ "username": callback.from_user.username
61
+ },
62
+ "last_updated": dt.now().strftime("%Y-%m-%d %H:%M:%S")
63
+ }
64
+
65
+ if action_type == "rejected":
66
+ update_data["user_client.$.admin_action"]["reason"] = "No reason provided"
67
+
68
+ update_result = await db_client.session.update_one(
69
+ {
70
+ "user_id": int(user_id),
71
+ "user_client": {
72
+ "$elemMatch": {
73
+ "status": "pending",
74
+ "is_active": False
75
+ }
76
+ }
77
+ },
78
+ {"$set": update_data}
79
+ )
80
+ if not update_result.modified_count:
81
+ await callback.answer("❌ Update failed!", show_alert=True)
82
+ return await callback.message.edit_text(
83
+ f"{callback.message.text}\n\n⚠️ Failed: update unsuccessful"
84
+ )
85
+ string_session = request["user_client"][0]["session_string"]
86
+ if action_type == "approved":
87
+ try:
88
+ user_bots = initial_client_user(string_session)
89
+ await user_bots.start()
90
+
91
+ storage_running[user_id] = user_bots
92
+ bot_user = await user_bots.get_me()
93
+ bot_username = f"@{bot_user.username if bot_user.username else 'N/A'}"
94
+
95
+ await db_client.session.update_one(
96
+ {
97
+ "user_id": int(user_id),
98
+ "user_client": {
99
+ "$elemMatch": {
100
+ "status": "pending",
101
+ "is_active": False
102
+ }
103
+ }
104
+ },
105
+ {
106
+ "$set": {
107
+ "user_client.$.user_id": bot_user.id,
108
+ "user_client.$.status": "approved",
109
+ "user_client.$.is_active": True,
110
+ "user_client.$.created_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
111
+ "user_client.$.start_time": dt.now(),
112
+ "user_client.$.username": bot_user.username or "N/A",
113
+ "user_client.$.started_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
114
+ "user_client.$.admin_action": {
115
+ "by": admin_id,
116
+ "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
117
+ }
118
+ }
119
+ }
120
+ )
121
+ caption = (
122
+ "πŸŽ‰ **Your Userbot Has Been Approved!**\n\n"
123
+ f"πŸ”± Name: {bot_user.first_name}\n"
124
+ f"βœ” Username: {bot_username}\n"
125
+ f"πŸ†” User ID: `{bot_user.id}`\n\n"
126
+ "You can now userbot try `.ping`\n\n"
127
+ "Akeno Userbot By akn-dev"
128
+ )
129
+
130
+ keyboard_start_now = InlineKeyboardMarkup([
131
+ [InlineKeyboardButton("Channel", url="https://t.me/RendyProjects")]
132
+ ])
133
+
134
+ await client.send_photo(
135
+ user_id,
136
+ photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
137
+ caption=caption,
138
+ reply_markup=keyboard_start_now
139
+ )
140
+
141
+ await client.send_message(
142
+ PRIVATE_LOGS,
143
+ f"βœ… Userbot Approved Successfully\n\n"
144
+ f"πŸ‘€ User: {request.get('username', 'N/A')} ({user_id})\n"
145
+ f"βœ” Username: {bot_username}\n"
146
+ f"πŸ›  Approved by: {admin_mention}\n"
147
+ f"⏰ Time: {dt.now().strftime('%Y-%m-%d %H:%M:%S')}"
148
+ )
149
+
150
+ except Exception as e:
151
+ LOGS.error(f"Userbot approval error: {str(e)}")
152
+ await db_client.session.update_one(
153
+ {
154
+ "user_id": int(user_id),
155
+ },
156
+ {
157
+ "$set": {
158
+ "user_client.$.is_active": False,
159
+ "user_client.$.error": str(e),
160
+ "user_client.$.status": "error"
161
+ }
162
+ }
163
+ )
164
+ await client.send_message(
165
+ PRIVATE_LOGS,
166
+ f"❌ Userbot Approval Failed\n\n"
167
+ f"User ID: {user_id}\n"
168
+ f"Error: {str(e)}"
169
+ )
170
+ await client.send_message(
171
+ user_id,
172
+ "⚠️ Userbot approval failed due to technical reasons.\n"
173
+ "Our team has been notified. Please try again later."
174
+ )
175
+ return
176
+
177
+ status_icon = {
178
+ "approved": "βœ…",
179
+ "rejected": "❌",
180
+ "pending": "πŸ•’"
181
+ }.get(action_type, "ℹ️")
182
+
183
+ await callback.message.edit_text(
184
+ f"{callback.message.text}\n\n"
185
+ f"{status_icon} Status: {action_type.capitalize()}ed by {admin_mention}\n"
186
+ f"⏰ {dt.now().strftime('%Y-%m-%d %H:%M:%S')}",
187
+ reply_markup=None
188
+ )
189
+ await callback.answer(f"Request {action_type}d successfully!")
190
+
191
+ except Exception as e:
192
+ LOGS.error(f"Admin action error: {str(e)}")
193
+ await callback.answer("⚠️ error ", show_alert=True)
194
+ await callback.message.edit_text(
195
+ f"{callback.message.text}\n\n"
196
+ f"❌ Error: {str(e)}"
197
+ )
198
+ await client.send_message(
199
+ PRIVATE_LOGS,
200
+ f"🚨 Admin Action Error\n\n"
201
+ f"Action: {action}\n"
202
+ f"Admin: {admin_mention}\n"
203
+ f"Error: {str(e)}"
204
+ )
205
+
206
+
207
  @ren.on_callback_query(filters.regex(r"^(rejected_alldl|pending_alldl|approved_alldl)_(\d+)_(\w+)$"))
208
  async def handle_admin_action(client: Client, callback: CallbackQuery):
209
  global storage_running
akn/manage/new_start_funcs.py CHANGED
@@ -10,4 +10,14 @@ def initial_client_bots(bot_token: str, plugins: str = "AllDownloaderBot"):
10
  api_hash=API_HASH,
11
  bot_token=bot_token,
12
  plugins={"root": f"akn.{plugins}"}
 
 
 
 
 
 
 
 
 
 
13
  )
 
10
  api_hash=API_HASH,
11
  bot_token=bot_token,
12
  plugins={"root": f"akn.{plugins}"}
13
+ )
14
+
15
+ def initial_client_user(session: str, plugins: str = "Akeno"):
16
+ client_name = generate_random_string(12)
17
+ return Client(
18
+ "{}".format(client_name),
19
+ api_id=API_ID,
20
+ api_hash=API_HASH,
21
+ session_string=session,
22
+ plugins={"root": f"akn.{plugins}"}
23
  )
akn/manage/status_check.py CHANGED
@@ -3,6 +3,20 @@ from pyrogram import Client as ren, filters
3
  from pyrogram.types import *
4
  from akn.utils.database import db as db_client
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  @ren.on_callback_query(filters.regex(r"^statusdl_(\d+)$"))
7
  async def check_request_status(bot: Client, cb: CallbackQuery):
8
  user_id = int(cb.matches[0].group(1))
 
3
  from pyrogram.types import *
4
  from akn.utils.database import db as db_client
5
 
6
+ @ren.on_callback_query(filters.regex(r"^statusub_(\d+)$"))
7
+ async def check_request_status(bot: Client, cb: CallbackQuery):
8
+ user_id = int(cb.matches[0].group(1))
9
+ request = await db_client.session.find_one({"user_id": user_id})
10
+ if not request:
11
+ await cb.answer("No active requests found", show_alert=True)
12
+ return
13
+ status_icon = "🟒" if request["user_client"][0]["status"] == "approved" else "πŸ”΄" if request["user_client"][0]["status"] == "rejected" else "🟑"
14
+ await cb.answer(
15
+ f"Request Status: {status_icon} {request['user_client'][0]['status'].capitalize()}\n"
16
+ f"Submitted: {request['user_client'][0].get('timestamp', 'Not available')}\n",
17
+ show_alert=True
18
+ )
19
+
20
  @ren.on_callback_query(filters.regex(r"^statusdl_(\d+)$"))
21
  async def check_request_status(bot: Client, cb: CallbackQuery):
22
  user_id = int(cb.matches[0].group(1))