randydev commited on
Commit
a4f0503
Β·
verified Β·
1 Parent(s): 8f5e02f
Files changed (1) hide show
  1. akn/manage/approve_params.py +82 -111
akn/manage/approve_params.py CHANGED
@@ -38,129 +38,43 @@ async def stopv_client(bot: Client, cb: CallbackQuery):
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
- },
72
  {"$set": update_data}
73
  )
 
74
  if not update_result.modified_count:
75
  await callback.answer("❌ Update failed!", show_alert=True)
76
- return await callback.message.edit_text(
77
- f"{callback.message.text}\n\n⚠️ Failed: update unsuccessful"
78
- )
79
- string_session = request["user_client"][0]["session_string"]
80
- if action_type == "approved":
81
- try:
82
- user_bots = initial_client_user(string_session)
83
- await user_bots.start()
84
-
85
- storage_running[user_id] = user_bots
86
- bot_user = await user_bots.get_me()
87
- bot_username = f"@{bot_user.username if bot_user.username else 'N/A'}"
88
-
89
- await db_client.session.update_one(
90
- {
91
- "user_id": int(user_id)
92
- },
93
- {
94
- "$set": {
95
- "user_client.$.user_id": bot_user.id,
96
- "user_client.$.status": "approved",
97
- "user_client.$.is_active": True,
98
- "user_client.$.created_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
99
- "user_client.$.start_time": dt.now(),
100
- "user_client.$.username": bot_user.username or "N/A",
101
- "user_client.$.started_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
102
- "user_client.$.admin_action": {
103
- "by": admin_id,
104
- "at": dt.now().strftime("%Y-%m-%d %H:%M:%S")
105
- }
106
- }
107
- }
108
- )
109
- caption = (
110
- "πŸŽ‰ **Your Userbot Has Been Approved!**\n\n"
111
- f"πŸ”± Name: {bot_user.first_name}\n"
112
- f"βœ” Username: {bot_username}\n"
113
- f"πŸ†” User ID: `{bot_user.id}`\n\n"
114
- "You can now userbot try `.ping`\n\n"
115
- "Akeno Userbot By akn-dev"
116
- )
117
-
118
- keyboard_start_now = InlineKeyboardMarkup([
119
- [InlineKeyboardButton("Channel", url="https://t.me/RendyProjects")]
120
- ])
121
-
122
- await client.send_photo(
123
- user_id,
124
- photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
125
- caption=caption,
126
- reply_markup=keyboard_start_now
127
- )
128
-
129
- await client.send_message(
130
- PRIVATE_LOGS,
131
- f"βœ… Userbot Approved Successfully\n\n"
132
- f"πŸ‘€ User: {request.get('username', 'N/A')} ({user_id})\n"
133
- f"βœ” Username: {bot_username}\n"
134
- f"πŸ›  Approved by: {admin_mention}\n"
135
- f"⏰ Time: {dt.now().strftime('%Y-%m-%d %H:%M:%S')}"
136
- )
137
 
138
- except Exception as e:
139
- LOGS.error(f"Userbot approval error: {str(e)}")
140
- await db_client.session.update_one(
141
- {
142
- "user_id": int(user_id),
143
- },
144
- {
145
- "$set": {
146
- "user_client.$.is_active": False,
147
- "user_client.$.error": str(e),
148
- "user_client.$.status": "error"
149
- }
150
- }
151
- )
152
- await client.send_message(
153
- PRIVATE_LOGS,
154
- f"❌ Userbot Approval Failed\n\n"
155
- f"User ID: {user_id}\n"
156
- f"Error: {str(e)}"
157
- )
158
- await client.send_message(
159
- user_id,
160
- "⚠️ Userbot approval failed due to technical reasons.\n"
161
- "Our team has been notified. Please try again later."
162
- )
163
- return
164
 
