-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
72 lines (48 loc) · 1.91 KB
/
bot.py
File metadata and controls
72 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!usr/bin/env python
# Authors: Ric y Blanca
# file : bot.py
# Description:
# Telegram-bot who upload files and photos to dropbox or drive
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from platform.dropbox import upload_to_dropbox
from platform.drive import upload_to_drive
from _config import TOKEN
def start(bot, update):
msg = (f"Hola {update.message.from_user.first_name}, "
"bienvenido a nuestra secta <3.\n"
"¿Quieres colaborar en los apuntes?")
update.message.reply_text(msg)
def help(bot, update):
update.message.reply_text(" - Envia una foto o un archivo")
def upload(bot, update):
"""Descarga el archivo enviado y lo sube a la plataforma"""
prefix = 'downloads/'
# Elegir plataforma
upload_file = upload_to_drive
update.message.reply_text("Marchando, a ver si lo subo")
if update.message.photo:
photo = update.message.photo[-1]
# Preguntar por el nombre de la foto y modificar (interactive_tools.py)
path = prefix + "photo.png"
#gestión de carpetas
file_id = photo.file_id
file_down = bot.get_file(file_id)
file_down.download(path)
elif update.message.document:
doc = update.message.document
path = prefix + doc.file_name
file_id = doc.file_id
file_down = bot.get_file(file_id)
file_down.download(path)
upload_file(path)
msg = ("Subida finalizada, muchas gracias por colaborar "
"en nuestro repositorillo, besito psicológico para *ti* :)")
update.message.reply_text(msg)
updater = Updater(TOKEN)
# Filtrar mensajes con documentos o fotos
notes = MessageHandler(Filters.photo | Filters.document, upload)
updater.dispatcher.add_handler(notes)
updater.dispatcher.add_handler(CommandHandler("start", start))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.start_polling()
updater.idle()