added photo_handler

This commit is contained in:
Alexander Karpov 2023-03-16 13:46:37 +03:00
parent d7d296a0d7
commit 531ea77d52
2 changed files with 42 additions and 0 deletions

2
bots/README.md Normal file
View File

@ -0,0 +1,2 @@
# Telegram bot scrips
my small collection of bots(mainly as a mvp)

40
bots/photo_handler.py Normal file
View File

@ -0,0 +1,40 @@
import time
import telebot
bot = telebot.TeleBot("132:TOKEN")
@bot.message_handler(content_types=["photo"])
def send_text(message):
try:
file_name = message.document.file_name
file_id = message.document.file_name
file_id_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_id_info.file_path)
src = file_name
print(src)
with open(src, "wb") as new_file:
new_file.write(downloaded_file)
bot.send_message(
message.chat.id,
"[*] File added:\nFile name - {}".format(
str(file_name),
),
)
except Exception as ex:
bot.send_message(message.chat.id, "[!] error - {}".format(str(ex)))
while True:
try:
print("[*] bot starting..")
print("[*] bot started!")
bot.polling(none_stop=True, interval=2)
break
except Exception as ex:
print("[*] error - {}".format(str(ex)))
print("[*] rebooting..")
bot.stop_polling()
time.sleep(15)
print("[*] restarted!")