genstava789 commited on
Commit ·
46d346f
1
Parent(s): cf35205
init
Browse files
bot.py
CHANGED
|
@@ -119,7 +119,7 @@ def create_ngrok_status_message(user_id, message_id):
|
|
| 119 |
]
|
| 120 |
)
|
| 121 |
return full_message, buttons
|
| 122 |
-
|
| 123 |
@bot.on_message(filters.command("start"))
|
| 124 |
async def start(client: Client, message: Message):
|
| 125 |
user_id = message.from_user.id
|
|
@@ -390,41 +390,18 @@ async def reply_hi(client: Client, message: Message):
|
|
| 390 |
else:
|
| 391 |
await message.reply_text("Please reply to a message with /hi to use this command.")
|
| 392 |
|
| 393 |
-
@bot.on_message(filters.
|
| 394 |
-
async def
|
| 395 |
-
|
|
|
|
| 396 |
|
| 397 |
-
|
|
|
|
|
|
|
| 398 |
|
| 399 |
-
#
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
if message.reply_to_message.document:
|
| 403 |
-
logging.debug("Replied message contains a document")
|
| 404 |
-
try:
|
| 405 |
-
# Download the replied document as the cookies file
|
| 406 |
-
replied_message = message.reply_to_message
|
| 407 |
-
cookies_file_path = os.path.join(cookies_directory, replied_message.document.file_name)
|
| 408 |
-
logging.debug(f"Downloading document to {cookies_file_path}")
|
| 409 |
-
|
| 410 |
-
await replied_message.download(file_name=cookies_file_path)
|
| 411 |
-
cookies_file = cookies_file_path
|
| 412 |
-
logging.debug(f"Cookies file set to: {cookies_file}")
|
| 413 |
-
await message.reply(f"Cookies file '{replied_message.document.file_name}' has been set successfully.")
|
| 414 |
-
|
| 415 |
-
except PermissionError as e:
|
| 416 |
-
logging.error(f"Permission error: {e}")
|
| 417 |
-
await message.reply("Permission denied: Unable to save the cookies file. Please check the server's file permissions.")
|
| 418 |
-
|
| 419 |
-
except Exception as e:
|
| 420 |
-
logging.error(f"Failed to download document: {e}")
|
| 421 |
-
await message.reply("An error occurred while downloading the cookies file. Please try again.")
|
| 422 |
-
else:
|
| 423 |
-
logging.debug("Replied message does not contain a document")
|
| 424 |
-
await message.reply("Please reply to a document message containing the cookies file with the command /cookies.")
|
| 425 |
-
else:
|
| 426 |
-
logging.debug("The /cookies command was not used as a reply")
|
| 427 |
-
await message.reply("Please use the /cookies command as a reply to a document message.")
|
| 428 |
|
| 429 |
def run_bot():
|
| 430 |
loop = asyncio.new_event_loop()
|
|
|
|
| 119 |
]
|
| 120 |
)
|
| 121 |
return full_message, buttons
|
| 122 |
+
|
| 123 |
@bot.on_message(filters.command("start"))
|
| 124 |
async def start(client: Client, message: Message):
|
| 125 |
user_id = message.from_user.id
|
|
|
|
| 390 |
else:
|
| 391 |
await message.reply_text("Please reply to a message with /hi to use this command.")
|
| 392 |
|
| 393 |
+
@bot.on_message(filters.document | filters.video | filters.photo)
|
| 394 |
+
async def handle_media(client: Client, message: Message):
|
| 395 |
+
user_id = message.from_user.id
|
| 396 |
+
logging.debug(f"Received media from user {user_id}")
|
| 397 |
|
| 398 |
+
# Download the media
|
| 399 |
+
file_path = await message.download()
|
| 400 |
+
logging.debug(f"Downloaded media to {file_path}")
|
| 401 |
|
| 402 |
+
# Upload the media back to the bot
|
| 403 |
+
await client.send_document(chat_id=message.chat.id, document=file_path)
|
| 404 |
+
logging.debug("Uploaded media back to the bot")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
def run_bot():
|
| 407 |
loop = asyncio.new_event_loop()
|