nexus3rd commited on
Commit
dc97221
·
1 Parent(s): 42c71d0
Files changed (1) hide show
  1. bot.py +10 -14
bot.py CHANGED
@@ -148,9 +148,16 @@ async def start(client: Client, message: Message):
148
  async def set_api_callback(client: Client, callback_query: CallbackQuery):
149
  user_id = int(callback_query.matches[0].group(1))
150
  prompt_message = await callback_query.message.reply("Please send your Ngrok API key as a reply to this message.")
151
- await callback_query.answer() # Acknowledge the callback query to prevent loading state
 
 
 
 
 
 
 
 
152
 
153
- # Define a function to capture the API key
154
  @bot.on_message(filters.reply & filters.create(lambda _, __, message: message.reply_to_message and message.reply_to_message.id == prompt_message.id))
155
  async def capture_api_key(client: Client, message: Message):
156
  api_key = message.text.strip()
@@ -158,18 +165,7 @@ async def set_api_callback(client: Client, callback_query: CallbackQuery):
158
  await message.reply("Ngrok API key set successfully!")
159
  await prompt_message.delete()
160
 
161
- # Function to wait and delete the prompt if no key is set
162
- async def wait_and_delete_prompt():
163
- await asyncio.sleep(60) # Wait for 60 seconds
164
- if user_id not in user_api_keys:
165
- try:
166
- await prompt_message.delete()
167
- except Exception as e:
168
- print(f"Error while deleting prompt message: {e}")
169
-
170
- # Start the timeout function
171
- asyncio.create_task(wait_and_delete_prompt())
172
-
173
  @bot.on_callback_query(filters.regex(r"^refresh_ngrok\|(\d+)\|(\d+)$"))
174
  async def refresh_ngrok(client: Client, callback_query: CallbackQuery):
175
  user_id = int(callback_query.matches[0].group(1))
 
148
  async def set_api_callback(client: Client, callback_query: CallbackQuery):
149
  user_id = int(callback_query.matches[0].group(1))
150
  prompt_message = await callback_query.message.reply("Please send your Ngrok API key as a reply to this message.")
151
+ await callback_query.answer()
152
+
153
+ # Wait for 5 seconds
154
+ await asyncio.sleep(5)
155
+
156
+ # Check if the API key was set
157
+ if user_id not in user_api_keys:
158
+ await prompt_message.delete()
159
+ return
160
 
 
161
  @bot.on_message(filters.reply & filters.create(lambda _, __, message: message.reply_to_message and message.reply_to_message.id == prompt_message.id))
162
  async def capture_api_key(client: Client, message: Message):
163
  api_key = message.text.strip()
 
165
  await message.reply("Ngrok API key set successfully!")
166
  await prompt_message.delete()
167
 
168
+ # Other callback functions remain unchanged
 
 
 
 
 
 
 
 
 
 
 
169
  @bot.on_callback_query(filters.regex(r"^refresh_ngrok\|(\d+)\|(\d+)$"))
170
  async def refresh_ngrok(client: Client, callback_query: CallbackQuery):
171
  user_id = int(callback_query.matches[0].group(1))