mirror of
https://github.com/Alexander-D-Karpov/scripts.git
synced 2024-11-22 03:56:32 +03:00
added photo_handler
This commit is contained in:
parent
d7d296a0d7
commit
531ea77d52
2
bots/README.md
Normal file
2
bots/README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Telegram bot scrips
|
||||||
|
my small collection of bots(mainly as a mvp)
|
40
bots/photo_handler.py
Normal file
40
bots/photo_handler.py
Normal 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!")
|
Loading…
Reference in New Issue
Block a user