Now prints image files.
Added image handling. Can't print inline images, but will remind the user to send the image as a file.
This commit is contained in:
parent
4ca6b82761
commit
3cd1137b84
12
tg_print.py
12
tg_print.py
|
@ -2,6 +2,7 @@ import sys
|
|||
import os
|
||||
import telebot
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
# Telegram API token
|
||||
TOKEN = 'TOKEN'
|
||||
|
@ -26,13 +27,16 @@ def start(message):
|
|||
# Handle incoming files
|
||||
@bot.message_handler(content_types=['document', 'audio', 'photo'])
|
||||
def handle_file(message):
|
||||
try:
|
||||
if message.photo:
|
||||
# Handle photos
|
||||
bot.send_message(CHAT_ID, 'Printing Images isn\'t supported')
|
||||
file_info = bot.get_file(message.photo[-1].file_id)
|
||||
file_name = f"photo_{message.photo[-1].file_id}{Path(file_info.file_path).suffix}"
|
||||
bot.send_message(CHAT_ID, 'Printing Images isn\'t supported. Please send the image as a file. Like this --> https://i.imgur.com/JcTtCvR.png')
|
||||
elif message.audio:
|
||||
# Handle audio
|
||||
bot.send_message(CHAT_ID, "I can't print sounds!")
|
||||
else:
|
||||
elif message.document:
|
||||
# Handle other file types
|
||||
# Download the file
|
||||
file_info = bot.get_file(message.document.file_id)
|
||||
|
@ -50,6 +54,10 @@ def handle_file(message):
|
|||
|
||||
# Send a message to the channel indicating that a file has been downloaded and printed
|
||||
bot.send_message(CHAT_ID, f'File "{file_name}" has been downloaded and printed!')
|
||||
except Exception as e:
|
||||
# Handle any other exceptions
|
||||
print(f"Error: {e}")
|
||||
bot.send_message(CHAT_ID, 'An error occurred while processing the file. Please try again.')
|
||||
|
||||
# Start the bot
|
||||
bot.polling()
|
Loading…
Reference in New Issue