4141 DL_COMPLETE_BUTTON ,
4242) # Assuming buttons.py exists
4343
44- # --- MongoDB Connection ---
45- pwd = os .getenv ('MONGO_PWD' )
46-
47- # connection string
48- connection_string = f'mongodb+srv://myAtlasDBUser:{ pwd } @pyroytbot.p1vptc2.mongodb.net/?retryWrites=true&w=majority&appName=PyroYtBot'
49-
50- # initialize the client
51- client = MongoClient (connection_string )
52-
5344
5445# --- MongoDB tools ---
5546async def mongo_check_user_database (
@@ -126,7 +117,6 @@ async def start_command(client: Client, message):
126117
127118@bot .on_message (filters .command ("help" ))
128119async def help_command (client : Client , message ):
129- print (f"Help command received from user { message .from_user .id } " )
130120
131121 user_id = str (message .from_user .id )
132122 userdict : dict = message .from_user
@@ -139,7 +129,7 @@ async def help_command(client: Client, message):
139129async def about_command (client : Client , message ):
140130 user_id = str (message .from_user .id )
141131 userdict : dict = message .from_user
142- mongo_check_user_database (str (user_id ), userdict , message )
132+ await mongo_check_user_database (str (user_id ), userdict , message )
143133
144134 await message .reply (
145135 text = "**💁 Some details about Me 💁**" ,
@@ -312,6 +302,7 @@ async def youtube_url_handler(client: Client, message):
312302
313303
314304##### Add a sudo user ########
305+
315306@bot .on_message (filters .command ("addsudo" ))
316307async def add_sudo_user (client : Client , message ):
317308 user_id = str (message .from_user .id )
@@ -331,21 +322,21 @@ async def add_sudo_user(client: Client, message):
331322 ):
332323 user_to_add_info : dict = message .reply_to_message .from_user
333324 info : dict = {
334- "_id" : str (user_to_add_info .id ),
335- "date_time" : message .reply_to_message .date ,
336- "fist_name" : user_to_add_info .first_name ,
337- "last_name" : user_to_add_info .last_name ,
338- "username" : user_to_add_info .username ,
339- "language_code" : user_to_add_info .language_code ,
340- "Dc_id" : user_to_add_info .dc_id ,
341- "is_premium" : user_to_add_info .is_premium ,
342- "is_verified" : user_to_add_info .is_verified ,
343- "message_body" : message .reply_to_message .text ,
344- "message_id" : message .reply_to_message .id ,
345- "chat_id" : message .chat .id ,
346- "chat_title" : message .chat .title ,
347- "chat_type" : str (message .chat .type ),
348- "chat_username" : message .chat .username ,
325+ "_id" : str (user_to_add_info .id ) or "None" ,
326+ "date_time" : message .reply_to_message .date or "None" ,
327+ "fist_name" : user_to_add_info .first_name or "None" ,
328+ "last_name" : user_to_add_info .last_name or "None" ,
329+ "username" : user_to_add_info .username or "None" ,
330+ "language_code" : user_to_add_info .language_code or "None" ,
331+ "Dc_id" : user_to_add_info .dc_id or "None" ,
332+ "is_premium" : user_to_add_info .is_premium or "None" ,
333+ "is_verified" : user_to_add_info .is_verified or "None" ,
334+ "message_body" : message .reply_to_message .text or "None" ,
335+ "message_id" : message .reply_to_message .id or "None" ,
336+ "chat_id" : message .chat .id or "None" ,
337+ "chat_title" : message .chat .title or "None" ,
338+ "chat_type" : str (message .chat .type ) or "None" ,
339+ "chat_username" : message .chat .username or "None" ,
349340 }
350341 add_a_sudo_user_to_the_db (info )
351342 await bot .send_message (f"{ user_to_add_info .id } added as a Sudo user" )
@@ -382,6 +373,7 @@ async def add_sudo_user(client: Client, message):
382373
383374
384375##### remove sudo user ########
376+
385377@bot .on_message (filters .command ("rmsudo" ))
386378async def remove_sudo_user (client : Client , message ):
387379 user_id = str (message .from_user .id )
@@ -429,7 +421,6 @@ async def remove_sudo_user(client: Client, message):
429421
430422# ---- List sudo users --------#
431423
432-
433424@bot .on_message (filters .command ("allsudo" ))
434425async def list_sudo_users (client : Client , message ):
435426 user_id = str (message .from_user .id )
@@ -440,24 +431,26 @@ async def list_sudo_users(client: Client, message):
440431 not_authorized = await message .reply (
441432 "You are not authorized to use this command"
442433 )
443- # await message.delete()
444- # await not_authorized.delete()
434+ await message .delete ()
435+ await not_authorized .delete ()
445436 return
446437 checking = await message .reply ("Checking sudo users..." )
447438 sudo_users_count = count_sudo_users ()
448439 if sudo_users_count is not None :
449- # await message.delete()
440+ await message .delete ()
450441 await checking .edit (
451442 f"""
452443__**Sudo User Status**__:
453444There are ({ sudo_users_count } ) sudo users.
454445"""
455446 )
456447 else :
457- await message .reply ("Error counting sudo users." )
458- # return
448+ err = await message .reply ("Error counting sudo users." )
459449 await message .delete ()
460450 await checking .delete ()
451+ await asyncio .sleep (5 )
452+ await err .delete ()
453+ return
461454
462455
463456### -------- List bot users -----
@@ -472,8 +465,9 @@ async def list_users(client: Client, message):
472465 not_authorized = await message .reply (
473466 "You are not authorized to use this command"
474467 )
475- # await message.delete()
476- # await not_authorized.delete()
468+ await message .delete ()
469+ await asyncio .sleep (5 )
470+ await not_authorized .delete ()
477471 return
478472 checking = await message .reply ("Checking users..." )
479473 user_count = count_bot_users ()
@@ -482,14 +476,15 @@ async def list_users(client: Client, message):
482476 await checking .edit (
483477 f"""
484478__**User Status**__:
485- There are ( { user_count } ) users.
479+ There are currently { user_count } users of the bot in the database .
486480"""
487481 )
488482 else :
489- await message .reply ("Error counting users." )
490- # return
483+ err = await message .reply ("Error counting users." )
491484 await message .delete ()
492485 await checking .delete ()
486+ await asyncio .sleep (5 )
487+ await err .delete ()
493488
494489
495490# --- Callback Query Handler ---
0 commit comments