165
  status_icon = {
166
  "approved": "βœ…",
@@ -178,19 +92,76 @@ async def ubadmin_action(client: Client, callback: CallbackQuery):
178
 
179
  except Exception as e:
180
  LOGS.error(f"Admin action error: {str(e)}")
181
- await callback.answer("⚠️ error ", show_alert=True)
182
- await callback.message.edit_text(
183
- f"{callback.message.text}\n\n"
184
- f"❌ Error: {str(e)}"
185
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  await client.send_message(
187
  PRIVATE_LOGS,
188
- f"🚨 Admin Action Error\n\n"
189
- f"Action: {action}\n"
190
- f"Admin: {admin_mention}\n"
191
- f"Error: {str(e)}"
 
192
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  @ren.on_callback_query(filters.regex(r"^(rejected_alldl|pending_alldl|approved_alldl)_(\d+)_(\w+)$"))
196
  async def handle_admin_action(client: Client, callback: CallbackQuery):
 
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
+
 
 
 
 
42
  try:
43
+ action, user_id = callback.matches[0].groups()
44
+ action_type = action.split('_')[0]
45
+ admin_id = callback.from_user.id
46
+ admin_mention = callback.from_user.mention
47
+
48
  request = await db_client.session.find_one({"user_id": int(user_id)})
49
  if not request:
50
  await callback.answer("❌ User request not found!", show_alert=True)
51
+ await callback.message.edit_text(f"{callback.message.text}\n\n⚠️ Failed: Request not found")
52
+ return
 
 
53
 
54
  update_data = {
55
  "user_client.$.status": action_type,
56
+ "last_updated": dt.now().isoformat(),
57
  "user_client.$.admin_action": {
58
  "by": admin_id,
59
+ "at": dt.now().isoformat(),
60
  "username": callback.from_user.username
61
+ }
 
62
  }
63
 
64
  if action_type == "rejected":
65
  update_data["user_client.$.admin_action"]["reason"] = "No reason provided"
66
 
67
  update_result = await db_client.session.update_one(
68
+ {"user_id": int(user_id)},
 
 
69
  {"$set": update_data}
70
  )
71
+
72
  if not update_result.modified_count:
73
  await callback.answer("❌ Update failed!", show_alert=True)
74
+ return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
+ if action_type == "approved":
77
+ await handle_approvalub(client, callback, request, user_id, admin_id, admin_mention)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  status_icon = {
80
  "approved": "βœ…",
 
92
 
93
  except Exception as e:
94
  LOGS.error(f"Admin action error: {str(e)}")
95
+ await handle_errorub(client, callback, e, action, admin_mention)
96
+
97
+ async def handle_approvalub(client, callback, request, user_id, admin_id, admin_mention):
98
+ try:
99
+ string_session = request["user_client"][0]["session_string"]
100
+ user_bots = initial_client_user(string_session)
101
+
102
+ await user_bots.start()
103
+ bot_user = await user_bots.get_me()
104
+
105
+ global storage_running
106
+ storage_running[user_id] = user_bots
107
+
108
+ update = {
109
+ "$set": {
110
+ "user_client.$.user_id": bot_user.id,
111
+ "user_client.$.status": "approved",
112
+ "user_client.$.is_active": True,
113
+ "user_client.$.username": bot_user.username or "N/A",
114
+ "user_client.$.started_at": dt.now().isoformat(),
115
+ "user_client.$.admin_action": {
116
+ "by": admin_id,
117
+ "at": dt.now().isoformat()
118
+ }
119
+ }
120
+ }
121
+
122
+ await db_client.session.update_one({"user_id": int(user_id)}, update)
123
+ await notify_userub(client, user_id, bot_user)
124
  await client.send_message(
125
  PRIVATE_LOGS,
126
+ f"βœ… Userbot Approved Successfully\n\n"
127
+ f"πŸ‘€ User: {request.get('username', 'N/A')} ({user_id})\n"
128
+ f"⭐ Username: {bot_user.username}\n"
129
+ f"πŸ›  Approved by: {admin_mention}\n"
130
+ f"⏰ Time: {dt.now().strftime('%Y-%m-%d %H:%M:%S')}"
131
  )
132
+ except Exception as e:
133
+ LOGS.error(f"Approval error: {str(e)}")
134
+
135
+ async def notify_userub(client, user_id, bot_user):
136
+ caption = (
137
+ "πŸŽ‰ **Your Userbot Has Been Approved!**\n\n"
138
+ f"πŸ”± Name: {bot_user.first_name}\n"
139
+ f"βœ” Username: @{bot_user.username or 'N/A'}\n"
140
+ f"πŸ†” User ID: `{bot_user.id}`\n\n"
141
+ "You can now userbot try `.ping`\n\n"
142
+ "Akeno Userbot By akn-dev"
143
+ )
144
+ await client.send_photo(
145
+ user_id,
146
+ photo="https://telegra.ph//file/586a3867c3e16ca6bb4fa.jpg",
147
+ caption=caption,
148
+ reply_markup=InlineKeyboardMarkup([
149
+ [InlineKeyboardButton("Channel", url="https://t.me/RendyProjects")]
150
+ ])
151
+ )
152
 
153
+ async def handle_errorub(client, callback, error, action, admin_mention):
154
+ await callback.answer("⚠️ Error", show_alert=True)
155
+ await callback.message.edit_text(
156
+ f"{callback.message.text}\n\n❌ Error: {str(error)}"
157
+ )
158
+ await client.send_message(
159
+ PRIVATE_LOGS,
160
+ f"🚨 Admin Action Error\n\n"
161
+ f"Action: {action}\n"
162
+ f"Admin: {admin_mention}\n"
163
+ f"Error: {str(error)}"
164
+ )
165
 
166
  @ren.on_callback_query(filters.regex(r"^(rejected_alldl|pending_alldl|approved_alldl)_(\d+)_(\w+)$"))
167
  async def handle_admin_action(client: Client, callback: CallbackQuery):