- akn/manage/bots_manage.py +191 -87
akn/manage/bots_manage.py
CHANGED
@@ -8,6 +8,7 @@ from datetime import datetime as dt
|
|
8 |
from pyrogram import *
|
9 |
from pyrogram import Client as ren, filters
|
10 |
from pyrogram.types import *
|
|
|
11 |
from akn.utils.database import db as db_client
|
12 |
from akn.manage.settings_control import verify_bot_ownershipdl
|
13 |
from akn.utils.logger import LOGS
|
@@ -45,7 +46,7 @@ async def show_user_bots(client: Client, callback: CallbackQuery):
|
|
45 |
message_text += f"π <b>Active Bots:</b> {sum(1 for b in bots_by_status['approved'] if b.get('is_active'))}\n"
|
46 |
message_text += f"β³ <b>Pending:</b> {len(bots_by_status['pending'])}\n"
|
47 |
message_text += f"β <b>Rejected:</b> {len(bots_by_status['rejected'])}\n"
|
48 |
-
message_text += f"
|
49 |
|
50 |
buttons = []
|
51 |
|
@@ -66,21 +67,21 @@ async def show_user_bots(client: Client, callback: CallbackQuery):
|
|
66 |
if bots_by_status["pending"]:
|
67 |
message_text += "\nπ <b>Pending Approval:</b>\n"
|
68 |
for bot in bots_by_status["pending"]:
|
69 |
-
token_preview = bot.get("bot_token", "")[:10] +
|
70 |
submitted_time = bot.get("timestamp", "Unknown")
|
71 |
message_text += f"β£ {token_preview} - {submitted_time}\n"
|
72 |
|
73 |
buttons.append([
|
74 |
InlineKeyboardButton(
|
75 |
f"β Cancel {token_preview}",
|
76 |
-
callback_data=f"
|
77 |
)
|
78 |
])
|
79 |
|
80 |
if bots_by_status["rejected"]:
|
81 |
message_text += "\nβ <b>Rejected Bots:</b>\n"
|
82 |
for bot in bots_by_status["rejected"]:
|
83 |
-
token_preview = bot.get("bot_token", "")[:10] +
|
84 |
reason = bot.get("admin_action", {}).get("reason", "No reason given")
|
85 |
message_text += f"β£ {token_preview} - {reason}\n"
|
86 |
|
@@ -121,7 +122,7 @@ async def show_user_bots(client: Client, callback: CallbackQuery):
|
|
121 |
PRIVATE_LOGS,
|
122 |
f"π¨ <b>Error in my_bots handler</b>\n\n"
|
123 |
f"π€ User: {user_mention} ({user_id})\n"
|
124 |
-
f"π§ Error:
|
125 |
)
|
126 |
|
127 |
@ren.on_callback_query(filters.regex(r"^botmgmt_(\w+)$"))
|
@@ -178,11 +179,11 @@ async def manage_single_bot(client: Client, callback: CallbackQuery):
|
|
178 |
PRIVATE_LOGS,
|
179 |
f"π¨ <b>Error in single manage handler</b>\n\n"
|
180 |
f"π€ User: {user_mention} ({user_id})\n"
|
181 |
-
f"π§ Error:
|
182 |
)
|
183 |
|
184 |
@ren.on_callback_query(filters.regex(r"^botsettingsdl_(\w+)$"))
|
185 |
-
async def
|
186 |
try:
|
187 |
bots_uuid = callback.matches[0].group(1)
|
188 |
user_id = callback.from_user.id
|
@@ -222,7 +223,7 @@ async def xbot_settingsdl(client: Client, callback: CallbackQuery):
|
|
222 |
PRIVATE_LOGS,
|
223 |
f"π¨ <b>Error in settingdl handler</b>\n\n"
|
224 |
f"π€ User: {user_mention} ({user_id})\n"
|
225 |
-
f"π§ Error:
|
226 |
)
|
227 |
|
228 |
@ren.on_callback_query(filters.regex("start_reset_tokendl"))
|
@@ -230,7 +231,7 @@ async def reset_tokendl_callbackx(client, callback_query):
|
|
230 |
user_id = callback_query.from_user.id
|
231 |
bot_data = await db_client.alldl_bot.find_one({"user_id": user_id})
|
232 |
if not bot_data:
|
233 |
-
await
|
234 |
return
|
235 |
old_uuid = bot_data["bots"][0].get("uuid")
|
236 |
await callback_query.message.edit_text(
|
@@ -334,134 +335,173 @@ async def tokenx_reset_flowdl(client: Client, callback: CallbackQuery):
|
|
334 |
PRIVATE_LOGS,
|
335 |
f"π¨ <b>Error in tokenx reset handler</b>\n\n"
|
336 |
f"π€ User: {user_mention} ({user_id})\n"
|
337 |
-
f"π§ Error:
|
338 |
)
|
339 |
|
340 |
@ren.on_callback_query(filters.regex("^noop$"))
|
341 |
async def noopx_callback(client, callback_query):
|
342 |
await callback_query.answer("π This button is disabled.", show_alert=False)
|
343 |
|
344 |
-
@ren.on_callback_query(filters.regex(r"^
|
345 |
-
async def
|
346 |
try:
|
347 |
bots_uuid = callback.matches[0].group(1)
|
348 |
user_id = callback.from_user.id
|
349 |
user_mention = callback.from_user.mention
|
|
|
|
|
|
|
350 |
|
351 |
bot_data = await db_client.alldl_bot.find_one(
|
352 |
{
|
353 |
"user_id": user_id,
|
354 |
"bots.uuid": bots_uuid,
|
355 |
-
"bots.status": "rejected"
|
356 |
},
|
357 |
{"bots.$": 1}
|
358 |
)
|
359 |
|
360 |
if not bot_data:
|
361 |
-
await callback.answer("β Bot not found
|
362 |
return
|
363 |
|
364 |
-
bot = bot_data["bots"][0]
|
365 |
-
rejection_reason = bot.get("admin_action", {}).get("reason", "No reason provided")
|
366 |
-
|
367 |
await callback.message.edit_text(
|
368 |
-
f"
|
369 |
f"π UUID: `{bots_uuid}`\n"
|
370 |
-
f"
|
371 |
-
"
|
|
|
|
|
|
|
372 |
reply_markup=InlineKeyboardMarkup([
|
373 |
-
[InlineKeyboardButton("
|
374 |
-
[InlineKeyboardButton("
|
|
|
375 |
])
|
376 |
)
|
377 |
await callback.answer()
|
378 |
|
379 |
except Exception as e:
|
380 |
-
LOGS.error(f"
|
381 |
await callback.answer("β οΈ Error processing request", show_alert=True)
|
382 |
await client.send_message(
|
383 |
PRIVATE_LOGS,
|
384 |
-
f"π¨ <b>Error in
|
385 |
f"π€ User: {user_mention} ({user_id})\n"
|
386 |
-
f"π§ Error:
|
387 |
)
|
388 |
|
389 |
-
@ren.on_callback_query(filters.regex(r"^
|
390 |
-
async def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
try:
|
392 |
-
bots_uuid = callback.matches[0].group(1)
|
393 |
user_id = callback.from_user.id
|
394 |
user_mention = callback.from_user.mention
|
395 |
|
|
|
396 |
result = await db_client.alldl_bot.update_one(
|
397 |
-
{
|
398 |
-
|
399 |
-
"bots.uuid": bots_uuid
|
400 |
-
},
|
401 |
-
{
|
402 |
-
"$set": {
|
403 |
-
"bots.$.status": "pending",
|
404 |
-
"bots.$.resubmitted_at": dt.now(),
|
405 |
-
"bots.$.admin_action.reviewed": False
|
406 |
-
}
|
407 |
-
}
|
408 |
)
|
409 |
|
410 |
if result.modified_count == 1:
|
411 |
await callback.message.edit_text(
|
412 |
-
|
413 |
-
f"
|
414 |
-
f"Average review time: 24-48 hours",
|
415 |
reply_markup=InlineKeyboardMarkup([
|
416 |
-
[InlineKeyboardButton("
|
417 |
])
|
418 |
)
|
419 |
-
await
|
420 |
-
f"Bot
|
|
|
|
|
421 |
user_id=user_id,
|
422 |
-
|
423 |
)
|
424 |
else:
|
425 |
raise Exception("Database update failed")
|
426 |
|
427 |
except Exception as e:
|
428 |
-
LOGS.error(f"
|
429 |
-
await callback.message.edit_text("β
|
430 |
await client.send_message(
|
431 |
PRIVATE_LOGS,
|
432 |
-
f"π¨ <b>Error
|
433 |
f"π€ User: {user_mention} ({user_id})\n"
|
434 |
-
f"π§ Error:
|
435 |
)
|
436 |
|
437 |
-
async def notify_adminsdl(text_str, user_id, bots_uuid):
|
438 |
-
admin_buttons = InlineKeyboardMarkup([
|
439 |
-
[InlineKeyboardButton("β
Approve", callback_data=f"approved_alldl_{user_id}_{bots_uuid}"),
|
440 |
-
InlineKeyboardButton("β Reject", callback_data=f"rejected_alldl_{user_id}_{bots_uuid}")],
|
441 |
-
[InlineKeyboardButton("π€ View User", url=f"tg://user?id={user_id}")]
|
442 |
-
])
|
443 |
-
await client.send_message(
|
444 |
-
PRIVATE_LOGS,
|
445 |
-
text_str,
|
446 |
-
reply_markup=admin_buttons
|
447 |
-
)
|
448 |
|
449 |
-
@ren.on_callback_query(filters.regex(r"^
|
450 |
-
async def
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
@ren.on_callback_query(filters.regex(r"^cancelbotdl_(\w+)$"))
|
460 |
-
async def
|
461 |
try:
|
462 |
bots_uuid = callback.matches[0].group(1)
|
463 |
user_id = callback.from_user.id
|
464 |
user_mention = callback.from_user.mention
|
|
|
|
|
|
|
465 |
|
466 |
bot_data = await db_client.alldl_bot.find_one(
|
467 |
{
|
@@ -475,7 +515,7 @@ async def cancelbotdl(client: Client, callback: CallbackQuery):
|
|
475 |
if not bot_data:
|
476 |
await callback.answer("β No pending bot found with this ID", show_alert=True)
|
477 |
return
|
478 |
-
|
479 |
await callback.message.edit_text(
|
480 |
f"β οΈ **Confirm Cancellation**\n\n"
|
481 |
f"UUID: `{bots_uuid}`\n"
|
@@ -483,7 +523,8 @@ async def cancelbotdl(client: Client, callback: CallbackQuery):
|
|
483 |
"This will permanently remove the bot request:",
|
484 |
reply_markup=InlineKeyboardMarkup([
|
485 |
[InlineKeyboardButton("π Confirm Delete", callback_data=f"confirmcanceldl_{bots_uuid}")],
|
486 |
-
[InlineKeyboardButton("π Keep Request", callback_data=f"keepbotdl_{user_id}")]
|
|
|
487 |
])
|
488 |
)
|
489 |
await callback.answer()
|
@@ -493,18 +534,21 @@ async def cancelbotdl(client: Client, callback: CallbackQuery):
|
|
493 |
await callback.answer("β οΈ Error processing request", show_alert=True)
|
494 |
await client.send_message(
|
495 |
PRIVATE_LOGS,
|
496 |
-
f"π¨ <b>Error in
|
497 |
f"π€ User: {user_mention} ({user_id})\n"
|
498 |
-
f"π§ Error:
|
499 |
)
|
500 |
|
501 |
@ren.on_callback_query(filters.regex(r"^confirmcanceldl_(\w+)$"))
|
502 |
-
async def
|
503 |
try:
|
504 |
bots_uuid = callback.matches[0].group(1)
|
505 |
user_id = callback.from_user.id
|
506 |
user_mention = callback.from_user.mention
|
507 |
-
|
|
|
|
|
|
|
508 |
result = await db_client.alldl_bot.update_one(
|
509 |
{"user_id": user_id},
|
510 |
{"$pull": {"bots": {"uuid": bots_uuid}}}
|
@@ -515,8 +559,7 @@ async def confirm_cancel_botdl(client: Client, callback: CallbackQuery):
|
|
515 |
"β
**Request Cancelled**\n\n"
|
516 |
f"Bot `{bots_uuid}` has been permanently removed",
|
517 |
reply_markup=InlineKeyboardMarkup([
|
518 |
-
[InlineKeyboardButton("π My Bots", callback_data="my_bots")]
|
519 |
-
[InlineKeyboardButton("Β« Back", callback_data="customzie_bot")]
|
520 |
])
|
521 |
)
|
522 |
else:
|
@@ -527,19 +570,80 @@ async def confirm_cancel_botdl(client: Client, callback: CallbackQuery):
|
|
527 |
await callback.message.edit_text("β Failed to cancel request. Please contact support.")
|
528 |
await client.send_message(
|
529 |
PRIVATE_LOGS,
|
530 |
-
f"π¨ <b>Error in confirm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
f"π€ User: {user_mention} ({user_id})\n"
|
532 |
-
f"π§ Error:
|
533 |
)
|
534 |
|
535 |
-
|
536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
await callback.message.edit_text(
|
538 |
-
"
|
539 |
-
"Your submission remains pending admin review",
|
540 |
reply_markup=InlineKeyboardMarkup([
|
541 |
-
[InlineKeyboardButton("
|
542 |
-
[InlineKeyboardButton("Β« Back", callback_data="customzie_bot")]
|
543 |
])
|
544 |
)
|
545 |
await callback.answer()
|
|
|
8 |
from pyrogram import *
|
9 |
from pyrogram import Client as ren, filters
|
10 |
from pyrogram.types import *
|
11 |
+
|
12 |
from akn.utils.database import db as db_client
|
13 |
from akn.manage.settings_control import verify_bot_ownershipdl
|
14 |
from akn.utils.logger import LOGS
|
|
|
46 |
message_text += f"π <b>Active Bots:</b> {sum(1 for b in bots_by_status['approved'] if b.get('is_active'))}\n"
|
47 |
message_text += f"β³ <b>Pending:</b> {len(bots_by_status['pending'])}\n"
|
48 |
message_text += f"β <b>Rejected:</b> {len(bots_by_status['rejected'])}\n"
|
49 |
+
message_text += f"β <b>Pong:</b> `{latency:.2f} ms`\n\n"
|
50 |
|
51 |
buttons = []
|
52 |
|
|
|
67 |
if bots_by_status["pending"]:
|
68 |
message_text += "\nπ <b>Pending Approval:</b>\n"
|
69 |
for bot in bots_by_status["pending"]:
|
70 |
+
token_preview = bot.get("bot_token", "")[:10] + "..."
|
71 |
submitted_time = bot.get("timestamp", "Unknown")
|
72 |
message_text += f"β£ {token_preview} - {submitted_time}\n"
|
73 |
|
74 |
buttons.append([
|
75 |
InlineKeyboardButton(
|
76 |
f"β Cancel {token_preview}",
|
77 |
+
callback_data=f"cancelbot_{bot.get('uuid', 'unknown')}"
|
78 |
)
|
79 |
])
|
80 |
|
81 |
if bots_by_status["rejected"]:
|
82 |
message_text += "\nβ <b>Rejected Bots:</b>\n"
|
83 |
for bot in bots_by_status["rejected"]:
|
84 |
+
token_preview = bot.get("bot_token", "")[:10] + "..."
|
85 |
reason = bot.get("admin_action", {}).get("reason", "No reason given")
|
86 |
message_text += f"β£ {token_preview} - {reason}\n"
|
87 |
|
|
|
122 |
PRIVATE_LOGS,
|
123 |
f"π¨ <b>Error in my_bots handler</b>\n\n"
|
124 |
f"π€ User: {user_mention} ({user_id})\n"
|
125 |
+
f"π§ Error: <code>{str(e)}</code>"
|
126 |
)
|
127 |
|
128 |
@ren.on_callback_query(filters.regex(r"^botmgmt_(\w+)$"))
|
|
|
179 |
PRIVATE_LOGS,
|
180 |
f"π¨ <b>Error in single manage handler</b>\n\n"
|
181 |
f"π€ User: {user_mention} ({user_id})\n"
|
182 |
+
f"π§ Error: <code>{str(e)}</code>"
|
183 |
)
|
184 |
|
185 |
@ren.on_callback_query(filters.regex(r"^botsettingsdl_(\w+)$"))
|
186 |
+
async def handle_bot_settingsdl(client: Client, callback: CallbackQuery):
|
187 |
try:
|
188 |
bots_uuid = callback.matches[0].group(1)
|
189 |
user_id = callback.from_user.id
|
|
|
223 |
PRIVATE_LOGS,
|
224 |
f"π¨ <b>Error in settingdl handler</b>\n\n"
|
225 |
f"π€ User: {user_mention} ({user_id})\n"
|
226 |
+
f"π§ Error: <code>{str(e)}</code>"
|
227 |
)
|
228 |
|
229 |
@ren.on_callback_query(filters.regex("start_reset_tokendl"))
|
|
|
231 |
user_id = callback_query.from_user.id
|
232 |
bot_data = await db_client.alldl_bot.find_one({"user_id": user_id})
|
233 |
if not bot_data:
|
234 |
+
await callback_query.answer("β Bot not found!", show_alert=True)
|
235 |
return
|
236 |
old_uuid = bot_data["bots"][0].get("uuid")
|
237 |
await callback_query.message.edit_text(
|
|
|
335 |
PRIVATE_LOGS,
|
336 |
f"π¨ <b>Error in tokenx reset handler</b>\n\n"
|
337 |
f"π€ User: {user_mention} ({user_id})\n"
|
338 |
+
f"π§ Error: <code>{str(e)}</code>"
|
339 |
)
|
340 |
|
341 |
@ren.on_callback_query(filters.regex("^noop$"))
|
342 |
async def noopx_callback(client, callback_query):
|
343 |
await callback_query.answer("π This button is disabled.", show_alert=False)
|
344 |
|
345 |
+
@ren.on_callback_query(filters.regex(r"^deletebotdl_(\w+)$"))
|
346 |
+
async def handle_delete_botdl(client: Client, callback: CallbackQuery):
|
347 |
try:
|
348 |
bots_uuid = callback.matches[0].group(1)
|
349 |
user_id = callback.from_user.id
|
350 |
user_mention = callback.from_user.mention
|
351 |
+
if not await verify_bot_ownershipdl(user_id, bots_uuid):
|
352 |
+
await callback.answer("β Unauthorized access!", show_alert=True)
|
353 |
+
return
|
354 |
|
355 |
bot_data = await db_client.alldl_bot.find_one(
|
356 |
{
|
357 |
"user_id": user_id,
|
358 |
"bots.uuid": bots_uuid,
|
|
|
359 |
},
|
360 |
{"bots.$": 1}
|
361 |
)
|
362 |
|
363 |
if not bot_data:
|
364 |
+
await callback.answer("β Bot not found!", show_alert=True)
|
365 |
return
|
366 |
|
|
|
|
|
|
|
367 |
await callback.message.edit_text(
|
368 |
+
f"β οΈ **Permanent Deletion**\n\n"
|
369 |
f"π UUID: `{bots_uuid}`\n"
|
370 |
+
f"π Username: {bot_data['bots'][0].get('bot_username', 'N/A')}\n\n"
|
371 |
+
"This will immediately:\n"
|
372 |
+
"1. Stop the bot instance\n"
|
373 |
+
"2. Remove all download history\n"
|
374 |
+
"3. Delete configuration data",
|
375 |
reply_markup=InlineKeyboardMarkup([
|
376 |
+
[InlineKeyboardButton("β οΈ Confirm Delete", callback_data=f"confirmdeletedl_{bots_uuid}")],
|
377 |
+
[InlineKeyboardButton("π Cancel", callback_data=f"nodeletedl_{bots_uuid}")],
|
378 |
+
[InlineKeyboardButton("Β« Back", callback_data="my_bots")]
|
379 |
])
|
380 |
)
|
381 |
await callback.answer()
|
382 |
|
383 |
except Exception as e:
|
384 |
+
LOGS.error(f"Delete init error: {str(e)}")
|
385 |
await callback.answer("β οΈ Error processing request", show_alert=True)
|
386 |
await client.send_message(
|
387 |
PRIVATE_LOGS,
|
388 |
+
f"π¨ <b>Error in delete_botdl handler</b>\n\n"
|
389 |
f"π€ User: {user_mention} ({user_id})\n"
|
390 |
+
f"π§ Error: <code>{str(e)}</code>"
|
391 |
)
|
392 |
|
393 |
+
@ren.on_callback_query(filters.regex(r"^(confirmdeletedl|nodeletdl)_(\w+)$"))
|
394 |
+
async def delete_confirmationdl(client: Client, callback: CallbackQuery):
|
395 |
+
action, bots_uuid = callback.matches[0].groups()
|
396 |
+
|
397 |
+
if action == "nodelete":
|
398 |
+
await callback.message.edit_text(
|
399 |
+
"β
Deletion cancelled",
|
400 |
+
reply_markup=InlineKeyboardMarkup([
|
401 |
+
[InlineKeyboardButton("Β« Back", callback_data="my_bots")]
|
402 |
+
])
|
403 |
+
)
|
404 |
+
await callback.answer()
|
405 |
+
return
|
406 |
+
|
407 |
try:
|
|
|
408 |
user_id = callback.from_user.id
|
409 |
user_mention = callback.from_user.mention
|
410 |
|
411 |
+
|
412 |
result = await db_client.alldl_bot.update_one(
|
413 |
+
{"user_id": user_id},
|
414 |
+
{"$pull": {"bots": {"uuid": bots_uuid}}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
)
|
416 |
|
417 |
if result.modified_count == 1:
|
418 |
await callback.message.edit_text(
|
419 |
+
"ποΈ **Bot Deleted**\n\n"
|
420 |
+
f"All data for `{bots_uuid}` has been removed",
|
|
|
421 |
reply_markup=InlineKeyboardMarkup([
|
422 |
+
[InlineKeyboardButton("π My Bots", callback_data="my_bots")],
|
423 |
])
|
424 |
)
|
425 |
+
await notify_admins(
|
426 |
+
f"ποΈ <b>Bot Deleted</b>\n\n"
|
427 |
+
f"User: {user_mention}\n"
|
428 |
+
f"UUID: {bots_uuid}\n",
|
429 |
user_id=user_id,
|
430 |
+
bot_uuid=bots_uuid
|
431 |
)
|
432 |
else:
|
433 |
raise Exception("Database update failed")
|
434 |
|
435 |
except Exception as e:
|
436 |
+
LOGS.error(f"Deletion error: {str(e)}")
|
437 |
+
await callback.message.edit_text("β Deletion failed. Please contact support.")
|
438 |
await client.send_message(
|
439 |
PRIVATE_LOGS,
|
440 |
+
f"π¨ <b>Error indelete_confirmationdl handler</b>\n\n"
|
441 |
f"π€ User: {user_mention} ({user_id})\n"
|
442 |
+
f"π§ Error: <code>{str(e)}</code>"
|
443 |
)
|
444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
|
446 |
+
@ren.on_callback_query(filters.regex(r"^resubmitdl_(\w+)$"))
|
447 |
+
async def xresubmission(client: Client, callback: CallbackQuery):
|
448 |
+
try:
|
449 |
+
bots_uuid = callback.matches[0].group(1)
|
450 |
+
user_id = callback.from_user.id
|
451 |
+
user_mention = callback.from_user.mention
|
452 |
+
if not await verify_bot_ownershipdl(user_id, bots_uuid):
|
453 |
+
await callback.answer("β Unauthorized access!", show_alert=True)
|
454 |
+
return
|
455 |
+
|
456 |
+
bot_data = await db_client.alldl_bot.find_one(
|
457 |
+
{
|
458 |
+
"user_id": user_id,
|
459 |
+
"bots.uuid": bots_uuid,
|
460 |
+
"bots.status": "rejected"
|
461 |
+
},
|
462 |
+
{"bots.$": 1}
|
463 |
+
)
|
464 |
+
|
465 |
+
if not bot_data:
|
466 |
+
await callback.answer("β Bot not found or not eligible for resubmission", show_alert=True)
|
467 |
+
return
|
468 |
+
|
469 |
+
bot = bot_data["bots"][0]
|
470 |
+
rejection_reason = bot.get("admin_action", {}).get("reason", "No reason provided")
|
471 |
+
|
472 |
+
|
473 |
+
await callback.message.edit_text(
|
474 |
+
f"π **Resubmit Bot Request**\n\n"
|
475 |
+
f"π UUID: `{bots_uuid}`\n"
|
476 |
+
f"β Previous Rejection Reason: {rejection_reason}\n\n"
|
477 |
+
"Please confirm you want to resubmit this bot for approval:",
|
478 |
+
reply_markup=InlineKeyboardMarkup([
|
479 |
+
[InlineKeyboardButton("β
Confirm Resubmit", callback_data=f"confirm_resubmitdl_{bots_uuid}")],
|
480 |
+
[InlineKeyboardButton("β Cancel", callback_data=f"cancel_resubmitdl_")],
|
481 |
+
[InlineKeyboardButton("Β« Back", callback_data="my_bots")]
|
482 |
+
])
|
483 |
+
)
|
484 |
+
await callback.answer()
|
485 |
+
|
486 |
+
except Exception as e:
|
487 |
+
LOGS.error(f"Resubmission init error: {str(e)}")
|
488 |
+
await callback.answer("β οΈ Error processing request", show_alert=True)
|
489 |
+
await client.send_message(
|
490 |
+
PRIVATE_LOGS,
|
491 |
+
f"π¨ <b>Error in xresubmission handler</b>\n\n"
|
492 |
+
f"π€ User: {user_mention} ({user_id})\n"
|
493 |
+
f"π§ Error: <code>{str(e)}</code>"
|
494 |
+
)
|
495 |
|
496 |
@ren.on_callback_query(filters.regex(r"^cancelbotdl_(\w+)$"))
|
497 |
+
async def handle_cancel_bot(client: Client, callback: CallbackQuery):
|
498 |
try:
|
499 |
bots_uuid = callback.matches[0].group(1)
|
500 |
user_id = callback.from_user.id
|
501 |
user_mention = callback.from_user.mention
|
502 |
+
if not await verify_bot_ownershipdl(user_id, bots_uuid):
|
503 |
+
await callback.answer("β Unauthorized access!", show_alert=True)
|
504 |
+
return
|
505 |
|
506 |
bot_data = await db_client.alldl_bot.find_one(
|
507 |
{
|
|
|
515 |
if not bot_data:
|
516 |
await callback.answer("β No pending bot found with this ID", show_alert=True)
|
517 |
return
|
518 |
+
|
519 |
await callback.message.edit_text(
|
520 |
f"β οΈ **Confirm Cancellation**\n\n"
|
521 |
f"UUID: `{bots_uuid}`\n"
|
|
|
523 |
"This will permanently remove the bot request:",
|
524 |
reply_markup=InlineKeyboardMarkup([
|
525 |
[InlineKeyboardButton("π Confirm Delete", callback_data=f"confirmcanceldl_{bots_uuid}")],
|
526 |
+
[InlineKeyboardButton("π Keep Request", callback_data=f"keepbotdl_{user_id}")],
|
527 |
+
[InlineKeyboardButton("Β« Back", callback_data="my_bots")]
|
528 |
])
|
529 |
)
|
530 |
await callback.answer()
|
|
|
534 |
await callback.answer("β οΈ Error processing request", show_alert=True)
|
535 |
await client.send_message(
|
536 |
PRIVATE_LOGS,
|
537 |
+
f"π¨ <b>Error in cancel_bot handler</b>\n\n"
|
538 |
f"π€ User: {user_mention} ({user_id})\n"
|
539 |
+
f"π§ Error: <code>{str(e)}</code>"
|
540 |
)
|
541 |
|
542 |
@ren.on_callback_query(filters.regex(r"^confirmcanceldl_(\w+)$"))
|
543 |
+
async def confirm_cancel_bot(client: Client, callback: CallbackQuery):
|
544 |
try:
|
545 |
bots_uuid = callback.matches[0].group(1)
|
546 |
user_id = callback.from_user.id
|
547 |
user_mention = callback.from_user.mention
|
548 |
+
if not await verify_bot_ownershipdl(user_id, bots_uuid):
|
549 |
+
await callback.answer("β Unauthorized access!", show_alert=True)
|
550 |
+
return
|
551 |
+
|
552 |
result = await db_client.alldl_bot.update_one(
|
553 |
{"user_id": user_id},
|
554 |
{"$pull": {"bots": {"uuid": bots_uuid}}}
|
|
|
559 |
"β
**Request Cancelled**\n\n"
|
560 |
f"Bot `{bots_uuid}` has been permanently removed",
|
561 |
reply_markup=InlineKeyboardMarkup([
|
562 |
+
[InlineKeyboardButton("π My Bots", callback_data="my_bots")]
|
|
|
563 |
])
|
564 |
)
|
565 |
else:
|
|
|
570 |
await callback.message.edit_text("β Failed to cancel request. Please contact support.")
|
571 |
await client.send_message(
|
572 |
PRIVATE_LOGS,
|
573 |
+
f"π¨ <b>Error in confirm cancel handler</b>\n\n"
|
574 |
+
f"π€ User: {user_mention} ({user_id})\n"
|
575 |
+
f"π§ Error: <code>{str(e)}</code>"
|
576 |
+
)
|
577 |
+
|
578 |
+
@ren.on_callback_query(filters.regex(r"^confirm_resubmitdl_(\w+)$"))
|
579 |
+
async def confirm_resubmission(client: Client, callback: CallbackQuery):
|
580 |
+
try:
|
581 |
+
bots_uuid = callback.matches[0].group(1)
|
582 |
+
user_id = callback.from_user.id
|
583 |
+
user_mention = callback.from_user.mention
|
584 |
+
if not await verify_bot_ownershipdl(user_id, bots_uuid):
|
585 |
+
await callback.answer("β Unauthorized access!", show_alert=True)
|
586 |
+
return
|
587 |
+
|
588 |
+
result = await db_client.alldl_bot.update_one(
|
589 |
+
{
|
590 |
+
"user_id": user_id,
|
591 |
+
"bots.uuid": bots_uuid
|
592 |
+
},
|
593 |
+
{
|
594 |
+
"$set": {
|
595 |
+
"bots.$.status": "pending",
|
596 |
+
"bots.$.resubmitted_at": dt.now().strftime("%Y-%m-%d %H:%M:%S"),
|
597 |
+
"bots.$.admin_action.reviewed": False
|
598 |
+
}
|
599 |
+
}
|
600 |
+
)
|
601 |
+
|
602 |
+
if result.modified_count == 1:
|
603 |
+
await callback.message.edit_text(
|
604 |
+
f"β
**Resubmission Successful**\n\n"
|
605 |
+
f"Bot `{bots_uuid}` has been queued for admin review.\n"
|
606 |
+
f"Average review time: 24-48 hours",
|
607 |
+
reply_markup=InlineKeyboardMarkup([
|
608 |
+
[InlineKeyboardButton("π View Status", callback_data=f"statusdl_{user_id}")]
|
609 |
+
])
|
610 |
+
)
|
611 |
+
await notify_admins(
|
612 |
+
f"Bot resubmitted: {bots_uuid} by {callback.from_user.mention}",
|
613 |
+
user_id=user_id,
|
614 |
+
bots_uuid=bots_uuid
|
615 |
+
)
|
616 |
+
else:
|
617 |
+
raise Exception("Database update failed")
|
618 |
+
|
619 |
+
except Exception as e:
|
620 |
+
LOGS.error(f"Resubmission error: {str(e)}")
|
621 |
+
await callback.message.edit_text("β Failed to resubmit. Please try again later.")
|
622 |
+
await client.send_message(
|
623 |
+
PRIVATE_LOGS,
|
624 |
+
f"π¨ <b>Error in confirm_resubmission handler</b>\n\n"
|
625 |
f"π€ User: {user_mention} ({user_id})\n"
|
626 |
+
f"π§ Error: <code>{str(e)}</code>"
|
627 |
)
|
628 |
|
629 |
+
async def notify_admins(message, user_id, bots_uuid):
|
630 |
+
admin_buttons = InlineKeyboardMarkup([
|
631 |
+
[InlineKeyboardButton("β
Approve", callback_data=f"approved_alldl_{user_id}_{bots_uuid}"),
|
632 |
+
InlineKeyboardButton("β Reject", callback_data=f"rejected_alldl_{user_id}_{bots_uuid}")],
|
633 |
+
[InlineKeyboardButton("π€ View User", url=f"tg://user?id={user_id}")]
|
634 |
+
])
|
635 |
+
return await client.send_message(
|
636 |
+
chat_id=PRIVATE_LOGS,
|
637 |
+
text=message,
|
638 |
+
reply_markup=admin_buttons
|
639 |
+
)
|
640 |
+
|
641 |
+
@ren.on_callback_query(filters.regex(r"^cancel_resubmitdl_"))
|
642 |
+
async def cancel_resubmit(client: Client, callback: CallbackQuery):
|
643 |
await callback.message.edit_text(
|
644 |
+
"π« Resubmission cancelled",
|
|
|
645 |
reply_markup=InlineKeyboardMarkup([
|
646 |
+
[InlineKeyboardButton("Β« Back", callback_data="my_bots")]
|
|
|
647 |
])
|
648 |
)
|
649 |
await callback.answer()
|